| 90 | } |
| 91 | |
| 92 | bool CLSymbols::load(const std::vector<std::string> &libraries_filenames, bool use_loader) |
| 93 | { |
| 94 | void *handle = nullptr; |
| 95 | unsigned int index = 0; |
| 96 | for (index = 0; index < libraries_filenames.size(); ++index) |
| 97 | { |
| 98 | handle = dlopen(libraries_filenames[index].c_str(), RTLD_LAZY | RTLD_LOCAL); |
| 99 | if (handle != nullptr) |
| 100 | { |
| 101 | break; |
| 102 | } |
| 103 | } |
| 104 | if (index == libraries_filenames.size()) |
| 105 | { |
| 106 | // Set status of loading to failed |
| 107 | _loaded.second = false; |
| 108 | return false; |
| 109 | } |
| 110 | |
| 111 | #ifdef __ANDROID__ |
| 112 | typedef void *(*loadOpenCLPointer_t)(const char *name); |
| 113 | loadOpenCLPointer_t loadOpenCLPointer; |
| 114 | if (use_loader) |
| 115 | { |
| 116 | typedef void (*enableOpenCL_t)(); |
| 117 | enableOpenCL_t enableOpenCL = reinterpret_cast<enableOpenCL_t>(dlsym(handle, "enableOpenCL")); |
| 118 | enableOpenCL(); |
| 119 | |
| 120 | loadOpenCLPointer = reinterpret_cast<loadOpenCLPointer_t>(dlsym(handle, "loadOpenCLPointer")); |
| 121 | } |
| 122 | else |
| 123 | { |
| 124 | loadOpenCLPointer = nullptr; |
| 125 | } |
| 126 | #define LOAD_FUNCTION_PTR(func_name, _handle) \ |
| 127 | func_name##_ptr = reinterpret_cast<decltype(func_name) *>(use_loader ? loadOpenCLPointer(#func_name) \ |
| 128 | : dlsym(handle, #func_name)); |
| 129 | #else /* __ANDROID__ */ |
| 130 | (void)use_loader; // Avoid unused warning |
| 131 | #define LOAD_FUNCTION_PTR(func_name, handle) \ |
| 132 | func_name##_ptr = reinterpret_cast<decltype(func_name) *>(dlsym(handle, #func_name)); |
| 133 | #endif /* __ANDROID__ */ |
| 134 | |
| 135 | #define LOAD_EXTENSION_FUNCTION_PTR(func_name, platform_id) \ |
| 136 | func_name##_ptr = \ |
| 137 | reinterpret_cast<decltype(func_name) *>(clGetExtensionFunctionAddressForPlatform(platform_id, #func_name)); |
| 138 | |
| 139 | LOAD_FUNCTION_PTR(clCreateContext, handle); |
| 140 | LOAD_FUNCTION_PTR(clCreateContextFromType, handle); |
| 141 | LOAD_FUNCTION_PTR(clCreateCommandQueue, handle); |
| 142 | LOAD_FUNCTION_PTR(clCreateCommandQueueWithProperties, handle); |
| 143 | LOAD_FUNCTION_PTR(clGetContextInfo, handle); |
| 144 | LOAD_FUNCTION_PTR(clBuildProgram, handle); |
| 145 | LOAD_FUNCTION_PTR(clEnqueueNDRangeKernel, handle); |
| 146 | LOAD_FUNCTION_PTR(clSetKernelArg, handle); |
| 147 | LOAD_FUNCTION_PTR(clReleaseKernel, handle); |
| 148 | LOAD_FUNCTION_PTR(clCreateProgramWithSource, handle); |
| 149 | LOAD_FUNCTION_PTR(clCreateBuffer, handle); |
no test coverage detected