diff --git a/opencl/source/api/api.cpp b/opencl/source/api/api.cpp index 4c32c34dcf..cbadda4e2b 100644 --- a/opencl/source/api/api.cpp +++ b/opencl/source/api/api.cpp @@ -1437,10 +1437,6 @@ cl_program CL_API_CALL clCreateProgramWithBuiltInKernels(cl_context context, retVal = validateObjects(WithCastToInternal(context, &pContext), numDevices, deviceList, kernelNames, errcodeRet); - if (numDevices == 0) { - retVal = CL_INVALID_VALUE; - } - if (retVal == CL_SUCCESS) { ClDeviceVector deviceVector; for (auto i = 0u; i < numDevices; i++) { @@ -1542,8 +1538,34 @@ cl_int CL_API_CALL clCompileProgram(cl_program program, retVal = validateObjects(WithCastToInternal(program, &pProgram), Program::isValidCallback(funcNotify, userData)); + ClDeviceVector deviceVector; + const ClDeviceVector *deviceVectorPtr = &deviceVector; + if (CL_SUCCESS == retVal) { - retVal = pProgram->compile(numDevices, deviceList, options, + if (deviceList == nullptr) { + if (numDevices == 0) { + deviceVectorPtr = &pProgram->getDevices(); + } else { + retVal = CL_INVALID_VALUE; + } + + } else { + if (numDevices == 0) { + retVal = CL_INVALID_VALUE; + } else { + for (auto i = 0u; i < numDevices; i++) { + auto device = castToObject(deviceList[i]); + if (!device || !pProgram->isDeviceAssociated(*device)) { + retVal = CL_INVALID_DEVICE; + break; + } + deviceVector.push_back(device); + } + } + } + } + if (CL_SUCCESS == retVal) { + retVal = pProgram->compile(*deviceVectorPtr, options, numInputHeaders, inputHeaders, headerIncludeNames); pProgram->invokeCallback(funcNotify, userData); } @@ -1639,13 +1661,19 @@ cl_int CL_API_CALL clGetProgramBuildInfo(cl_program program, "paramName", NEO::FileLoggerInstance().infoPointerToString(paramValue, paramValueSize), "paramValueSize", paramValueSize, "paramValue", paramValue, "paramValueSizeRet", paramValueSizeRet); - retVal = validateObjects(program); + Program *pProgram = nullptr; + ClDevice *pClDevice = nullptr; + + retVal = validateObjects(WithCastToInternal(program, &pProgram), WithCastToInternal(device, &pClDevice)); if (CL_SUCCESS == retVal) { - Program *pProgram = (Program *)(program); - + if (!pProgram->isDeviceAssociated(*pClDevice)) { + retVal = CL_INVALID_DEVICE; + } + } + if (CL_SUCCESS == retVal) { retVal = pProgram->getBuildInfo( - device, + pClDevice, paramName, paramValueSize, paramValue, diff --git a/opencl/source/program/compile.cpp b/opencl/source/program/compile.cpp index 6604b62946..1584fbbea2 100644 --- a/opencl/source/program/compile.cpp +++ b/opencl/source/program/compile.cpp @@ -26,23 +26,18 @@ namespace NEO { cl_int Program::compile( - cl_uint numDevices, - const cl_device_id *deviceList, + const ClDeviceVector &deviceVector, const char *buildOptions, cl_uint numInputHeaders, const cl_program *inputHeaders, const char **headerIncludeNames) { cl_int retVal = CL_SUCCESS; - auto clDevice = this->pDevice->getSpecializedDevice(); - UNRECOVERABLE_IF(clDevice == nullptr); + auto defaultClDevice = deviceVector[0]; + UNRECOVERABLE_IF(defaultClDevice == nullptr); + auto &defaultDevice = defaultClDevice->getDevice(); + internalOptions.clear(); do { - if (((deviceList == nullptr) && (numDevices != 0)) || - ((deviceList != nullptr) && (numDevices == 0))) { - retVal = CL_INVALID_VALUE; - break; - } - if (numInputHeaders == 0) { if ((headerIncludeNames != nullptr) || (inputHeaders != nullptr)) { retVal = CL_INVALID_VALUE; @@ -55,14 +50,7 @@ cl_int Program::compile( } } - // if a device_list is specified, make sure it points to our device - // NOTE: a null device_list is ok - it means "all devices" - if ((deviceList != nullptr) && validateObject(*deviceList) != CL_SUCCESS) { - retVal = CL_INVALID_DEVICE; - break; - } - - if (buildStatuses[clDevice] == CL_BUILD_IN_PROGRESS) { + if (std::any_of(deviceVector.begin(), deviceVector.end(), [&](auto device) { return CL_BUILD_IN_PROGRESS == buildStatuses[device]; })) { retVal = CL_INVALID_OPERATION; break; } @@ -71,8 +59,9 @@ cl_int Program::compile( retVal = CL_SUCCESS; break; } - - buildStatuses[clDevice] = CL_BUILD_IN_PROGRESS; + for (const auto &device : deviceVector) { + buildStatuses[device] = CL_BUILD_IN_PROGRESS; + } options = (buildOptions != nullptr) ? buildOptions : ""; @@ -115,7 +104,7 @@ cl_int Program::compile( std::vector compileData = elfEncoder.encode(); - CompilerInterface *pCompilerInterface = pDevice->getCompilerInterface(); + CompilerInterface *pCompilerInterface = defaultDevice.getCompilerInterface(); if (!pCompilerInterface) { retVal = CL_OUT_OF_HOST_MEMORY; break; @@ -124,14 +113,11 @@ cl_int Program::compile( TranslationInput inputArgs = {IGC::CodeType::elf, IGC::CodeType::undefined}; // set parameters for compilation - auto clDevice = this->pDevice->getSpecializedDevice(); - UNRECOVERABLE_IF(clDevice == nullptr); - if (requiresOpenClCFeatures(options)) { - CompilerOptions::concatenateAppend(internalOptions, clDevice->peekCompilerExtensionsWithFeatures()); - CompilerOptions::concatenateAppend(internalOptions, clDevice->peekCompilerFeatures()); + CompilerOptions::concatenateAppend(internalOptions, defaultClDevice->peekCompilerExtensionsWithFeatures()); + CompilerOptions::concatenateAppend(internalOptions, defaultClDevice->peekCompilerFeatures()); } else { - CompilerOptions::concatenateAppend(internalOptions, clDevice->peekCompilerExtensions()); + CompilerOptions::concatenateAppend(internalOptions, defaultClDevice->peekCompilerExtensions()); } if (isKernelDebugEnabled()) { @@ -148,9 +134,11 @@ cl_int Program::compile( inputArgs.internalOptions = ArrayRef(internalOptions.c_str(), internalOptions.length()); TranslationOutput compilerOuput; - auto compilerErr = pCompilerInterface->compile(*this->pDevice, inputArgs, compilerOuput); - this->updateBuildLog(this->pDevice->getRootDeviceIndex(), compilerOuput.frontendCompilerLog.c_str(), compilerOuput.frontendCompilerLog.size()); - this->updateBuildLog(this->pDevice->getRootDeviceIndex(), compilerOuput.backendCompilerLog.c_str(), compilerOuput.backendCompilerLog.size()); + auto compilerErr = pCompilerInterface->compile(defaultDevice, inputArgs, compilerOuput); + for (const auto &device : deviceVector) { + this->updateBuildLog(device->getRootDeviceIndex(), compilerOuput.frontendCompilerLog.c_str(), compilerOuput.frontendCompilerLog.size()); + this->updateBuildLog(device->getRootDeviceIndex(), compilerOuput.backendCompilerLog.c_str(), compilerOuput.backendCompilerLog.size()); + } retVal = asClError(compilerErr); if (retVal != CL_SUCCESS) { break; @@ -166,15 +154,18 @@ cl_int Program::compile( } while (false); if (retVal != CL_SUCCESS) { - buildStatuses[clDevice] = CL_BUILD_ERROR; + for (const auto &device : deviceVector) { + buildStatuses[device] = CL_BUILD_ERROR; + } programBinaryType = CL_PROGRAM_BINARY_TYPE_NONE; } else { - buildStatuses[clDevice] = CL_BUILD_SUCCESS; + for (const auto &device : deviceVector) { + buildStatuses[device] = CL_BUILD_SUCCESS; + } programBinaryType = CL_PROGRAM_BINARY_TYPE_COMPILED_OBJECT; } internalOptions.clear(); - return retVal; } } // namespace NEO diff --git a/opencl/source/program/get_info.cpp b/opencl/source/program/get_info.cpp index b155738307..d4ceac937a 100644 --- a/opencl/source/program/get_info.cpp +++ b/opencl/source/program/get_info.cpp @@ -180,11 +180,6 @@ cl_int Program::getBuildInfo(cl_device_id device, cl_program_build_info paramNam const void *pSrc = nullptr; size_t srcSize = GetInfo::invalidSourceSize; size_t retSize = 0; - cl_device_id device_id = pDevice->getSpecializedDevice(); - - if (device != device_id) { - return CL_INVALID_DEVICE; - } auto pClDev = castToObject(device); auto rootDeviceIndex = pClDev->getRootDeviceIndex(); diff --git a/opencl/source/program/program.cpp b/opencl/source/program/program.cpp index dc27b1be23..0096e85f46 100644 --- a/opencl/source/program/program.cpp +++ b/opencl/source/program/program.cpp @@ -499,4 +499,7 @@ void Program::invokeCallback(void(CL_CALLBACK *funcNotify)(cl_program program, v } } +bool Program::isDeviceAssociated(const ClDevice &clDevice) const { + return std::any_of(clDevices.begin(), clDevices.end(), [&](auto programDevice) { return programDevice == &clDevice; }); +} } // namespace NEO diff --git a/opencl/source/program/program.h b/opencl/source/program/program.h index 8b9901a2f0..fe9c0f1b3f 100644 --- a/opencl/source/program/program.h +++ b/opencl/source/program/program.h @@ -135,7 +135,7 @@ class Program : public BaseObject<_cl_program> { MOCKABLE_VIRTUAL cl_int processGenBinary(uint32_t rootDeviceIndex); MOCKABLE_VIRTUAL cl_int processProgramInfo(ProgramInfo &dst); - cl_int compile(cl_uint numDevices, const cl_device_id *deviceList, const char *buildOptions, + cl_int compile(const ClDeviceVector &deviceVector, const char *buildOptions, cl_uint numInputHeaders, const cl_program *inputHeaders, const char **headerIncludeNames); cl_int link(cl_uint numDevices, const cl_device_id *deviceList, const char *buildOptions, @@ -263,6 +263,9 @@ class Program : public BaseObject<_cl_program> { static bool isValidCallback(void(CL_CALLBACK *funcNotify)(cl_program program, void *userData), void *userData); void invokeCallback(void(CL_CALLBACK *funcNotify)(cl_program program, void *userData), void *userData); + const ClDeviceVector &getDevices() const { return clDevices; } + bool isDeviceAssociated(const ClDevice &clDevice) const; + protected: MOCKABLE_VIRTUAL cl_int createProgramFromBinary(const void *pBinary, size_t binarySize, uint32_t rootDeviceIndex); diff --git a/opencl/test/unit_test/api/cl_compile_program_tests.inl b/opencl/test/unit_test/api/cl_compile_program_tests.inl index e04e6c8f6a..eb74225449 100644 --- a/opencl/test/unit_test/api/cl_compile_program_tests.inl +++ b/opencl/test/unit_test/api/cl_compile_program_tests.inl @@ -235,4 +235,97 @@ TEST_F(clCompileProgramTests, GivenValidCallbackInputWhenLinkProgramThenCallback EXPECT_EQ(CL_SUCCESS, retVal); } +TEST(clCompileProgramTest, givenMultiDeviceProgramWhenCompilingForInvalidDevicesInputThenInvalidDeviceErrorIsReturned) { + cl_program pProgram = nullptr; + std::unique_ptr pSource = nullptr; + size_t sourceSize = 0; + std::string testFile; + + KernelBinaryHelper kbHelper("CopyBuffer_simd16"); + + testFile.append(clFiles); + testFile.append("CopyBuffer_simd16.cl"); + + pSource = loadDataFromFile( + testFile.c_str(), + sourceSize); + + ASSERT_NE(0u, sourceSize); + ASSERT_NE(nullptr, pSource); + + const char *sources[1] = {pSource.get()}; + + MockUnrestrictiveContextMultiGPU context; + cl_int retVal = CL_INVALID_PROGRAM; + + pProgram = clCreateProgramWithSource( + &context, + 1, + sources, + &sourceSize, + &retVal); + + EXPECT_NE(nullptr, pProgram); + ASSERT_EQ(CL_SUCCESS, retVal); + + MockContext mockContext; + cl_device_id nullDeviceInput[] = {context.getDevice(0), nullptr}; + cl_device_id notAssociatedDeviceInput[] = {mockContext.getDevice(0)}; + cl_device_id validDeviceInput[] = {context.getDevice(0)}; + + retVal = clCompileProgram( + pProgram, + 0, + validDeviceInput, + nullptr, + 0, + nullptr, + nullptr, + nullptr, + nullptr); + + EXPECT_EQ(CL_INVALID_VALUE, retVal); + + retVal = clCompileProgram( + pProgram, + 1, + nullptr, + nullptr, + 0, + nullptr, + nullptr, + nullptr, + nullptr); + + EXPECT_EQ(CL_INVALID_VALUE, retVal); + + retVal = clCompileProgram( + pProgram, + 2, + nullDeviceInput, + nullptr, + 0, + nullptr, + nullptr, + nullptr, + nullptr); + + EXPECT_EQ(CL_INVALID_DEVICE, retVal); + + retVal = clCompileProgram( + pProgram, + 1, + notAssociatedDeviceInput, + nullptr, + 0, + nullptr, + nullptr, + nullptr, + nullptr); + + EXPECT_EQ(CL_INVALID_DEVICE, retVal); + + retVal = clReleaseProgram(pProgram); + EXPECT_EQ(CL_SUCCESS, retVal); +} } // namespace ULT diff --git a/opencl/test/unit_test/api/cl_get_program_build_info_tests.inl b/opencl/test/unit_test/api/cl_get_program_build_info_tests.inl index ca5b0ce787..9885c9ff5a 100644 --- a/opencl/test/unit_test/api/cl_get_program_build_info_tests.inl +++ b/opencl/test/unit_test/api/cl_get_program_build_info_tests.inl @@ -98,6 +98,140 @@ TEST_F(clGetProgramBuildInfoTests, givenSourceWhenclGetProgramBuildInfoIsCalledT EXPECT_EQ(CL_SUCCESS, retVal); } +TEST(clGetProgramBuildInfoTest, givenMultiDeviceProgramWhenCompilingForSpecificDevicesThenOnlySpecificDevicesReportBuildStatus) { + cl_program pProgram = nullptr; + std::unique_ptr pSource = nullptr; + size_t sourceSize = 0; + std::string testFile; + + KernelBinaryHelper kbHelper("CopyBuffer_simd16"); + + testFile.append(clFiles); + testFile.append("CopyBuffer_simd16.cl"); + + pSource = loadDataFromFile( + testFile.c_str(), + sourceSize); + + ASSERT_NE(0u, sourceSize); + ASSERT_NE(nullptr, pSource); + + const char *sources[1] = {pSource.get()}; + + MockUnrestrictiveContextMultiGPU context; + cl_int retVal = CL_INVALID_PROGRAM; + + pProgram = clCreateProgramWithSource( + &context, + 1, + sources, + &sourceSize, + &retVal); + + EXPECT_NE(nullptr, pProgram); + ASSERT_EQ(CL_SUCCESS, retVal); + + cl_build_status buildStatus; + for (const auto &device : context.getDevices()) { + retVal = clGetProgramBuildInfo(pProgram, device, CL_PROGRAM_BUILD_STATUS, sizeof(buildStatus), &buildStatus, NULL); + EXPECT_EQ(CL_SUCCESS, retVal); + EXPECT_EQ(CL_BUILD_NONE, buildStatus); + } + + cl_device_id devicesForCompilation[] = {context.getDevice(1), context.getDevice(3)}; + cl_device_id devicesNotForCompilation[] = {context.getDevice(0), context.getDevice(2), context.getDevice(4), context.getDevice(5)}; + + retVal = clCompileProgram( + pProgram, + 2, + devicesForCompilation, + nullptr, + 0, + nullptr, + nullptr, + nullptr, + nullptr); + + ASSERT_EQ(CL_SUCCESS, retVal); + + for (const auto &device : devicesNotForCompilation) { + retVal = clGetProgramBuildInfo(pProgram, device, CL_PROGRAM_BUILD_STATUS, sizeof(buildStatus), &buildStatus, NULL); + EXPECT_EQ(CL_SUCCESS, retVal); + EXPECT_EQ(CL_BUILD_NONE, buildStatus); + } + for (const auto &device : devicesForCompilation) { + retVal = clGetProgramBuildInfo(pProgram, device, CL_PROGRAM_BUILD_STATUS, sizeof(buildStatus), &buildStatus, NULL); + EXPECT_EQ(CL_SUCCESS, retVal); + EXPECT_EQ(CL_BUILD_SUCCESS, buildStatus); + } + + retVal = clReleaseProgram(pProgram); + EXPECT_EQ(CL_SUCCESS, retVal); +} + +TEST(clGetProgramBuildInfoTest, givenMultiDeviceProgramWhenCompilingWithoutInputDevicesThenAllDevicesReportBuildStatus) { + cl_program pProgram = nullptr; + std::unique_ptr pSource = nullptr; + size_t sourceSize = 0; + std::string testFile; + + KernelBinaryHelper kbHelper("CopyBuffer_simd16"); + + testFile.append(clFiles); + testFile.append("CopyBuffer_simd16.cl"); + + pSource = loadDataFromFile( + testFile.c_str(), + sourceSize); + + ASSERT_NE(0u, sourceSize); + ASSERT_NE(nullptr, pSource); + + const char *sources[1] = {pSource.get()}; + + MockUnrestrictiveContextMultiGPU context; + cl_int retVal = CL_INVALID_PROGRAM; + + pProgram = clCreateProgramWithSource( + &context, + 1, + sources, + &sourceSize, + &retVal); + + EXPECT_NE(nullptr, pProgram); + ASSERT_EQ(CL_SUCCESS, retVal); + + cl_build_status buildStatus; + for (const auto &device : context.getDevices()) { + retVal = clGetProgramBuildInfo(pProgram, device, CL_PROGRAM_BUILD_STATUS, sizeof(buildStatus), &buildStatus, NULL); + EXPECT_EQ(CL_SUCCESS, retVal); + EXPECT_EQ(CL_BUILD_NONE, buildStatus); + } + + retVal = clCompileProgram( + pProgram, + 0, + nullptr, + nullptr, + 0, + nullptr, + nullptr, + nullptr, + nullptr); + + ASSERT_EQ(CL_SUCCESS, retVal); + + for (const auto &device : context.getDevices()) { + retVal = clGetProgramBuildInfo(pProgram, device, CL_PROGRAM_BUILD_STATUS, sizeof(buildStatus), &buildStatus, NULL); + EXPECT_EQ(CL_SUCCESS, retVal); + EXPECT_EQ(CL_BUILD_SUCCESS, buildStatus); + } + + retVal = clReleaseProgram(pProgram); + EXPECT_EQ(CL_SUCCESS, retVal); +} + TEST_F(clGetProgramBuildInfoTests, givenElfBinaryWhenclGetProgramBuildInfoIsCalledThenReturnClBuildNone) { cl_program pProgram = nullptr; cl_int binaryStatus = CL_INVALID_VALUE; @@ -132,4 +266,16 @@ TEST_F(clGetProgramBuildInfoTests, givenElfBinaryWhenclGetProgramBuildInfoIsCall retVal = clReleaseProgram(pProgram); EXPECT_EQ(CL_SUCCESS, retVal); } + +TEST_F(clGetProgramBuildInfoTests, givenInvalidDeviceInputWhenGetProgramBuildInfoIsCalledThenInvalidDeviceErrorIsReturned) { + cl_build_status buildStatus; + retVal = clGetProgramBuildInfo(pProgram, nullptr, CL_PROGRAM_BUILD_STATUS, sizeof(buildStatus), &buildStatus, nullptr); + EXPECT_EQ(CL_INVALID_DEVICE, retVal); + retVal = clGetProgramBuildInfo(pProgram, reinterpret_cast(pProgram), CL_PROGRAM_BUILD_STATUS, sizeof(buildStatus), &buildStatus, nullptr); + EXPECT_EQ(CL_INVALID_DEVICE, retVal); + + MockContext context; + retVal = clGetProgramBuildInfo(pProgram, context.getDevice(0), CL_PROGRAM_BUILD_STATUS, sizeof(buildStatus), &buildStatus, nullptr); + EXPECT_EQ(CL_INVALID_DEVICE, retVal); +} } // namespace ULT diff --git a/opencl/test/unit_test/program/program_tests.cpp b/opencl/test/unit_test/program/program_tests.cpp index 82ca5c7498..639a86f678 100644 --- a/opencl/test/unit_test/program/program_tests.cpp +++ b/opencl/test/unit_test/program/program_tests.cpp @@ -337,37 +337,6 @@ TEST_P(ProgramFromBinaryTest, WhenGettingProgramScopeGlobalCtorsAndDtorsPresentI EXPECT_EQ(expectedParam, paramRet); } -TEST_P(ProgramFromBinaryTest, GivenInvalidDeviceWhenGettingBuildStatusThenInvalidDeviceErrorIsReturned) { - cl_build_status buildStatus = 0; - size_t paramValueSize = sizeof(buildStatus); - size_t paramValueSizeRet = 0; - - size_t invalidDevice = 0xdeadbee0; - retVal = pProgram->getBuildInfo( - reinterpret_cast(invalidDevice), - CL_PROGRAM_BUILD_STATUS, - paramValueSize, - &buildStatus, - ¶mValueSizeRet); - EXPECT_EQ(CL_INVALID_DEVICE, retVal); -} - -TEST_P(ProgramFromBinaryTest, GivenCorruptedDeviceWhenGettingBuildStatusThenInvalidDiveErrorIsReturned) { - cl_build_status buildStatus = 0; - size_t paramValueSize = sizeof(buildStatus); - size_t paramValueSizeRet = 0; - - CreateProgramFromBinary(pContext, pContext->getDevices(), BinaryFileName); - - retVal = pProgram->getBuildInfo( - reinterpret_cast(pContext), - CL_PROGRAM_BUILD_STATUS, - paramValueSize, - &buildStatus, - ¶mValueSizeRet); - EXPECT_EQ(CL_INVALID_DEVICE, retVal); -} - TEST_P(ProgramFromBinaryTest, GivenNullDeviceWhenGettingBuildStatusThenBuildNoneIsReturned) { cl_device_id device = pClDevice; cl_build_status buildStatus = 0; @@ -890,7 +859,7 @@ TEST_P(ProgramFromSourceTest, WhenCompilingProgramThenFeaturesOptionIsNotAdded) auto featuresOption = pClDevice->peekCompilerFeatures(); EXPECT_THAT(pCompilerInterface->buildInternalOptions, testing::Not(testing::HasSubstr(featuresOption))); - retVal = pProgram->compile(1, devices, nullptr, 0, nullptr, nullptr); + retVal = pProgram->compile(pProgram->getDevices(), nullptr, 0, nullptr, nullptr); EXPECT_EQ(CL_SUCCESS, retVal); EXPECT_THAT(pCompilerInterface->buildInternalOptions, testing::Not(testing::HasSubstr(featuresOption))); } @@ -906,7 +875,7 @@ TEST_P(ProgramFromSourceTest, WhenCompilingProgramWithOpenClC30ThenFeaturesOptio auto featuresOption = pClDevice->peekCompilerFeatures(); EXPECT_THAT(pCompilerInterface->buildInternalOptions, testing::Not(testing::HasSubstr(featuresOption))); - retVal = pProgram->compile(1, devices, "-cl-std=CL3.0", 0, nullptr, nullptr); + retVal = pProgram->compile(pProgram->getDevices(), "-cl-std=CL3.0", 0, nullptr, nullptr); EXPECT_EQ(CL_SUCCESS, retVal); EXPECT_THAT(pCompilerInterface->buildInternalOptions, testing::HasSubstr(featuresOption)); } @@ -1013,9 +982,6 @@ TEST_P(ProgramFromSourceTest, GivenSpecificParamatersWhenCompilingProgramThenSuc &usedDevice, SourceFileName); - auto *p = (MockProgram *)pProgram; - - cl_device_id deviceList = {0}; cl_program inputHeaders; const char *headerIncludeNames = ""; cl_program nullprogram = nullptr; @@ -1024,49 +990,38 @@ TEST_P(ProgramFromSourceTest, GivenSpecificParamatersWhenCompilingProgramThenSuc // Order of following microtests is important - do not change. // Add new microtests at end. - // invalid compile parameters: combinations of numDevices & deviceList - retVal = pProgram->compile(1, nullptr, nullptr, 0, nullptr, nullptr); - EXPECT_EQ(CL_INVALID_VALUE, retVal); - - retVal = pProgram->compile(0, &deviceList, nullptr, 0, nullptr, nullptr); - EXPECT_EQ(CL_INVALID_VALUE, retVal); - // invalid compile parameters: combinations of numInputHeaders==0 & inputHeaders & headerIncludeNames - retVal = pProgram->compile(0, nullptr, nullptr, 0, &inputHeaders, nullptr); + retVal = pProgram->compile(pProgram->getDevices(), nullptr, 0, &inputHeaders, nullptr); EXPECT_EQ(CL_INVALID_VALUE, retVal); - retVal = pProgram->compile(0, nullptr, nullptr, 0, nullptr, &headerIncludeNames); + retVal = pProgram->compile(pProgram->getDevices(), nullptr, 0, nullptr, &headerIncludeNames); EXPECT_EQ(CL_INVALID_VALUE, retVal); // invalid compile parameters: combinations of numInputHeaders!=0 & inputHeaders & headerIncludeNames - retVal = pProgram->compile(0, nullptr, nullptr, 1, &inputHeaders, nullptr); + retVal = pProgram->compile(pProgram->getDevices(), nullptr, 1, &inputHeaders, nullptr); EXPECT_EQ(CL_INVALID_VALUE, retVal); - retVal = pProgram->compile(0, nullptr, nullptr, 1, nullptr, &headerIncludeNames); + retVal = pProgram->compile(pProgram->getDevices(), nullptr, 1, nullptr, &headerIncludeNames); EXPECT_EQ(CL_INVALID_VALUE, retVal); - // invalid compile parameters: invalid content of deviceList - retVal = pProgram->compile(1, &deviceList, nullptr, 0, nullptr, nullptr); - EXPECT_EQ(CL_INVALID_DEVICE, retVal); - // fail compilation - another compilation is already in progress - p->setBuildStatus(CL_BUILD_IN_PROGRESS); - retVal = pProgram->compile(0, nullptr, nullptr, 0, nullptr, nullptr); + pProgram->setBuildStatus(CL_BUILD_IN_PROGRESS); + retVal = pProgram->compile(pProgram->getDevices(), nullptr, 0, nullptr, nullptr); EXPECT_EQ(CL_INVALID_OPERATION, retVal); - p->setBuildStatus(CL_BUILD_NONE); + pProgram->setBuildStatus(CL_BUILD_NONE); // invalid compile parameters: invalid header Program object==nullptr - retVal = pProgram->compile(0, nullptr, nullptr, 1, &nullprogram, &headerIncludeNames); + retVal = pProgram->compile(pProgram->getDevices(), nullptr, 1, &nullprogram, &headerIncludeNames); EXPECT_EQ(CL_INVALID_PROGRAM, retVal); // invalid compile parameters: invalid header Program object==non Program object - retVal = pProgram->compile(0, nullptr, nullptr, 1, &invprogram, &headerIncludeNames); + retVal = pProgram->compile(pProgram->getDevices(), nullptr, 1, &invprogram, &headerIncludeNames); EXPECT_EQ(CL_INVALID_PROGRAM, retVal); // compile successfully kernel with header std::string testFile; size_t sourceSize; - Program *p3; // header Program object + MockProgram *p3; // header Program object testFile.append(clFiles); testFile.append("CopyBuffer_simd16.cl"); // header source file auto pSourceBuffer = loadDataFromFile(testFile.c_str(), sourceSize); @@ -1077,13 +1032,12 @@ TEST_P(ProgramFromSourceTest, GivenSpecificParamatersWhenCompilingProgramThenSuc EXPECT_EQ(CL_SUCCESS, retVal); EXPECT_NE(nullptr, p3); inputHeaders = p3; - retVal = pProgram->compile(0, nullptr, nullptr, 1, &inputHeaders, &headerIncludeNames); + retVal = pProgram->compile(pProgram->getDevices(), nullptr, 1, &inputHeaders, &headerIncludeNames); EXPECT_EQ(CL_SUCCESS, retVal); // fail compilation of kernel with header - header is invalid - p = (MockProgram *)p3; - p->sourceCode = ""; // set header source code as non-existent (invalid) - retVal = pProgram->compile(0, nullptr, nullptr, 1, &inputHeaders, &headerIncludeNames); + p3->sourceCode = ""; // set header source code as non-existent (invalid) + retVal = p3->compile(p3->getDevices(), nullptr, 1, &inputHeaders, &headerIncludeNames); EXPECT_EQ(CL_INVALID_PROGRAM, retVal); delete p3; @@ -1093,17 +1047,17 @@ TEST_P(ProgramFromSourceTest, GivenSpecificParamatersWhenCompilingProgramThenSuc std::unique_ptr rootDeviceEnvironment = std::make_unique(*executionEnvironment); std::swap(rootDeviceEnvironment, executionEnvironment->rootDeviceEnvironments[device->getRootDeviceIndex()]); auto p2 = std::make_unique(toClDeviceVector(*device)); - retVal = p2->compile(0, nullptr, nullptr, 0, nullptr, nullptr); + retVal = p2->compile(p2->getDevices(), nullptr, 0, nullptr, nullptr); EXPECT_EQ(CL_OUT_OF_HOST_MEMORY, retVal); p2.reset(nullptr); std::swap(rootDeviceEnvironment, executionEnvironment->rootDeviceEnvironments[device->getRootDeviceIndex()]); // fail compilation - any compilation error (here caused by specifying unrecognized option) - retVal = pProgram->compile(0, nullptr, "-invalid-option", 0, nullptr, nullptr); + retVal = pProgram->compile(pProgram->getDevices(), "-invalid-option", 0, nullptr, nullptr); EXPECT_EQ(CL_COMPILE_PROGRAM_FAILURE, retVal); // compile successfully - retVal = pProgram->compile(0, nullptr, nullptr, 0, nullptr, nullptr); + retVal = pProgram->compile(pProgram->getDevices(), nullptr, 0, nullptr, nullptr); EXPECT_EQ(CL_SUCCESS, retVal); } @@ -1115,7 +1069,7 @@ TEST_P(ProgramFromSourceTest, GivenFlagsWhenCompilingProgramThenBuildOptionsHave program->sourceCode = "__kernel mock() {}"; // Ask to build created program without NEO::CompilerOptions::gtpinRera and NEO::CompilerOptions::greaterThan4gbBuffersRequired flags. - cl_int retVal = program->compile(0, nullptr, CompilerOptions::fastRelaxedMath.data(), 0, nullptr, nullptr); + cl_int retVal = program->compile(pProgram->getDevices(), CompilerOptions::fastRelaxedMath.data(), 0, nullptr, nullptr); EXPECT_EQ(CL_SUCCESS, retVal); // Check build options that were applied @@ -1130,7 +1084,7 @@ TEST_P(ProgramFromSourceTest, GivenFlagsWhenCompilingProgramThenBuildOptionsHave cip->buildOptions.clear(); cip->buildInternalOptions.clear(); auto options = CompilerOptions::concatenate(CompilerOptions::greaterThan4gbBuffersRequired, CompilerOptions::gtpinRera, CompilerOptions::finiteMathOnly); - retVal = program->compile(0, nullptr, options.c_str(), + retVal = program->compile(pProgram->getDevices(), options.c_str(), 0, nullptr, nullptr); EXPECT_EQ(CL_SUCCESS, retVal); @@ -1151,7 +1105,7 @@ TEST_F(ProgramTests, GivenFlagsWhenLinkingProgramThenBuildOptionsHaveBeenApplied cl_program program = pProgram.get(); // compile successfully a kernel to be linked later - cl_int retVal = pProgram->compile(0, nullptr, nullptr, 0, nullptr, nullptr); + cl_int retVal = pProgram->compile(pProgram->getDevices(), nullptr, 0, nullptr, nullptr); EXPECT_EQ(CL_SUCCESS, retVal); // Ask to link created program with NEO::CompilerOptions::gtpinRera and NEO::CompilerOptions::greaterThan4gbBuffersRequired flags. @@ -1269,7 +1223,7 @@ TEST_P(ProgramFromSourceTest, GivenSpecificParamatersWhenLinkingProgramThenSucce EXPECT_EQ(CL_INVALID_PROGRAM, retVal); // compile successfully a kernel to be linked later - retVal = pProgram->compile(0, nullptr, nullptr, 0, nullptr, nullptr); + retVal = pProgram->compile(pProgram->getDevices(), nullptr, 0, nullptr, nullptr); EXPECT_EQ(CL_SUCCESS, retVal); // fail linking - code to be linked does not exist @@ -1311,7 +1265,7 @@ TEST_P(ProgramFromSourceTest, GivenInvalidOptionsWhenCreatingLibraryThenCorrectE // Add new microtests at end. // compile successfully a kernel to be later used to create library - retVal = pProgram->compile(0, nullptr, nullptr, 0, nullptr, nullptr); + retVal = pProgram->compile(pProgram->getDevices(), nullptr, 0, nullptr, nullptr); EXPECT_EQ(CL_SUCCESS, retVal); // create library successfully @@ -1969,9 +1923,8 @@ TEST_F(ProgramTests, GivenNullContextWhenCreatingProgramFromGenBinaryThenSuccess EXPECT_EQ(CL_SUCCESS, retVal); EXPECT_EQ((uint32_t)CL_PROGRAM_BINARY_TYPE_EXECUTABLE, (uint32_t)pProgram->getProgramBinaryType()); - cl_device_id deviceId = nullptr; cl_build_status status = 0; - pProgram->getBuildInfo(deviceId, CL_PROGRAM_BUILD_STATUS, + pProgram->getBuildInfo(pClDevice, CL_PROGRAM_BUILD_STATUS, sizeof(cl_build_status), &status, nullptr); EXPECT_EQ(CL_BUILD_SUCCESS, status); @@ -2262,33 +2215,31 @@ TEST_F(ProgramTests, givenProgramCreatedFromILWhenCompileIsCalledThenReuseTheILI REQUIRE_OCL_21_OR_SKIP(pContext); const uint32_t spirv[16] = {0x03022307}; cl_int errCode = 0; - auto prog = Program::createFromIL(pContext, reinterpret_cast(spirv), sizeof(spirv), errCode); - ASSERT_NE(nullptr, prog); - cl_device_id deviceId = pClDevice; + auto pProgram = Program::createFromIL(pContext, reinterpret_cast(spirv), sizeof(spirv), errCode); + ASSERT_NE(nullptr, pProgram); auto debugVars = NEO::getIgcDebugVars(); debugVars.forceBuildFailure = true; gEnvironment->fclPushDebugVars(debugVars); - auto compilerErr = prog->compile(1, &deviceId, nullptr, 0, nullptr, nullptr); + auto compilerErr = pProgram->compile(pProgram->getDevices(), nullptr, 0, nullptr, nullptr); EXPECT_EQ(CL_SUCCESS, compilerErr); gEnvironment->fclPopDebugVars(); - prog->release(); + pProgram->release(); } TEST_F(ProgramTests, givenProgramCreatedFromIntermediateBinaryRepresentationWhenCompileIsCalledThenReuseTheILInsteadOfCallingCompilerInterface) { const uint32_t spirv[16] = {0x03022307}; cl_int errCode = 0; - cl_device_id deviceId = pClDevice; size_t lengths = sizeof(spirv); const unsigned char *binaries[1] = {reinterpret_cast(spirv)}; - auto prog = Program::create(pContext, pContext->getDevices(), &lengths, binaries, nullptr, errCode); - ASSERT_NE(nullptr, prog); + auto pProgram = Program::create(pContext, pContext->getDevices(), &lengths, binaries, nullptr, errCode); + ASSERT_NE(nullptr, pProgram); auto debugVars = NEO::getIgcDebugVars(); debugVars.forceBuildFailure = true; gEnvironment->fclPushDebugVars(debugVars); - auto compilerErr = prog->compile(1, &deviceId, nullptr, 0, nullptr, nullptr); + auto compilerErr = pProgram->compile(pProgram->getDevices(), nullptr, 0, nullptr, nullptr); EXPECT_EQ(CL_SUCCESS, compilerErr); gEnvironment->fclPopDebugVars(); - prog->release(); + pProgram->release(); } TEST_F(ProgramTests, GivenIlIsNullptrWhenCreatingFromIlThenInvalidBinaryErrorIsReturned) { @@ -2944,7 +2895,7 @@ TEST_F(ProgramBinTest, GivenDebugDataAvailableWhenLinkingProgramThenDebugDataIsS &knownSourceSize, retVal); - retVal = pProgram->compile(1, &device, nullptr, 0, nullptr, nullptr); + retVal = pProgram->compile(pProgram->getDevices(), nullptr, 0, nullptr, nullptr); EXPECT_EQ(CL_SUCCESS, retVal); cl_program programToLink = pProgram; @@ -3026,7 +2977,7 @@ TEST_F(ProgramBinTest, GivenSourceKernelWhenLinkingProgramThenGtpinInitInfoIsPas retVal); std::unique_ptr mockCompilerInterface(new MockCompilerInterfaceWithGtpinParam); - retVal = pProgram->compile(1, &device, nullptr, 0, nullptr, nullptr); + retVal = pProgram->compile(pProgram->getDevices(), nullptr, 0, nullptr, nullptr); EXPECT_EQ(CL_SUCCESS, retVal); pDevice->getExecutionEnvironment()->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]->compilerInterface.reset(mockCompilerInterface.get()); diff --git a/opencl/test/unit_test/program/program_with_block_kernels_tests.cpp b/opencl/test/unit_test/program/program_with_block_kernels_tests.cpp index 81032ffd78..bac4e7ea18 100644 --- a/opencl/test/unit_test/program/program_with_block_kernels_tests.cpp +++ b/opencl/test/unit_test/program/program_with_block_kernels_tests.cpp @@ -100,7 +100,7 @@ TEST_F(ProgramWithBlockKernelsTest, GivenKernelWithBlockKernelsWhenProgramIsLink Program *programLinked = new Program(pContext, false, pContext->getDevices()); cl_program program = pProgram; - retVal = pProgram->compile(1, &device, buildOptions, 0, nullptr, nullptr); + retVal = pProgram->compile(pProgram->getDevices(), buildOptions, 0, nullptr, nullptr); EXPECT_EQ(CL_SUCCESS, retVal); diff --git a/opencl/test/unit_test/program/program_with_kernel_debug_tests.cpp b/opencl/test/unit_test/program/program_with_kernel_debug_tests.cpp index cc588c29b9..7205243c87 100644 --- a/opencl/test/unit_test/program/program_with_kernel_debug_tests.cpp +++ b/opencl/test/unit_test/program/program_with_kernel_debug_tests.cpp @@ -94,7 +94,7 @@ TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugWhenProgramIsCompi debugVars.receivedInternalOptionsOutput = &receivedInternalOptions; gEnvironment->fclPushDebugVars(debugVars); - cl_int retVal = pProgram->compile(1, &device, nullptr, + cl_int retVal = pProgram->compile(pProgram->getDevices(), nullptr, 0, nullptr, nullptr); EXPECT_EQ(CL_SUCCESS, retVal); @@ -103,7 +103,7 @@ TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugWhenProgramIsCompi } TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugWhenProgramIsCompiledThenInternalOptionsIncludeDashGFlag) { - cl_int retVal = pProgram->compile(1, &device, nullptr, + cl_int retVal = pProgram->compile(pProgram->getDevices(), nullptr, 0, nullptr, nullptr); EXPECT_EQ(CL_SUCCESS, retVal); @@ -115,7 +115,7 @@ TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugAndOptDisabledWhen sourceLevelDebugger->isOptDisabled = true; pDevice->executionEnvironment->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]->debugger.reset(sourceLevelDebugger); - cl_int retVal = pProgram->compile(1, &device, nullptr, + cl_int retVal = pProgram->compile(pProgram->getDevices(), nullptr, 0, nullptr, nullptr); EXPECT_EQ(CL_SUCCESS, retVal); EXPECT_THAT(pProgram->getOptions(), ::testing::HasSubstr(CompilerOptions::optDisable.data())); @@ -126,7 +126,7 @@ TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugWhenProgramIsCompi sourceLevelDebugger->sourceCodeFilename = "debugFileName"; pDevice->executionEnvironment->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]->debugger.reset(sourceLevelDebugger); - cl_int retVal = pProgram->compile(1, &device, nullptr, + cl_int retVal = pProgram->compile(pProgram->getDevices(), nullptr, 0, nullptr, nullptr); EXPECT_EQ(CL_SUCCESS, retVal); EXPECT_THAT(pProgram->getOptions(), ::testing::StartsWith("-s debugFileName")); @@ -176,7 +176,7 @@ TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugWhenProgramIsLinke MockActiveSourceLevelDebugger *sourceLevelDebugger = new MockActiveSourceLevelDebugger; pDevice->executionEnvironment->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]->debugger.reset(sourceLevelDebugger); - cl_int retVal = pProgram->compile(1, &device, nullptr, 0, nullptr, nullptr); + cl_int retVal = pProgram->compile(pProgram->getDevices(), nullptr, 0, nullptr, nullptr); EXPECT_EQ(CL_SUCCESS, retVal); auto program = std::unique_ptr(new GMockProgram(pContext, false, toClDeviceVector(*pClDevice))); @@ -217,7 +217,7 @@ TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugWhenProgramIsLinke sourceLevelDebugger->setActive(true); pDevice->executionEnvironment->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]->debugger.reset(sourceLevelDebugger); - cl_int retVal = pProgram->compile(1, &device, nullptr, + cl_int retVal = pProgram->compile(pProgram->getDevices(), nullptr, 0, nullptr, nullptr); EXPECT_EQ(CL_SUCCESS, retVal);