Use all passed devices when compiling program

Related-To: NEO-5001
Change-Id: I852c6e57fb7c450ee4dae2d5ff59a206397b2390
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski 2020-10-28 10:27:14 +01:00 committed by sys_ocldev
parent d539a7f8e4
commit 20f4786423
10 changed files with 348 additions and 138 deletions

View File

@ -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<ClDevice>(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,

View File

@ -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<ClDevice>();
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<uint8_t> 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<ClDevice>();
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<const char>(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

View File

@ -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<ClDevice>();
if (device != device_id) {
return CL_INVALID_DEVICE;
}
auto pClDev = castToObject<ClDevice>(device);
auto rootDeviceIndex = pClDev->getRootDeviceIndex();

View File

@ -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

View File

@ -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);

View File

@ -235,4 +235,97 @@ TEST_F(clCompileProgramTests, GivenValidCallbackInputWhenLinkProgramThenCallback
EXPECT_EQ(CL_SUCCESS, retVal);
}
TEST(clCompileProgramTest, givenMultiDeviceProgramWhenCompilingForInvalidDevicesInputThenInvalidDeviceErrorIsReturned) {
cl_program pProgram = nullptr;
std::unique_ptr<char[]> 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

View File

@ -98,6 +98,140 @@ TEST_F(clGetProgramBuildInfoTests, givenSourceWhenclGetProgramBuildInfoIsCalledT
EXPECT_EQ(CL_SUCCESS, retVal);
}
TEST(clGetProgramBuildInfoTest, givenMultiDeviceProgramWhenCompilingForSpecificDevicesThenOnlySpecificDevicesReportBuildStatus) {
cl_program pProgram = nullptr;
std::unique_ptr<char[]> 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<char[]> 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<cl_device_id>(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

View File

@ -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<ClDevice *>(invalidDevice),
CL_PROGRAM_BUILD_STATUS,
paramValueSize,
&buildStatus,
&paramValueSizeRet);
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<ClDevice *>(pContext),
CL_PROGRAM_BUILD_STATUS,
paramValueSize,
&buildStatus,
&paramValueSizeRet);
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> rootDeviceEnvironment = std::make_unique<NoCompilerInterfaceRootDeviceEnvironment>(*executionEnvironment);
std::swap(rootDeviceEnvironment, executionEnvironment->rootDeviceEnvironments[device->getRootDeviceIndex()]);
auto p2 = std::make_unique<MockProgram>(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<MockProgram>(pContext, reinterpret_cast<const void *>(spirv), sizeof(spirv), errCode);
ASSERT_NE(nullptr, prog);
cl_device_id deviceId = pClDevice;
auto pProgram = Program::createFromIL<MockProgram>(pContext, reinterpret_cast<const void *>(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<const unsigned char *>(spirv)};
auto prog = Program::create<MockProgram>(pContext, pContext->getDevices(), &lengths, binaries, nullptr, errCode);
ASSERT_NE(nullptr, prog);
auto pProgram = Program::create<MockProgram>(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<MockCompilerInterfaceWithGtpinParam> 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());

View File

@ -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);

View File

@ -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<GMockProgram>(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);