| 34 | } |
| 35 | |
| 36 | ocl_executable_object::ocl_executable_object(const cl::Context& ctx, cl::Device& dev, |
| 37 | hcf_object_id source, const std::string& code_image, const kernel_configuration &config) |
| 38 | : _source{source}, _ctx{ctx}, _dev{dev}, _id{config.generate_id()} { |
| 39 | |
| 40 | std::vector<char> ir(code_image.size()); |
| 41 | std::memcpy(ir.data(), code_image.data(), code_image.size()); |
| 42 | |
| 43 | cl_int err = 0; |
| 44 | _program = cl::Program(_ctx, ir, false, &err); |
| 45 | |
| 46 | if(err != CL_SUCCESS) { |
| 47 | _build_status = register_error( |
| 48 | __acpp_here(), |
| 49 | error_info{"ocl_code_object: Construction of CL program failed", |
| 50 | error_code{"CL", static_cast<int>(err)}}); |
| 51 | return; |
| 52 | } |
| 53 | |
| 54 | std::string options_string="-cl-uniform-work-group-size"; |
| 55 | for(const auto& flag : config.build_flags()) { |
| 56 | if(flag == kernel_build_flag::fast_math) { |
| 57 | options_string += " -cl-fast-relaxed-math -cl-denorms-are-zero"; |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | err = _program.build( |
| 62 | _dev, options_string.c_str()); |
| 63 | |
| 64 | if(err != CL_SUCCESS) { |
| 65 | std::string build_log = "<build log not available>"; |
| 66 | cl_int access_build_log_err = |
| 67 | _program.getBuildInfo(_dev, CL_PROGRAM_BUILD_LOG, &build_log); |
| 68 | |
| 69 | std::string msg = "ocl_code_object: Building CL program failed."; |
| 70 | if(access_build_log_err == CL_SUCCESS) |
| 71 | msg += " Build log: " + build_log; |
| 72 | |
| 73 | _build_status = register_error( |
| 74 | __acpp_here(), error_info{msg, |
| 75 | error_code{"CL", static_cast<int>(err)}}); |
| 76 | return; |
| 77 | } |
| 78 | |
| 79 | // clCreateKernelsInProgram seems to not work reliably |
| 80 | //err = _program.createKernels(&kernels); |
| 81 | std::string concatenated_name_list; |
| 82 | err = _program.getInfo(CL_PROGRAM_KERNEL_NAMES, &concatenated_name_list); |
| 83 | |
| 84 | if(err != CL_SUCCESS) { |
| 85 | _build_status = register_error( |
| 86 | __acpp_here(), |
| 87 | error_info{ |
| 88 | "ocl_code_object: Could not obtain kernel names in program", |
| 89 | error_code{"CL", static_cast<int>(err)}}); |
| 90 | return; |
| 91 | } |
| 92 | |
| 93 | _kernel_names = |
nothing calls this directly
no test coverage detected