Skip to content

Commit 36bd143

Browse files
committed
add access initialization steps to gpu proceccing methods
1 parent c073c3f commit 36bd143

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

src/numerics/APRIsoConvGPU333.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ template<typename inputType, typename outputType, typename stencilType, typename
2323
void isotropic_convolve_333(GPUAccessHelper& access, GPUAccessHelper& tree_access, VectorData<inputType>& input,
2424
VectorData<outputType>& output, VectorData<stencilType>& stencil, VectorData<treeType>& tree_data,
2525
bool reflective_bc=false, bool use_stencil_downsample=false, bool normalize_stencil=false) {
26+
tree_access.init_gpu();
27+
access.init_gpu(tree_access);
28+
2629
assert(stencil.size() == 27);
2730
VectorData<stencilType> stencil_vec;
2831
const int nlevels = use_stencil_downsample ? access.level_max() - access.level_min() : 1;
@@ -35,6 +38,9 @@ template<typename inputType, typename outputType, typename stencilType, typename
3538
void isotropic_convolve_333(GPUAccessHelper& access, GPUAccessHelper& tree_access, VectorData<inputType>& input,
3639
VectorData<outputType>& output, PixelData<stencilType>& stencil, VectorData<treeType>& tree_data,
3740
bool reflective_bc=false, bool use_stencil_downsample=false, bool normalize_stencil=false) {
41+
tree_access.init_gpu();
42+
access.init_gpu(tree_access);
43+
3844
assert(stencil.z_num == 3);
3945
assert(stencil.x_num == 3);
4046
assert(stencil.y_num == 3);

src/numerics/APRIsoConvGPU555.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ template<typename inputType, typename outputType, typename stencilType, typename
2424
void isotropic_convolve_555(GPUAccessHelper& access, GPUAccessHelper& tree_access, VectorData<inputType>& input, VectorData<outputType>& output,
2525
VectorData<stencilType>& stencil, VectorData<treeType>& tree_data, bool reflective_bc, bool use_stencil_downsample,
2626
bool normalize_stencil) {
27+
tree_access.init_gpu();
28+
access.init_gpu(tree_access);
29+
2730
assert(stencil.size() == 125);
2831
VectorData<stencilType> stencil_vec;
2932
const int nlevels = use_stencil_downsample ? access.level_max() - access.level_min() : 1;
@@ -36,6 +39,9 @@ template<typename inputType, typename outputType, typename stencilType, typename
3639
void isotropic_convolve_555(GPUAccessHelper& access, GPUAccessHelper& tree_access, VectorData<inputType>& input, VectorData<outputType>& output,
3740
PixelData<stencilType>& stencil, VectorData<treeType>& tree_data, bool reflective_bc, bool use_stencil_downsample,
3841
bool normalize_stencil) {
42+
tree_access.init_gpu();
43+
access.init_gpu(tree_access);
44+
3945
assert(stencil.z_num == 5);
4046
assert(stencil.x_num == 5);
4147
assert(stencil.y_num == 5);

src/numerics/APRNumericsGPU.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,20 @@ namespace APRNumericsGPU {
119119
template<typename InputType>
120120
void APRNumericsGPU::gradient_cfd(GPUAccessHelper &access, GPUAccessHelper &tree_access, VectorData<InputType> &inputParticles,
121121
VectorData<float> &outputParticles, const int dimension, const float delta) {
122+
// initialize access
123+
tree_access.init_gpu();
124+
access.init_gpu(tree_access);
122125

126+
// generate stencil
123127
PixelData<float> stencil(3, 3, 3, 0);
124128
stencil.at(dimension == 0 ? 0 : 1, dimension == 1 ? 0 : 1, dimension == 2 ? 0 : 1) = -1.f / (2.f * delta);
125129
stencil.at(dimension == 0 ? 2 : 1, dimension == 1 ? 2 : 1, dimension == 2 ? 2 : 1) = 1.f / (2.f * delta);
126130

131+
// rescale stencil for each level
127132
VectorData<float> stencil_vec;
128133
APRStencil::get_rescaled_stencils(stencil, stencil_vec, access.level_max()-access.level_min());
129134

135+
// compute gradient
130136
VectorData<float> tree_data;
131137
isotropic_convolve_333_direct(access, tree_access, inputParticles, outputParticles, stencil_vec, tree_data, true);
132138
}
@@ -136,12 +142,18 @@ template<typename InputType>
136142
void APRNumericsGPU::gradient_sobel(GPUAccessHelper &access, GPUAccessHelper &tree_access,
137143
VectorData<InputType> &inputParticles, VectorData<float> &outputParticles,
138144
int dimension, float delta) {
145+
// initialize acccess
146+
tree_access.init_gpu();
147+
access.init_gpu(tree_access);
139148

149+
// generate stencil
140150
auto stencil = APRStencil::create_sobel_filter<float>(dimension, delta);
141151

152+
// rescale stencil for each level
142153
VectorData<float> stencil_vec;
143154
APRStencil::get_rescaled_stencils(stencil, stencil_vec, access.level_max()-access.level_min());
144155

156+
// compute output
145157
VectorData<float> tree_data;
146158
isotropic_convolve_333_direct(access, tree_access, inputParticles, outputParticles, stencil_vec, tree_data, true);
147159
}
@@ -151,6 +163,9 @@ template<typename InputType>
151163
void APRNumericsGPU::gradient_magnitude_cfd(GPUAccessHelper &access, GPUAccessHelper &tree_access,
152164
VectorData<InputType> &inputParticles, VectorData<float> &outputParticles,
153165
const std::vector<float> &deltas) {
166+
// initialize access
167+
tree_access.init_gpu();
168+
access.init_gpu(tree_access);
154169

155170
// generate cfd stencils
156171
PixelData<float> stencil_y(3, 3, 3, 0);
@@ -176,6 +191,10 @@ template<typename InputType>
176191
void APRNumericsGPU::gradient_magnitude_sobel(GPUAccessHelper &access, GPUAccessHelper &tree_access,
177192
VectorData<InputType> &inputParticles, VectorData<float> &outputParticles,
178193
const std::vector<float> &deltas) {
194+
// initialize access
195+
tree_access.init_gpu();
196+
access.init_gpu(tree_access);
197+
179198
// generate Sobel stencils
180199
auto stencil_y = APRStencil::create_sobel_filter<float>(0, deltas[0]);
181200
auto stencil_x = APRStencil::create_sobel_filter<float>(1, deltas[1]);

0 commit comments

Comments
 (0)