Skip to content

Commit

Permalink
Removed OpenCL 2.0 requirement in blur sample
Browse files Browse the repository at this point in the history
  • Loading branch information
Beanavil committed Jun 18, 2024
1 parent c2f6b75 commit 0d849e1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 47 deletions.
5 changes: 0 additions & 5 deletions samples/core/blur/blur.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,11 +510,6 @@ std::tuple<bool, bool, bool> BlurCppExample::query_capabilities()
use_subgroup_exchange_relative);
}

bool BlurCppExample::query_opencl_2_0_support()
{
return cl::util::opencl_c_version_contains(device, "2.0");
}

void BlurCppExample::create_image_buffers()
{
input_image_buf = cl::Image2D(
Expand Down
3 changes: 0 additions & 3 deletions samples/core/blur/blur.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ class BlurCppExample {
// Query device and runtime capabilities
std::tuple<bool, bool, bool> query_capabilities();

// Query device support for OpenCL 2.0
bool query_opencl_2_0_support();

void create_image_buffers();

void build_program(std::string kernel_op);
Expand Down
28 changes: 4 additions & 24 deletions samples/core/blur/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1051,18 +1051,6 @@ int main(int argc, char *argv[])
free(name);
}

// 5) query if OpenCL driver version is 2.0
bool opencl_version_2_0 = false;
{
char *driver_version = NULL;
OCLERROR_PAR(
driver_version = cl_util_get_device_info(s.device, CL_DRIVER_VERSION, &error),
error, clean);
opencl_version_2_0 = strcmp("2.0", driver_version) ? 0 : 1;
clean:
free(driver_version);
}

/// Create image buffers
const cl_image_desc desc = { .image_type = CL_MEM_OBJECT_IMAGE2D,
.image_width = s.input_image.width,
Expand Down Expand Up @@ -1128,25 +1116,21 @@ int main(int argc, char *argv[])
error, prg);

/// Subgroup exchange in dual-pass blur
if (use_subgroup_exchange_relative && opencl_version_2_0)
if (use_subgroup_exchange_relative)
{
printf("Dual-pass subgroup relative exchange blur\n");

kernel_op[0] = '\0';
// cl_khr_subgroup_shuffle_relative requires OpenCL 2.0
strcat(kernel_op, " -cl-std=CL2.0 ");
strcat(kernel_op, "-D USE_SUBGROUP_EXCHANGE_RELATIVE ");
OCLERROR_RET(dual_pass_subgroup_exchange_box_blur(
&s, (cl_int)blur_opts.size),
error, prg);
}
if (use_subgroup_exchange && opencl_version_2_0)
if (use_subgroup_exchange)
{
printf("Dual-pass subgroup exchange blur\n");

kernel_op[0] = '\0';
// cl_khr_subgroup_shuffle requires OpenCL 2.0
strcat(kernel_op, " -cl-std=CL2.0 ");
strcat(kernel_op, "-D USE_SUBGROUP_EXCHANGE ");

OCLERROR_RET(dual_pass_subgroup_exchange_box_blur(
Expand Down Expand Up @@ -1185,26 +1169,22 @@ int main(int argc, char *argv[])
}

/// Subgroup exchange in dual-pass Gaussian blur
if (use_subgroup_exchange_relative && opencl_version_2_0)
if (use_subgroup_exchange_relative)
{
printf("Dual-pass subgroup relative exchange Gaussian blur\n");

kernel_op[0] = '\0';
// cl_khr_subgroup_shuffle_relative requires OpenCL 2.0
strcat(kernel_op, " -cl-std=CL2.0 ");
strcat(kernel_op, "-D USE_SUBGROUP_EXCHANGE_RELATIVE ");

OCLERROR_RET(dual_pass_subgroup_exchange_kernel_blur(&s, gauss_size,
gauss_kern),
error, gkrn);
}
if (use_subgroup_exchange && opencl_version_2_0)
if (use_subgroup_exchange)
{
printf("Dual-pass subgroup exchange Gaussian blur\n");

kernel_op[0] = '\0';
// cl_khr_subgroup_shuffle requires OpenCL 2.0
strcat(kernel_op, " -cl-std=CL2.0 ");
strcat(kernel_op, "-D USE_SUBGROUP_EXCHANGE ");

OCLERROR_RET(dual_pass_subgroup_exchange_kernel_blur(&s, gauss_size,
Expand Down
23 changes: 8 additions & 15 deletions samples/core/blur/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ int main(int argc, char* argv[])
std::tie(use_local_mem, use_subgroup_exchange,
use_subgroup_exchange_relative) = blur.query_capabilities();

bool opencl_version_2_0 = blur.query_opencl_2_0_support();

// Create image buffers used for operation. In this example input,
// output and temporary image buffers are used. Temporary buffer is used
// when 2 blur operations in the row are performed. Result of the first
Expand Down Expand Up @@ -87,23 +85,20 @@ int main(int argc, char* argv[])
// file you can find 'USE_SUBGROUP_EXCHANGE_RELATIVE' C-like
// definition switch for blur_box_horizontal_subgroup_exchange
// function. In this case, 2 blur kernel functors are used.
if (use_subgroup_exchange_relative && opencl_version_2_0)
if (use_subgroup_exchange_relative)
{
std::cout << "Dual-pass subgroup relative exchange blur"
<< std::endl;
// cl_khr_subgroup_shuffle_relative requires OpenCL 2.0
blur.build_program(
"-D USE_SUBGROUP_EXCHANGE_RELATIVE -cl-std=CL2.0 ");
blur.build_program("-D USE_SUBGROUP_EXCHANGE_RELATIVE ");
blur.dual_pass_subgroup_exchange_box_blur();
}

// Same as the previous one, but with a different build switch. See
// the blur.cl file for more info about the switch.
if (use_subgroup_exchange && opencl_version_2_0)
if (use_subgroup_exchange)
{
std::cout << "Dual-pass subgroup exchange blur" << std::endl;
// cl_khr_subgroup_shuffle requires OpenCL 2.0
blur.build_program("-D USE_SUBGROUP_EXCHANGE -cl-std=CL2.0 ");
blur.build_program("-D USE_SUBGROUP_EXCHANGE ");
blur.dual_pass_subgroup_exchange_box_blur();
}
} // Box blur
Expand Down Expand Up @@ -135,25 +130,23 @@ int main(int argc, char* argv[])

// Similar to dual_pass_subgroup_exchange_box_blur but with a gauss
// kernel.
if (use_subgroup_exchange_relative && opencl_version_2_0)
if (use_subgroup_exchange_relative)
{
std::cout
<< "Dual-pass subgroup relative exchange Gaussian blur"
<< std::endl;
// cl_khr_subgroup_shuffle_relative requires OpenCL 2.0
blur.build_program(
"-D USE_SUBGROUP_EXCHANGE_RELATIVE -cl-std=CL2.0 ");
"-D USE_SUBGROUP_EXCHANGE_RELATIVE ");
blur.dual_pass_subgroup_exchange_kernel_blur();
}

// Same as the previous one, but with a different build switch. See
// the blur.cl file for more info about the switch.
if (use_subgroup_exchange && opencl_version_2_0)
if (use_subgroup_exchange)
{
std::cout << "Dual-pass subgroup exchange Gaussian blur"
<< std::endl;
// cl_khr_subgroup_shuffle requires OpenCL 2.0
blur.build_program("-D USE_SUBGROUP_EXCHANGE -cl-std=CL2.0 ");
blur.build_program("-D USE_SUBGROUP_EXCHANGE ");
blur.dual_pass_subgroup_exchange_kernel_blur();
}
} // Gaussian blur
Expand Down

0 comments on commit 0d849e1

Please sign in to comment.