MCPcopy Create free account
hub / github.com/defold/defold / init

Method init

engine/dlib/src/basis/encoder/basisu_opencl.cpp:76–168  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

74 cl_program get_program() const { return m_program; }
75
76 bool init(bool force_serialization)
77 {
78 deinit();
79
80 interval_timer tm;
81 tm.start();
82
83 cl_uint num_platforms = 0;
84 cl_int ret = clGetPlatformIDs(0, NULL, &num_platforms);
85 if (ret != CL_SUCCESS)
86 {
87 ocl_error_printf("ocl::init: clGetPlatformIDs() failed with %i\n", ret);
88 return false;
89 }
90
91 if ((!num_platforms) || (num_platforms > INT_MAX))
92 {
93 ocl_error_printf("ocl::init: clGetPlatformIDs() returned an invalid number of num_platforms\n");
94 return false;
95 }
96
97 std::vector<cl_platform_id> platforms(num_platforms);
98
99 ret = clGetPlatformIDs(num_platforms, platforms.data(), NULL);
100 if (ret != CL_SUCCESS)
101 {
102 ocl_error_printf("ocl::init: clGetPlatformIDs() failed\n");
103 return false;
104 }
105
106 cl_uint num_devices = 0;
107 ret = clGetDeviceIDs(platforms[0], CL_DEVICE_TYPE_GPU, 1, &m_device_id, &num_devices);
108
109 if (ret == CL_DEVICE_NOT_FOUND)
110 {
111 ocl_error_printf("ocl::init: Couldn't get any GPU device ID's, trying CL_DEVICE_TYPE_CPU\n");
112
113 ret = clGetDeviceIDs(platforms[0], CL_DEVICE_TYPE_CPU, 1, &m_device_id, &num_devices);
114 }
115
116 if (ret != CL_SUCCESS)
117 {
118 ocl_error_printf("ocl::init: Unable to get any device ID's\n");
119
120 m_device_id = nullptr;
121 return false;
122 }
123
124 ret = clGetDeviceInfo(m_device_id,
125 CL_DEVICE_SINGLE_FP_CONFIG,
126 sizeof(m_dev_fp_config),
127 &m_dev_fp_config,
128 nullptr);
129 if (ret != CL_SUCCESS)
130 {
131 ocl_error_printf("ocl::init: clGetDeviceInfo() failed\n");
132 return false;
133 }

Callers

nothing calls this directly

Calls 7

ocl_error_printfFunction · 0.85
clGetDeviceInfoFunction · 0.85
clGetPlatformInfoFunction · 0.85
clCreateCommandQueueFunction · 0.85
get_elapsed_secsMethod · 0.80
startMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected