Skip to content

Commit 5d1c559

Browse files
Fix blur example usage of clGetDeviceInfo (#136)
`blur` example is retrieving `CL_DEVICE_OPENCL_C_VERSION` in a fixed sized array of 64 bytes, CL spec does not specify a limit to the output length. Therefore, the test may fail if the version is longer than 64 bytes. This change fixes the issue by querying `clGetDeviceInfo` for the expected output size. Signed-off-by: Michael Rizkalla <michael.rizkalla@arm.com>
1 parent c2b3b60 commit 5d1c559

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

samples/core/blur/main.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,10 +1062,16 @@ int main(int argc, char *argv[])
10621062
// supported by each device is used to compile the program. Therefore,
10631063
// it's only necessary to add the -cl-std option for 2.0 and 3.0 OpenCL
10641064
// versions.
1065-
char dev_version[64];
1065+
size_t dev_version_size = 0;
1066+
char *dev_version = NULL;
1067+
OCLERROR_RET(clGetDeviceInfo(s.device, CL_DEVICE_OPENCL_C_VERSION, 0, NULL,
1068+
&dev_version_size),
1069+
error, dev);
1070+
1071+
dev_version = malloc(dev_version_size);
10661072
OCLERROR_RET(clGetDeviceInfo(s.device, CL_DEVICE_OPENCL_C_VERSION,
1067-
sizeof(dev_version), &dev_version, NULL),
1068-
error, end);
1073+
dev_version_size, dev_version, NULL),
1074+
error, dev);
10691075
char compiler_options[1024] = "";
10701076
if (opencl_version_contains(dev_version, "3."))
10711077
{
@@ -1075,6 +1081,8 @@ int main(int argc, char *argv[])
10751081
{
10761082
strcat(compiler_options, "-cl-std=CL2.0 ");
10771083
}
1084+
free(dev_version);
1085+
dev_version = NULL;
10781086

10791087
/// Create image buffers
10801088
const cl_image_desc desc = { .image_type = CL_MEM_OBJECT_IMAGE2D,
@@ -1238,6 +1246,8 @@ int main(int argc, char *argv[])
12381246
OCLERROR_RET(clReleaseMemObject(s.output_image_buf), end_error, inbuf);
12391247
inbuf:
12401248
OCLERROR_RET(clReleaseMemObject(s.input_image_buf), end_error, outim);
1249+
dev:
1250+
if (dev_version) free(dev_version);
12411251
outim:
12421252
free(s.output_image.pixels);
12431253
inim:

0 commit comments

Comments
 (0)