| 79 | } |
| 80 | |
| 81 | int |
| 82 | main(void) |
| 83 | { |
| 84 | cl_int err; |
| 85 | cl_platform_id platform = 0; |
| 86 | cl_device_id device = 0; |
| 87 | cl_context_properties props[3] = { CL_CONTEXT_PLATFORM, 0, 0 }; |
| 88 | cl_context ctx = 0; |
| 89 | cl_command_queue queue = 0; |
| 90 | cl_mem bufA, bufB, bufC; |
| 91 | cl_event event = NULL; |
| 92 | int ret = 0; |
| 93 | |
| 94 | /* Setup OpenCL environment. */ |
| 95 | err = clGetPlatformIDs(1, &platform, NULL); |
| 96 | if (err != CL_SUCCESS) { |
| 97 | printf( "clGetPlatformIDs() failed with %d\n", err ); |
| 98 | return 1; |
| 99 | } |
| 100 | |
| 101 | err = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &device, NULL); |
| 102 | if (err != CL_SUCCESS) { |
| 103 | printf( "clGetDeviceIDs() failed with %d\n", err ); |
| 104 | return 1; |
| 105 | } |
| 106 | |
| 107 | props[1] = (cl_context_properties)platform; |
| 108 | ctx = clCreateContext(props, 1, &device, NULL, NULL, &err); |
| 109 | if (err != CL_SUCCESS) { |
| 110 | printf( "clCreateContext() failed with %d\n", err ); |
| 111 | return 1; |
| 112 | } |
| 113 | |
| 114 | queue = clCreateCommandQueue(ctx, device, 0, &err); |
| 115 | if (err != CL_SUCCESS) { |
| 116 | printf( "clCreateCommandQueue() failed with %d\n", err ); |
| 117 | clReleaseContext(ctx); |
| 118 | return 1; |
| 119 | } |
| 120 | |
| 121 | /* Setup clblas. */ |
| 122 | err = clblasSetup(); |
| 123 | if (err != CL_SUCCESS) { |
| 124 | printf("clblasSetup() failed with %d\n", err); |
| 125 | clReleaseCommandQueue(queue); |
| 126 | clReleaseContext(ctx); |
| 127 | return 1; |
| 128 | } |
| 129 | |
| 130 | /* Prepare OpenCL memory objects and place matrices inside them. */ |
| 131 | bufA = clCreateBuffer(ctx, CL_MEM_READ_ONLY, M * M * sizeof(*A), |
| 132 | NULL, &err); |
| 133 | bufB = clCreateBuffer(ctx, CL_MEM_READ_ONLY, M * N * sizeof(*B), |
| 134 | NULL, &err); |
| 135 | bufC = clCreateBuffer(ctx, CL_MEM_READ_WRITE, M * N * sizeof(*C), |
| 136 | NULL, &err); |
| 137 | |
| 138 | err = clEnqueueWriteBuffer(queue, bufA, CL_TRUE, 0, |
nothing calls this directly
no test coverage detected