| 258 | } |
| 259 | |
| 260 | int32_t Program::link(const std::vector<Device*>& devices, size_t numInputs, |
| 261 | const std::vector<Program*>& inputPrograms, const char* options, |
| 262 | void(CL_CALLBACK* notifyFptr)(cl_program, void*), void* data, |
| 263 | bool optionChangable) { |
| 264 | ScopedLock sl(&programLock_); |
| 265 | |
| 266 | int32_t retval = CL_SUCCESS; |
| 267 | |
| 268 | if (symbolTable_ == NULL) { |
| 269 | symbolTable_ = new symbols_t; |
| 270 | if (symbolTable_ == NULL) { |
| 271 | return CL_OUT_OF_HOST_MEMORY; |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | // Clear the program object |
| 276 | clear(); |
| 277 | |
| 278 | // Process build options. |
| 279 | std::string cppstr(options ? options : ""); |
| 280 | optionChangable &= adjustOptionsOnIgnoreEnv(cppstr); |
| 281 | |
| 282 | // Link the program programs associated with the given devices. |
| 283 | for (const auto& it : devices) { |
| 284 | option::Options parsedOptions; |
| 285 | constexpr bool LinkOptsOnly = true; |
| 286 | if (!ParseAllOptions(cppstr, parsedOptions, optionChangable, LinkOptsOnly)) { |
| 287 | programLog_ = parsedOptions.optionsLog(); |
| 288 | LogError("Parsing link options failed."); |
| 289 | return CL_INVALID_LINKER_OPTIONS; |
| 290 | } |
| 291 | // find the corresponding device program in each input program |
| 292 | std::vector<device::Program*> inputDevPrograms(numInputs); |
| 293 | bool found = false; |
| 294 | for (size_t i = 0; i < numInputs; ++i) { |
| 295 | Program& inputProgram = *inputPrograms[i]; |
| 296 | if (inputProgram.language_ == SPIRV) { |
| 297 | parsedOptions.oVariables->BinaryIsSpirv = true; |
| 298 | } |
| 299 | const deviceprograms_t& inputDevProgs = inputProgram.devicePrograms(); |
| 300 | const auto findIt = inputDevProgs.find(it); |
| 301 | if (findIt == inputDevProgs.cend()) { |
| 302 | if (found) break; |
| 303 | continue; |
| 304 | } |
| 305 | inputDevPrograms[i] = findIt->second; |
| 306 | found = true; |
| 307 | } |
| 308 | if (inputDevPrograms.size() == 0) { |
| 309 | continue; |
| 310 | } |
| 311 | if (inputDevPrograms.size() < numInputs) { |
| 312 | return CL_INVALID_VALUE; |
| 313 | } |
| 314 | |
| 315 | device::Program* devProgram = getDeviceProgram(*it); |
| 316 | if (devProgram == NULL) { |
| 317 | const binary_t& bin = binary(*it); |
no test coverage detected