Skip to content

Commit

Permalink
Update SVM kernel example.
Browse files Browse the repository at this point in the history
  • Loading branch information
Prince781 committed Apr 2, 2019
1 parent 62c908a commit 36f0b73
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/opencl/svm-kernel.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <CL/cl.h>
#include <string.h>

#include "clext.h"
#include "util.h"
Expand All @@ -22,6 +23,22 @@ static void print_mat(const char *name, float *m, int len) {
}
}

static const char *svm_caps_tostr(cl_device_svm_capabilities caps) {
static char buf[1024];

buf[0] = 0;
if (caps & CL_DEVICE_SVM_COARSE_GRAIN_BUFFER)
strcat(buf, "coarse grain");
if (caps & CL_DEVICE_SVM_FINE_GRAIN_BUFFER)
strcat(buf, ", fine grain");
if (caps & CL_DEVICE_SVM_FINE_GRAIN_SYSTEM)
strcat(buf, " (system)");
if (caps & CL_DEVICE_SVM_ATOMICS)
strcat(buf, ", atomics");

return buf;
}

int main(int argc, char *argv[]) {
cl_uint platformIdCount = 0;
cl_platform_id *platformIds = NULL;
Expand Down Expand Up @@ -61,9 +78,14 @@ int main(int argc, char *argv[]) {

for (cl_uint i = 0; i < deviceIdCount; ++i) {
char device_name[1024];
cl_device_svm_capabilities caps;
const char *caps_str;

clGetDeviceInfo(deviceIds[i], CL_DEVICE_NAME, sizeof device_name, device_name, NULL);
clGetDeviceInfo(deviceIds[i], CL_DEVICE_SVM_CAPABILITIES, sizeof caps, &caps, NULL);
caps_str = svm_caps_tostr(caps);
printf("Device [%u] = %s\n", i, device_name);
printf(" SVM capabilities: %s\n", caps_str);
}

// create an OpenCL context
Expand Down

0 comments on commit 36f0b73

Please sign in to comment.