-
Notifications
You must be signed in to change notification settings - Fork 1
/
linearCombinationKernel1.h
114 lines (81 loc) · 3.18 KB
/
linearCombinationKernel1.h
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#ifndef __LINEAR_COMBINATION_KERNEL_1__
#define __LINEAR_COMBINATION_KERNEL_1__
//#define STANDALONE
#ifndef STANDALONE
#include "lsst/afw/image.h"
namespace afwImage = lsst::afw::image;
namespace afwMath = lsst::afw::math;
#endif
#include <stdio.h>
#include "Halide.h"
#include <bitset>
#include "clock.h"
using namespace std;
using namespace Halide;
using Halide::Image;
#define BOUNDING_BOX 2 //the kernel has dimensions (BOUNDING_BOX*2 + 1) x (BOUNDING_BOX*2 + 1)
#define NUMBER_OF_RUNS 5 //number of runs when performance testing
// from lesson_12_using_the_gpu.cpp
// We're going to want to schedule a pipeline in several ways, so we
// define the pipeline in a class so that we can recreate it several
// times with different schedules.
// Define some Vars to use.
Var x, y, i, j, i_v, y_0, yi;
//CURRENTLY ONLY IMAGE PLANE IS IMPLEMENTED
//this program uses tuples
//each basis kernel is convolved with each input plane (using tuples) and then
//the 5 output planes are combined using the weights of the spatially varying
//polynomials
class convolveKernelsSeparatelyThenCombinePipeline {
public:
Func polynomial1, polynomial2, polynomial3, polynomial4, polynomial5, kernel1, kernel2,
kernel3, kernel4, kernel5, image_bounded, blurImage1, blurImage2, blurImage3,
blurImage4, blurImage5, variance_bounded, mask_bounded, combined_output, imageOut,
varianceOut, maskOut;
Image<float> image;
Image<float> variance;
Image<uint16_t> mask;
Buffer image_gpu_output;
Buffer variance_gpu_output;
Buffer mask_gpu_output;
convolveKernelsSeparatelyThenCombinePipeline(Image<float> image_, Image<float> variance_,
Image<uint16_t> mask_, bool useTuples_);
void debug();
void schedule_for_cpu();
void schedule_for_gpu();
void test_performance_cpu();
void test_performance_gpu();
private:
bool useTuples;
};
//this program uses tuples
//the total kernel is computed as a spatially varying linear combination of each basis
//kernel and convolved once with each input plane (using a tuple)
class convolveOneSpatiallyVaryingKernelPipeline {
public:
Func polynomial1, polynomial2, polynomial3, polynomial4, polynomial5, kernel1, kernel2,
kernel3, kernel4, kernel5, blurImage1, blurImage2, blurImage3, blurImage4, blurImage5,
image_bounded, variance_bounded, mask_bounded, combined_output, imageOut, varianceOut,
maskOut;
Image<float> image;
Image<float> variance;
Image<uint16_t> mask;
Buffer image_gpu_output;
Buffer variance_gpu_output;
Buffer mask_gpu_output;
//will use tuples if useTuples==true, will not use tuples if useTuples==false
convolveOneSpatiallyVaryingKernelPipeline(Image<float> image_, Image<float> variance_,
Image<uint16_t> mask_, bool useTuples_);
void schedule_for_cpu();
void schedule_for_gpu();
void test_performance_cpu();
void test_performance_gpu();
//check whether the image planes match
//implement more if desired later
void test_correctness(Image<float> reference_output);
void debug();
private:
//will use tuples if useTuples==true, will not use tuples if useTuples==false
bool useTuples;
};
#endif //__LINEAR_COMBINATION_KERNEL_H__