MCPcopy Create free account
hub / github.com/XpuOS/xsched / OclTask

Method OclTask

platforms/example/test/src/task.cpp:5–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3#include "xsched/opencl/hal.h"
4
5OclTask::OclTask(cl_device_type dev_type, const char *kern_name, const char *kern_code)
6{
7 // get platforms
8 cl_uint plat_num;
9 OCL_ASSERT(clGetPlatformIDs(0, nullptr, &plat_num));
10 cl_platform_id *plat_ids = new cl_platform_id[plat_num];
11 OCL_ASSERT(clGetPlatformIDs(plat_num, plat_ids, nullptr));
12 // print platform info
13 for (cl_uint i = 0; i < plat_num; ++i) {
14 char plat_name[128];
15 OCL_ASSERT(clGetPlatformInfo(plat_ids[i], CL_PLATFORM_NAME, sizeof(plat_name), plat_name, nullptr));
16 XINFO("found platform %d: %s", i, plat_name);
17 }
18 // select platform
19 plat_ = plat_ids[0];
20 delete[] plat_ids;
21
22 // get devices
23 cl_uint dev_num;
24 OCL_ASSERT(clGetDeviceIDs(plat_, dev_type, 0, nullptr, &dev_num));
25 cl_device_id *dev_ids = new cl_device_id[dev_num];
26 OCL_ASSERT(clGetDeviceIDs(plat_, dev_type, dev_num, dev_ids, nullptr));
27 // print device info
28 for (cl_uint i = 0; i < dev_num; ++i) {
29 char dev_name[128];
30 OCL_ASSERT(clGetDeviceInfo(dev_ids[i], CL_DEVICE_NAME, sizeof(dev_name), dev_name, nullptr));
31 XINFO("found device %d: %s", i, dev_name);
32 }
33 // select device
34 dev_ = dev_ids[0];
35 delete[] dev_ids;
36
37 // create context
38 cl_int errcode;
39 ctx_ = clCreateContext(nullptr, 1, &dev_, nullptr, nullptr, &errcode);
40 OCL_ASSERT(errcode);
41
42 // create command queue
43 cmdq_ = clCreateCommandQueueWithProperties(ctx_, dev_, nullptr, &errcode);
44 OCL_ASSERT(errcode);
45
46 // create program
47 prog_ = clCreateProgramWithSource(ctx_, 1, &kern_code, nullptr, &errcode);
48 OCL_ASSERT(errcode);
49 OCL_ASSERT(clBuildProgram(prog_, 1, &dev_, nullptr, nullptr, nullptr));
50
51 // create kernel
52 kern_ = clCreateKernel(prog_, kern_name, &errcode);
53 OCL_ASSERT(errcode);
54}
55
56OclTask::~OclTask()
57{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected