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