MCPcopy Create free account
hub / github.com/clMathLibraries/clSPARSE / getProgram

Method getProgram

src/library/internal/kernel-cache.cpp:110–188  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

108}
109
110const cl::Program* KernelCache::getProgram(cl::CommandQueue& queue,
111 const std::string& program_name,
112 const std::string& params)
113{
114
115 cl_int status;
116 cl::Context context = queue.getInfo<CL_QUEUE_CONTEXT>();
117
118 const char* source = SourceProvider::GetSource(program_name);
119 if (source == nullptr)
120 {
121 std::cout << "Source not found [" << program_name << "]" << std::endl;
122 return nullptr;
123 }
124 size_t size = std::char_traits<char>::length(source);
125
126 cl::Program::Sources sources;
127
128 std::pair<const char*, size_t> pair =
129 std::make_pair(source, size);
130 sources.push_back(pair);
131
132 std::vector<cl::Device> devices;
133
134 auto d = queue.getInfo<CL_QUEUE_DEVICE>(&status);
135
136 if (status != CL_SUCCESS)
137 {
138 std::cout << "Problem with getting device form queue: "
139 << status << std::endl;
140
141 return nullptr;
142 }
143 devices.push_back(d);
144
145 cl::Program* program;
146
147 program = new cl::Program(context, sources);
148 status = program->build(devices, params.c_str());
149
150 // this should catch the nasty situation when you improperly define kernel
151 // string parameters ie: "space" after equal "-DTYPE= " + OclTypeTraits
152 if (status == CL_INVALID_BUILD_OPTIONS)
153 {
154 std::cout << "Error during program compilation err = "
155 << status << "(CL_INVALID_BUILD_OPTIONS)"
156 << "\n\tCheck the definiton of the program parameters"
157 << std::endl;
158 return nullptr;
159 }
160 else if (status != CL_SUCCESS)
161 {
162
163 std::cout << "#######################################" << std::endl;
164 std::cout << "sources: ";
165 for (auto& s : sources)
166 {
167 std::cout << s.first << std::endl;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected