@@ -59,10 +59,29 @@ int main(int argc, char **argv) {
5959 ParticleData<float > output;
6060 std::vector<float > deltas = {options.dy , options.dx , options.dz };
6161
62- if (options.sobel ) {
63- APRNumerics::gradient_magnitude_sobel (apr, parts, output, deltas);
64- } else {
65- APRNumerics::gradient_magnitude_cfd (apr, parts, output, deltas);
62+ bool done = false ;
63+
64+ if (options.use_cuda ) {
65+ #ifdef APR_USE_CUDA
66+ auto access = apr.gpuAPRHelper ();
67+ auto tree_access = apr.gpuTreeHelper ();
68+ if (options.sobel ) {
69+ APRNumericsGPU::gradient_magnitude_sobel (access, tree_access, parts.data , output.data , deltas);
70+ } else {
71+ APRNumericsGPU::gradient_magnitude_cfd (access, tree_access, parts.data , output.data , deltas);
72+ }
73+ done = true ;
74+ #else
75+ std::cout << " Option -use_cuda was given, but LibAPR was not built with CUDA enabled. Using CPU implementation." << std::endl;
76+ #endif
77+ }
78+
79+ if (!done) {
80+ if (options.sobel ) {
81+ APRNumerics::gradient_magnitude_sobel (apr, parts, output, deltas);
82+ } else {
83+ APRNumerics::gradient_magnitude_cfd (apr, parts, output, deltas);
84+ }
6685 }
6786 timer.stop_timer ();
6887
@@ -144,6 +163,11 @@ cmdLineOptions read_command_line_options(int argc, char **argv){
144163 result.dz = std::stof (get_command_option (argv, argv + argc, " -dz" ));
145164 }
146165
166+ if (command_option_exists (argv, argv + argc, " -use_cuda" ))
167+ {
168+ result.use_cuda = true ;
169+ }
170+
147171
148172 return result;
149173
0 commit comments