| 1285 | } |
| 1286 | |
| 1287 | int32_t Program::build(const std::string& sourceCode, const char* origOptions, |
| 1288 | amd::option::Options* options) { |
| 1289 | if (AMD_OCL_SUBST_OBJFILE != NULL && |
| 1290 | trySubstObjFile(AMD_OCL_SUBST_OBJFILE, sourceCode, options)) { |
| 1291 | return buildError(); |
| 1292 | } |
| 1293 | |
| 1294 | uint64_t start_time = 0; |
| 1295 | if (options->oVariables->EnableBuildTiming) { |
| 1296 | buildLog_ = "\nStart timing major build components.....\n\n"; |
| 1297 | start_time = amd::Os::timeNanos(); |
| 1298 | } |
| 1299 | |
| 1300 | lastBuildOptionsArg_ = origOptions ? origOptions : ""; |
| 1301 | if (options) { |
| 1302 | compileOptions_ = options->origOptionStr; |
| 1303 | } |
| 1304 | |
| 1305 | buildStatus_ = CL_BUILD_IN_PROGRESS; |
| 1306 | if (!initBuild(options)) { |
| 1307 | buildStatus_ = CL_BUILD_ERROR; |
| 1308 | if (buildLog_.empty()) { |
| 1309 | buildLog_ = "Internal error: Compilation init failed."; |
| 1310 | } |
| 1311 | } |
| 1312 | |
| 1313 | if (options->oVariables->FP32RoundDivideSqrt && |
| 1314 | !(device().info().singleFPConfig_ & CL_FP_CORRECTLY_ROUNDED_DIVIDE_SQRT)) { |
| 1315 | buildStatus_ = CL_BUILD_ERROR; |
| 1316 | buildLog_ += |
| 1317 | "Error: -cl-fp32-correctly-rounded-divide-sqrt " |
| 1318 | "specified without device support"; |
| 1319 | } |
| 1320 | |
| 1321 | std::vector<const std::string*> headers; |
| 1322 | std::vector<const char*> headerIncludeNames; |
| 1323 | const std::vector<std::string>& tmpHeaderNames = owner()->headerNames(); |
| 1324 | const std::vector<std::string>& tmpHeaders = owner()->headers(); |
| 1325 | for (size_t i = 0; i < tmpHeaders.size(); ++i) { |
| 1326 | headers.push_back(&tmpHeaders[i]); |
| 1327 | headerIncludeNames.push_back(tmpHeaderNames[i].c_str()); |
| 1328 | } |
| 1329 | // Compile the source code if any |
| 1330 | bool compileStatus = true; |
| 1331 | if ((buildStatus_ == CL_BUILD_IN_PROGRESS) && !sourceCode.empty()) { |
| 1332 | if (!headerIncludeNames.empty()) { |
| 1333 | compileStatus = compileImpl(sourceCode, headers, &headerIncludeNames[0], options); |
| 1334 | } else { |
| 1335 | compileStatus = compileImpl(sourceCode, headers, nullptr, options); |
| 1336 | } |
| 1337 | } |
| 1338 | if (!compileStatus) { |
| 1339 | buildStatus_ = CL_BUILD_ERROR; |
| 1340 | if (buildLog_.empty()) { |
| 1341 | buildLog_ = "Internal error: Compilation failed."; |
| 1342 | } |
| 1343 | } |
| 1344 | if ((buildStatus_ == CL_BUILD_IN_PROGRESS) && !linkImpl(options)) { |