Skip to content

Commit d15174d

Browse files
Block SVMAllocsManager creation in Context when SVM is not supported
- skip SVM tests when SVM is not supported Related-To: NEO-3157 Change-Id: Ie5d5ef4778749f60537084fc7f388714954a4873 Signed-off-by: Hoppe, Mateusz <[email protected]>
1 parent 9217b80 commit d15174d

File tree

10 files changed

+74
-21
lines changed

10 files changed

+74
-21
lines changed

runtime/api/api.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3621,6 +3621,12 @@ cl_int CL_API_CALL clSetKernelArgSVMPointer(cl_kernel kernel,
36213621
return retVal;
36223622
}
36233623

3624+
auto svmManager = pKernel->getContext().getSVMAllocsManager();
3625+
if (!svmManager) {
3626+
retVal = CL_INVALID_ARG_VALUE;
3627+
return retVal;
3628+
}
3629+
36243630
cl_int kernelArgAddressQualifier = pKernel->getKernelArgAddressQualifier(argIndex);
36253631
if ((kernelArgAddressQualifier != CL_KERNEL_ARG_ADDRESS_GLOBAL) &&
36263632
(kernelArgAddressQualifier != CL_KERNEL_ARG_ADDRESS_CONSTANT)) {
@@ -3630,7 +3636,7 @@ cl_int CL_API_CALL clSetKernelArgSVMPointer(cl_kernel kernel,
36303636

36313637
GraphicsAllocation *pSvmAlloc = nullptr;
36323638
if (argValue != nullptr) {
3633-
auto svmData = pKernel->getContext().getSVMAllocsManager()->getSVMAlloc(argValue);
3639+
auto svmData = svmManager->getSVMAlloc(argValue);
36343640
if (svmData == nullptr) {
36353641
retVal = CL_INVALID_ARG_VALUE;
36363642
return retVal;
@@ -3668,6 +3674,10 @@ cl_int CL_API_CALL clSetKernelExecInfo(cl_kernel kernel,
36683674
size_t numPointers = paramValueSize / sizeof(void *);
36693675
size_t *pSvmPtrList = (size_t *)paramValue;
36703676

3677+
if (pKernel->getContext().getSVMAllocsManager() == nullptr) {
3678+
return CL_INVALID_VALUE;
3679+
}
3680+
36713681
pKernel->clearKernelExecInfo();
36723682
for (uint32_t i = 0; i < numPointers; i++) {
36733683
auto svmData = pKernel->getContext().getSVMAllocsManager()->getSVMAlloc((const void *)pSvmPtrList[i]);
@@ -4145,9 +4155,14 @@ cl_int CL_API_CALL clEnqueueSVMMigrateMem(cl_command_queue commandQueue,
41454155
retVal = CL_INVALID_VALUE;
41464156
return retVal;
41474157
}
4158+
auto pSvmAllocMgr = pCommandQueue->getContext().getSVMAllocsManager();
4159+
4160+
if (pSvmAllocMgr == nullptr) {
4161+
retVal = CL_INVALID_VALUE;
4162+
return retVal;
4163+
}
41484164

41494165
for (uint32_t i = 0; i < numSvmPointers; i++) {
4150-
SVMAllocsManager *pSvmAllocMgr = pCommandQueue->getContext().getSVMAllocsManager();
41514166
auto svmData = pSvmAllocMgr->getSVMAlloc(svmPointers[i]);
41524167
if (svmData == nullptr) {
41534168
retVal = CL_INVALID_VALUE;

runtime/context/context.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@ bool Context::createImpl(const cl_context_properties *properties,
166166
if (devices.size() > 0) {
167167
auto device = this->getDevice(0);
168168
this->memoryManager = device->getMemoryManager();
169-
this->svmAllocsManager = new SVMAllocsManager(this->memoryManager);
169+
if (device->getHardwareInfo().capabilityTable.ftrSvm) {
170+
this->svmAllocsManager = new SVMAllocsManager(this->memoryManager);
171+
}
170172
if (memoryManager->isAsyncDeleterEnabled()) {
171173
memoryManager->getDeferredDeleter()->addClient();
172174
}

runtime/mem_obj/buffer.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,18 @@ Buffer *Buffer::create(Context *context,
175175
allocateMemory = true;
176176
}
177177

178-
auto svmData = context->getSVMAllocsManager()->getSVMAlloc(hostPtr);
179-
if (svmData) {
180-
memory = svmData->gpuAllocation;
181-
allocationType = memory->getAllocationType();
182-
isHostPtrSVM = true;
183-
zeroCopyAllowed = memory->getAllocationType() == GraphicsAllocation::AllocationType::SVM_ZERO_COPY;
184-
copyMemoryFromHostPtr = false;
185-
allocateMemory = false;
186-
mapAllocation = svmData->cpuAllocation;
178+
auto svmManager = context->getSVMAllocsManager();
179+
if (svmManager) {
180+
auto svmData = svmManager->getSVMAlloc(hostPtr);
181+
if (svmData) {
182+
memory = svmData->gpuAllocation;
183+
allocationType = memory->getAllocationType();
184+
isHostPtrSVM = true;
185+
zeroCopyAllowed = memory->getAllocationType() == GraphicsAllocation::AllocationType::SVM_ZERO_COPY;
186+
copyMemoryFromHostPtr = false;
187+
allocateMemory = false;
188+
mapAllocation = svmData->cpuAllocation;
189+
}
187190
}
188191
}
189192

unit_tests/api/cl_api_tests.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,12 @@ void api_fixture::SetUp() {
4242
void api_fixture::TearDown() {
4343
delete pKernel;
4444
delete pCommandQueue;
45-
pContext->release();
46-
pProgram->release();
45+
if (pContext) {
46+
pContext->release();
47+
}
48+
if (pProgram) {
49+
pProgram->release();
50+
}
4751

4852
PlatformFixture::TearDown();
4953
}

unit_tests/api/cl_set_kernel_arg_svm_pointer_tests.inl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,15 @@ TEST_F(clSetKernelArgSVMPointer_, SetKernelArgSVMPointer_invalidArgValue) {
113113
}
114114

115115
TEST_F(clSetKernelArgSVMPointer_, SetKernelArgSVMPointerWithNullArgValue_success) {
116-
auto retVal = clSetKernelArgSVMPointer(
117-
pMockKernel, // cl_kernel kernel
118-
0, // cl_uint arg_index
119-
nullptr // const void *arg_value
120-
);
121-
EXPECT_EQ(CL_SUCCESS, retVal);
116+
const DeviceInfo &devInfo = pDevice->getDeviceInfo();
117+
if (devInfo.svmCapabilities != 0) {
118+
auto retVal = clSetKernelArgSVMPointer(
119+
pMockKernel, // cl_kernel kernel
120+
0, // cl_uint arg_index
121+
nullptr // const void *arg_value
122+
);
123+
EXPECT_EQ(CL_SUCCESS, retVal);
124+
}
122125
}
123126

124127
TEST_F(clSetKernelArgSVMPointer_, SetKernelArgSVMPointer_success) {

unit_tests/api/cl_svm_alloc_tests.inl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ class clSVMAllocTemplateTests : public api_fixture,
2121
public:
2222
void SetUp() override {
2323
api_fixture::SetUp();
24+
if (!pPlatform->peekExecutionEnvironment()->getHardwareInfo()->capabilityTable.ftrSvm) {
25+
GTEST_SKIP();
26+
}
2427
}
2528

2629
void TearDown() override {

unit_tests/context/context_tests.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,21 @@ TEST_F(ContextTest, givenContextWhenSharingTableIsNotEmptyThenReturnsSharingFunc
299299
EXPECT_EQ(sharingF, sharingFunctions);
300300
}
301301

302+
TEST(Context, givenFtrSvmFalseWhenContextIsCreatedThenSVMAllocsManagerIsNotCreated) {
303+
ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment();
304+
auto hwInfo = executionEnvironment->getMutableHardwareInfo();
305+
hwInfo->capabilityTable.ftrSvm = false;
306+
307+
std::unique_ptr<MockDevice> device(MockDevice::createWithExecutionEnvironment<MockDevice>(hwInfo, executionEnvironment, 0));
308+
309+
cl_device_id clDevice = device.get();
310+
cl_int retVal = CL_SUCCESS;
311+
auto context = std::unique_ptr<MockContext>(Context::create<MockContext>(nullptr, DeviceVector(&clDevice, 1), nullptr, nullptr, retVal));
312+
ASSERT_NE(nullptr, context);
313+
auto svmManager = context->getSVMAllocsManager();
314+
EXPECT_EQ(nullptr, svmManager);
315+
}
316+
302317
class ContextWithAsyncDeleterTest : public ::testing::WithParamInterface<bool>,
303318
public ::testing::Test {
304319
public:

unit_tests/context/driver_diagnostics_enqueue_tests.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,9 @@ TEST_P(PerformanceHintEnqueueMapTest, GivenZeroCopyFlagWhenEnqueueUnmapIsCalling
661661
}
662662

663663
TEST_F(PerformanceHintEnqueueTest, GivenSVMPointerWhenEnqueueSVMMapIsCallingThenContextProvidesProperHint) {
664-
664+
if (!pPlatform->peekExecutionEnvironment()->getHardwareInfo()->capabilityTable.ftrSvm) {
665+
GTEST_SKIP();
666+
}
665667
void *svmPtr = context->getSVMAllocsManager()->createSVMAlloc(256, {});
666668

667669
pCmdQ->enqueueSVMMap(CL_FALSE, 0, svmPtr, 256, 0, nullptr, nullptr);

unit_tests/kernel/clone_kernel_tests.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,9 @@ TEST_F(CloneKernelTest, cloneKernelWithArgImmediate) {
509509
}
510510

511511
TEST_F(CloneKernelTest, cloneKernelWithExecInfo) {
512+
if (!pDevice->getHardwareInfo().capabilityTable.ftrSvm) {
513+
GTEST_SKIP();
514+
}
512515
void *ptrSVM = pContext->getSVMAllocsManager()->createSVMAlloc(256, {});
513516
ASSERT_NE(nullptr, ptrSVM);
514517

unit_tests/mem_obj/buffer_set_arg_tests.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,9 @@ TEST_F(BufferSetArgTest, clSetKernelArgBuffer) {
261261
}
262262

263263
TEST_F(BufferSetArgTest, clSetKernelArgSVMPointer) {
264+
if (!pDevice->getHardwareInfo().capabilityTable.ftrSvm) {
265+
GTEST_SKIP();
266+
}
264267
void *ptrSVM = pContext->getSVMAllocsManager()->createSVMAlloc(256, {});
265268
EXPECT_NE(nullptr, ptrSVM);
266269

0 commit comments

Comments
 (0)