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

Function main

src/samples/example_sspr2.c:82–182  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

80}
81
82int
83main(void)
84{
85 cl_int err;
86 cl_platform_id platform = 0;
87 cl_device_id device = 0;
88 cl_context_properties props[3] = { CL_CONTEXT_PLATFORM, 0, 0 };
89 cl_context ctx = 0;
90 cl_command_queue queue = 0;
91 cl_mem bufAP, bufX, bufY;
92 cl_event event = NULL;
93 int ret = 0, numElementsAP;
94
95 /* Setup OpenCL environment. */
96 err = clGetPlatformIDs(1, &platform, NULL);
97 if (err != CL_SUCCESS) {
98 printf( "clGetPlatformIDs() failed with %d\n", err );
99 return 1;
100 }
101
102 err = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &device, NULL);
103 if (err != CL_SUCCESS) {
104 printf( "clGetDeviceIDs() failed with %d\n", err );
105 return 1;
106 }
107
108 props[1] = (cl_context_properties)platform;
109 ctx = clCreateContext(props, 1, &device, NULL, NULL, &err);
110 if (err != CL_SUCCESS) {
111 printf( "clCreateContext() failed with %d\n", err );
112 return 1;
113 }
114
115 queue = clCreateCommandQueue(ctx, device, 0, &err);
116 if (err != CL_SUCCESS) {
117 printf( "clCreateCommandQueue() failed with %d\n", err );
118 clReleaseContext(ctx);
119 return 1;
120 }
121
122 /* Setup clblas. */
123 err = clblasSetup();
124 if (err != CL_SUCCESS) {
125 printf("clblasSetup() failed with %d\n", err);
126 clReleaseCommandQueue(queue);
127 clReleaseContext(ctx);
128 return 1;
129 }
130
131 numElementsAP = (N * (N+1)) / 2; // To get number of elements in a packed matrix
132
133 /* Prepare OpenCL memory objects and place matrices inside them. */
134 bufAP = clCreateBuffer(ctx, CL_MEM_READ_WRITE, (numElementsAP * sizeof(cl_float)),
135 NULL, &err);
136 bufX = clCreateBuffer(ctx, CL_MEM_READ_ONLY, N * sizeof(cl_float),
137 NULL, &err);
138 bufY = clCreateBuffer(ctx, CL_MEM_READ_ONLY, N * sizeof(cl_float),
139 NULL, &err);

Callers

nothing calls this directly

Calls 4

clblasSetupFunction · 0.85
clblasSspr2Function · 0.85
clblasTeardownFunction · 0.85
printResultFunction · 0.70

Tested by

no test coverage detected