@@ -119,14 +119,20 @@ namespace APRNumericsGPU {
119119template <typename InputType>
120120void 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>
136142void 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>
151163void 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>
176191void 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