MCPcopy Create free account
hub / github.com/clMathLibraries/clBLAS / main

Function main

src/samples/example_scopy.c:71–164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69}
70
71int
72main(void)
73{
74 cl_int err;
75 cl_platform_id platform = 0;
76 cl_device_id device = 0;
77 cl_context_properties props[3] = { CL_CONTEXT_PLATFORM, 0, 0 };
78 cl_context ctx = 0;
79 cl_command_queue queue = 0;
80 cl_mem bufX, bufY;
81 cl_event event = NULL;
82 int ret = 0;
83 int lenX = 1 + (N-1)*abs(incx);
84 int lenY = 1 + (N-1)*abs(incy);
85
86 /* Setup OpenCL environment. */
87 err = clGetPlatformIDs(1, &platform, NULL);
88 if (err != CL_SUCCESS) {
89 printf( "clGetPlatformIDs() failed with %d\n", err );
90 return 1;
91 }
92
93 err = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &device, NULL);
94 if (err != CL_SUCCESS) {
95 printf( "clGetDeviceIDs() failed with %d\n", err );
96 return 1;
97 }
98
99 props[1] = (cl_context_properties)platform;
100 ctx = clCreateContext(props, 1, &device, NULL, NULL, &err);
101 if (err != CL_SUCCESS) {
102 printf( "clCreateContext() failed with %d\n", err );
103 return 1;
104 }
105
106 queue = clCreateCommandQueue(ctx, device, 0, &err);
107 if (err != CL_SUCCESS) {
108 printf( "clCreateCommandQueue() failed with %d\n", err );
109 clReleaseContext(ctx);
110 return 1;
111 }
112
113 /* Setup clblas. */
114 err = clblasSetup();
115 if (err != CL_SUCCESS) {
116 printf("clblasSetup() failed with %d\n", err);
117 clReleaseCommandQueue(queue);
118 clReleaseContext(ctx);
119 return 1;
120 }
121
122 /* Prepare OpenCL memory objects and place matrices inside them. */
123 bufX = clCreateBuffer(ctx, CL_MEM_READ_ONLY, (lenX*sizeof(cl_float)), NULL, &err);
124 bufY = clCreateBuffer(ctx, CL_MEM_READ_WRITE, (lenY*sizeof(cl_float)), NULL, &err);
125
126 err = clEnqueueWriteBuffer(queue, bufX, CL_TRUE, 0, (lenX*sizeof(cl_float)), X, 0, NULL, NULL);
127 err = clEnqueueWriteBuffer(queue, bufY, CL_TRUE, 0, (lenY*sizeof(cl_float)), Y, 0, NULL, NULL);
128

Callers

nothing calls this directly

Calls 4

clblasSetupFunction · 0.85
clblasScopyFunction · 0.85
clblasTeardownFunction · 0.85
printResultFunction · 0.70

Tested by

no test coverage detected