| 61 | } |
| 62 | |
| 63 | int |
| 64 | main(void) |
| 65 | { |
| 66 | cl_int err; |
| 67 | cl_platform_id platform = 0; |
| 68 | cl_device_id device = 0; |
| 69 | cl_context_properties props[3] = { CL_CONTEXT_PLATFORM, 0, 0 }; |
| 70 | cl_context ctx = 0; |
| 71 | cl_command_queue queue = 0; |
| 72 | cl_mem bufA, bufX; |
| 73 | cl_event event = NULL; |
| 74 | int ret = 0; |
| 75 | |
| 76 | /* Setup OpenCL environment. */ |
| 77 | err = clGetPlatformIDs(1, &platform, NULL); |
| 78 | if (err != CL_SUCCESS) { |
| 79 | printf( "clGetPlatformIDs() failed with %d\n", err ); |
| 80 | return 1; |
| 81 | } |
| 82 | |
| 83 | err = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &device, NULL); |
| 84 | if (err != CL_SUCCESS) { |
| 85 | printf( "clGetDeviceIDs() failed with %d\n", err ); |
| 86 | return 1; |
| 87 | } |
| 88 | |
| 89 | props[1] = (cl_context_properties)platform; |
| 90 | ctx = clCreateContext(props, 1, &device, NULL, NULL, &err); |
| 91 | if (err != CL_SUCCESS) { |
| 92 | printf( "clCreateContext() failed with %d\n", err ); |
| 93 | return 1; |
| 94 | } |
| 95 | |
| 96 | queue = clCreateCommandQueue(ctx, device, 0, &err); |
| 97 | if (err != CL_SUCCESS) { |
| 98 | printf( "clCreateCommandQueue() failed with %d\n", err ); |
| 99 | clReleaseContext(ctx); |
| 100 | return 1; |
| 101 | } |
| 102 | |
| 103 | /* Setup clblas. */ |
| 104 | err = clblasSetup(); |
| 105 | if (err != CL_SUCCESS) { |
| 106 | printf("clblasSetup() failed with %d\n", err); |
| 107 | clReleaseCommandQueue(queue); |
| 108 | clReleaseContext(ctx); |
| 109 | return 1; |
| 110 | } |
| 111 | |
| 112 | /* Prepare OpenCL memory objects and place matrices inside them. */ |
| 113 | bufA = clCreateBuffer(ctx, CL_MEM_READ_ONLY, N * N * sizeof(cl_float), |
| 114 | NULL, &err); |
| 115 | bufX = clCreateBuffer(ctx, CL_MEM_READ_WRITE, N * sizeof(cl_float), |
| 116 | NULL, &err); |
| 117 | |
| 118 | err = clEnqueueWriteBuffer(queue, bufA, CL_TRUE, 0, |
| 119 | N * N * sizeof(cl_float), A, 0, NULL, NULL); |
| 120 | err = clEnqueueWriteBuffer(queue, bufX, CL_TRUE, 0, |
nothing calls this directly
no test coverage detected