Explorar o código

socl/examples: check that the number of devices is not zero

Nathalie Furmento %!s(int64=13) %!d(string=hai) anos
pai
achega
c334045fb8

+ 4 - 2
socl/examples/basic/basic.c

@@ -86,8 +86,10 @@ int main(int UNUSED(argc), char** UNUSED(argv)) {
       if (num_devices != 0)
          break;
    }
-   if (num_devices == 0)
-      error("No OpenCL device found\n");
+   if (num_devices == 0) {
+      printf("No OpenCL device found\n");
+      exit(77);
+   }
 
    printf("Creating context...\n");
    cl_context_properties properties[] = {CL_CONTEXT_PLATFORM, (cl_context_properties)platforms[platform_idx], 0};

+ 5 - 1
socl/examples/clinfo/clinfo.c

@@ -46,7 +46,6 @@ main(void) {
    err = clGetPlatformIDs(num_platforms, platforms, NULL);
    checkErr(err, "Unable to get platform list");
 
-
    // Iteratate over platforms
    printf("Number of platforms:\t\t\t\t %d\n", num_platforms);
 
@@ -92,6 +91,11 @@ main(void) {
 
          err = clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, 0, NULL, &num_devices);
          checkErr(err, "clGetDeviceIds(CL_DEVICE_TYPE_ALL)");
+	 if (num_devices == 0) {
+	      printf("  No devices found\n");
+	      continue;
+	 }
+
          devices = (cl_device_id*)malloc(sizeof(cl_device_id)*num_devices);
 
          err = clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, num_devices, devices, NULL);

+ 4 - 0
socl/examples/matmul/matmul.c

@@ -240,6 +240,10 @@ int main(int argc, const char** argv) {
 			devs[p] = 0;
 			continue;
 		}
+		if (devs[p] == 0) {
+		     printf("No OpenCL device found\n");
+		     exit(77);
+		}
 		check(err);
 		if (devs[p] == 0)
 			continue;