| 37 | |
| 38 | template <typename T> |
| 39 | bool buildProgramFromSource(cl::Program& program, cl::Context& context, std::string src, bool isFile = false) |
| 40 | { |
| 41 | #ifdef USE_OPENCL |
| 42 | try |
| 43 | { |
| 44 | std::string type = getType<T>(); |
| 45 | if (isFile) |
| 46 | { |
| 47 | std::ifstream programFile((char*) src.c_str()); |
| 48 | std::string programString(std::istreambuf_iterator<char>(programFile), |
| 49 | (std::istreambuf_iterator<char>())); |
| 50 | src = programString; |
| 51 | } |
| 52 | //src = std::regex_replace(src, std::regex("Type"), std::string(type)); |
| 53 | replaceAll(src, "Type", type); |
| 54 | program = cl::Program(context, src, true); |
| 55 | } |
| 56 | #if defined(USE_OPENCL) && defined(CL_HPP_ENABLE_EXCEPTIONS) |
| 57 | catch (cl::BuildError e) |
| 58 | { |
| 59 | auto buildInfo = e.getBuildLog(); |
| 60 | for (auto &pair : buildInfo) |
| 61 | std::cerr << "Device: " << pair.first.getInfo<CL_DEVICE_NAME>() << std::endl << |
| 62 | pair.second << std::endl; |
| 63 | error("OpenCL error: OpenPose crashed due to the previously printed errors.", |
| 64 | __LINE__, __FUNCTION__, __FILE__); |
| 65 | } |
| 66 | #endif |
| 67 | catch (const std::exception& e) |
| 68 | { |
| 69 | error(e.what(), __LINE__, __FUNCTION__, __FILE__); |
| 70 | } |
| 71 | return true; |
| 72 | #else |
| 73 | UNUSED(program); |
| 74 | UNUSED(src); |
| 75 | UNUSED(isFile); |
| 76 | error("OpenPose must be compiled with the `USE_OPENCL` macro definition in order to use this" |
| 77 | " functionality.", __LINE__, __FUNCTION__, __FILE__); |
| 78 | return false; |
| 79 | #endif |
| 80 | } |
| 81 | #endif |
| 82 | |
| 83 | std::shared_ptr<OpenCL> OpenCL::getInstance(const int deviceId, const int deviceType, bool getFromVienna) |
nothing calls this directly
no test coverage detected