summarylogtreecommitdiffstats
path: root/esee.patch
blob: 0829794b8ef6c907901f12828750287b5adc72f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
diff --git a/fsrcnn.cpp b/fsrcnn.cpp
index 77686df..019b612 100644
--- a/fsrcnn.cpp
+++ b/fsrcnn.cpp
@@ -24,10 +24,18 @@
 #include "fsrcnn.h"
 
 ncnn::Net fsrcnn;
+#ifndef min
+#define min(a,b) ((a) <= (b) ? (a) : (b))
+#endif
+#ifndef max
+#define max(a,b) ((a) >= (b) ? (a) : (b))
+#endif
 
 void fsrcnn_process(cv::Mat&, cv::Mat&, int, int);
+static ncnn::PoolAllocator *pa;
 
 void init_ncnn() {
+	pa = new ncnn::PoolAllocator;
        ncnn::create_gpu_instance();
        fsrcnn.set_vulkan_device(0);
        fsrcnn.opt.use_vulkan_compute = true;
@@ -36,6 +44,8 @@ void init_ncnn() {
 }
 
 void destroy_ncnn() {
+	delete pa;
+	pa = nullptr;
        fsrcnn.clear();
        ncnn::destroy_gpu_instance();
 }
@@ -140,12 +150,15 @@ void new_to_gray(const ncnn::Mat& m, float* gray)
 }
 
 void fsrcnn_process(cv::Mat& img_y, cv::Mat& out_y, int w, int h) {
+	ncnn::VkAllocator* blob_vkallocator = fsrcnn.vulkan_device()->acquire_blob_allocator();
        ncnn::VkMat in_gpu;
+	in_gpu.allocator = blob_vkallocator;
        ncnn::VkMat out_gpu;
+	out_gpu.allocator = blob_vkallocator;
        ncnn::Mat inimage = in_gpu.mapped();
        ncnn::Mat outimage = out_gpu.mapped();
 
-       new_from_gray((float *)img_y.data, w, h, inimage, (ncnn::Allocator*)0);
+       new_from_gray((float *)img_y.data, w, h, inimage, pa);
 
        {
                ncnn::Extractor ex = fsrcnn.create_extractor();
@@ -155,4 +168,5 @@ void fsrcnn_process(cv::Mat& img_y, cv::Mat& out_y, int w, int h) {
        }
 
        new_to_gray(outimage, (float*)out_y.data);
+	fsrcnn.vulkan_device()->reclaim_blob_allocator(blob_vkallocator);
 }