Skip to content

Commit 73dad03

Browse files
Fix clSVMAlloc function: use device from context
Related-To: NEO-4000 Change-Id: Iefad9d7a8908a584b98801bdbe13aa1e0be2e47f Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
1 parent dfc50f3 commit 73dad03

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

runtime/api/api.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3971,15 +3971,13 @@ void *CL_API_CALL clSVMAlloc(cl_context context,
39713971
"size", size,
39723972
"alignment", alignment);
39733973
void *pAlloc = nullptr;
3974-
auto pPlatform = platform();
3975-
auto pDevice = pPlatform->getDevice(0);
3976-
39773974
Context *pContext = nullptr;
39783975

3979-
if (validateObjects(WithCastToInternal(context, &pContext), pDevice) != CL_SUCCESS) {
3976+
if (validateObjects(WithCastToInternal(context, &pContext)) != CL_SUCCESS) {
39803977
TRACING_EXIT(clSVMAlloc, &pAlloc);
39813978
return pAlloc;
39823979
}
3980+
auto pDevice = pContext->getDevice(0);
39833981

39843982
if (flags == 0) {
39853983
flags = CL_MEM_READ_WRITE;

unit_tests/api/cl_svm_alloc_tests.inl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*
66
*/
77

8+
#include "core/unit_tests/utilities/base_object_utils.h"
89
#include "runtime/context/context.h"
910
#include "runtime/device/device.h"
1011

@@ -35,6 +36,27 @@ struct clSVMAllocValidFlagsTests : public clSVMAllocTemplateTests {
3536
cl_uchar pHostPtr[64];
3637
};
3738

39+
TEST(clSVMAllocTest, givenPlatformWithoutDevicesWhenClSVMAllocIsCalledThenDeviceIsTakenFromContext) {
40+
auto executionEnvironment = platform()->peekExecutionEnvironment();
41+
executionEnvironment->initializeMemoryManager();
42+
executionEnvironment->prepareRootDeviceEnvironments(1);
43+
auto device = std::unique_ptr<Device>(Device::create<RootDevice>(executionEnvironment, 0u));
44+
const DeviceInfo &devInfo = device->getDeviceInfo();
45+
if (devInfo.svmCapabilities == 0) {
46+
GTEST_SKIP();
47+
}
48+
cl_device_id clDevice = device.get();
49+
cl_int retVal;
50+
auto context = ReleaseableObjectPtr<Context>(Context::create<Context>(nullptr, DeviceVector(&clDevice, 1), nullptr, nullptr, retVal));
51+
EXPECT_EQ(CL_SUCCESS, retVal);
52+
53+
EXPECT_EQ(0u, platform()->getNumDevices());
54+
auto SVMPtr = clSVMAlloc(context.get(), 0u, 4096, 128);
55+
EXPECT_NE(nullptr, SVMPtr);
56+
57+
clSVMFree(context.get(), SVMPtr);
58+
}
59+
3860
TEST_P(clSVMAllocValidFlagsTests, GivenSvmSupportWhenAllocatingSvmThenSvmIsAllocated) {
3961
cl_mem_flags flags = GetParam();
4062
const DeviceInfo &devInfo = pPlatform->getDevice(0)->getDeviceInfo();

0 commit comments

Comments
 (0)