2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2019-02-18 20:12:54 +08:00
|
|
|
* Copyright (C) 2017-2019 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-09-18 03:26:09 +08:00
|
|
|
#include "core/memory_manager/graphics_allocation.h"
|
2019-09-26 18:10:38 +08:00
|
|
|
#include "core/memory_manager/unified_memory_manager.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "runtime/command_queue/command_queue.h"
|
|
|
|
#include "runtime/device/device.h"
|
2018-11-07 16:14:46 +08:00
|
|
|
#include "runtime/event/user_event.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
#include "unit_tests/mocks/mock_context.h"
|
|
|
|
|
|
|
|
#include "cl_api_tests.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
using namespace NEO;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
typedef api_tests clEnqueueSVMMigrateMemTests;
|
|
|
|
|
|
|
|
namespace ULT {
|
|
|
|
|
2019-02-18 20:12:54 +08:00
|
|
|
TEST_F(clEnqueueSVMMigrateMemTests, GivenInvalidCommandQueueWhenMigratingSVMThenInvalidCommandQueueErrorIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
auto retVal = clEnqueueSVMMigrateMem(
|
|
|
|
nullptr, // cl_command_queue command_queue
|
|
|
|
0, // cl_uint num_svm_pointers
|
|
|
|
nullptr, // const void **svm_pointers
|
|
|
|
nullptr, // const size_t *sizes
|
|
|
|
0, // const cl_mem_migration_flags flags
|
|
|
|
0, // cl_uint num_events_in_wait_list
|
|
|
|
nullptr, // const cl_event *event_wait_list
|
|
|
|
nullptr // cl_event *event
|
2018-06-13 03:54:39 +08:00
|
|
|
);
|
2017-12-21 07:45:38 +08:00
|
|
|
EXPECT_EQ(CL_INVALID_COMMAND_QUEUE, retVal);
|
|
|
|
}
|
|
|
|
|
2019-02-18 20:12:54 +08:00
|
|
|
TEST_F(clEnqueueSVMMigrateMemTests, GivenNullSvmPointersWhenMigratingSvmThenInvalidValueErrorIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
auto retVal = clEnqueueSVMMigrateMem(
|
|
|
|
pCommandQueue, // cl_command_queue command_queue
|
|
|
|
1, // cl_uint num_svm_pointers
|
|
|
|
nullptr, // const void **svm_pointers
|
|
|
|
nullptr, // const size_t *sizes
|
|
|
|
0, // const cl_mem_migration_flags flags
|
|
|
|
0, // cl_uint num_events_in_wait_list
|
|
|
|
nullptr, // const cl_event *event_wait_list
|
|
|
|
nullptr // cl_event *event
|
2018-06-13 03:54:39 +08:00
|
|
|
);
|
2017-12-21 07:45:38 +08:00
|
|
|
EXPECT_EQ(CL_INVALID_VALUE, retVal);
|
|
|
|
}
|
|
|
|
|
2019-02-18 20:12:54 +08:00
|
|
|
TEST_F(clEnqueueSVMMigrateMemTests, GivenNumSvmPointersIsZeroWhenMigratingSvmThenInvalidValueErrorIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
const DeviceInfo &devInfo = pPlatform->getDevice(0)->getDeviceInfo();
|
|
|
|
if (devInfo.svmCapabilities != 0) {
|
|
|
|
void *ptrSvm = clSVMAlloc(pContext, CL_MEM_READ_WRITE, 256, 4);
|
|
|
|
ASSERT_NE(nullptr, ptrSvm);
|
|
|
|
|
|
|
|
const void *svmPtrs[] = {ptrSvm};
|
|
|
|
auto retVal = clEnqueueSVMMigrateMem(
|
|
|
|
pCommandQueue, // cl_command_queue command_queue
|
|
|
|
0, // cl_uint num_svm_pointers
|
|
|
|
svmPtrs, // const void **svm_pointers
|
|
|
|
nullptr, // const size_t *sizes
|
|
|
|
0, // const cl_mem_migration_flags flags
|
|
|
|
0, // cl_uint num_events_in_wait_list
|
|
|
|
nullptr, // const cl_event *event_wait_list
|
|
|
|
nullptr // cl_event *event
|
2018-06-13 03:54:39 +08:00
|
|
|
);
|
2017-12-21 07:45:38 +08:00
|
|
|
EXPECT_EQ(CL_INVALID_VALUE, retVal);
|
|
|
|
|
|
|
|
clSVMFree(pContext, ptrSvm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-18 20:12:54 +08:00
|
|
|
TEST_F(clEnqueueSVMMigrateMemTests, GivenSvmPointerIsHostPtrWhenMigratingSvmThenInvalidValueErrorIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
char *ptrHost = new char[10];
|
|
|
|
ASSERT_NE(nullptr, ptrHost);
|
|
|
|
|
|
|
|
const void *svmPtrs[] = {ptrHost};
|
|
|
|
auto retVal = clEnqueueSVMMigrateMem(
|
|
|
|
pCommandQueue, // cl_command_queue command_queue
|
|
|
|
1, // cl_uint num_svm_pointers
|
|
|
|
svmPtrs, // const void **svm_pointers
|
|
|
|
nullptr, // const size_t *sizes
|
|
|
|
0, // const cl_mem_migration_flags flags
|
|
|
|
0, // cl_uint num_events_in_wait_list
|
|
|
|
nullptr, // const cl_event *event_wait_list
|
|
|
|
nullptr // cl_event *event
|
2018-06-13 03:54:39 +08:00
|
|
|
);
|
2017-12-21 07:45:38 +08:00
|
|
|
EXPECT_EQ(CL_INVALID_VALUE, retVal);
|
|
|
|
|
|
|
|
delete[] ptrHost;
|
|
|
|
}
|
|
|
|
|
2019-02-18 20:12:54 +08:00
|
|
|
TEST_F(clEnqueueSVMMigrateMemTests, GivenNonZeroSizeIsNotContainedWithinAllocationWhenMigratingSvmThenInvalidValueErrorIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
const DeviceInfo &devInfo = pPlatform->getDevice(0)->getDeviceInfo();
|
|
|
|
if (devInfo.svmCapabilities != 0) {
|
|
|
|
void *ptrSvm = clSVMAlloc(pContext, CL_MEM_READ_WRITE, 256, 4);
|
|
|
|
ASSERT_NE(nullptr, ptrSvm);
|
|
|
|
|
2019-03-06 23:35:21 +08:00
|
|
|
auto svmData = pContext->getSVMAllocsManager()->getSVMAlloc(ptrSvm);
|
|
|
|
ASSERT_NE(nullptr, svmData);
|
|
|
|
auto svmAlloc = svmData->gpuAllocation;
|
2018-07-11 15:45:20 +08:00
|
|
|
EXPECT_NE(nullptr, svmAlloc);
|
|
|
|
size_t allocSize = svmAlloc->getUnderlyingBufferSize();
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
const void *svmPtrs[] = {ptrSvm};
|
2018-07-11 15:45:20 +08:00
|
|
|
const size_t sizes[] = {allocSize + 1};
|
2017-12-21 07:45:38 +08:00
|
|
|
auto retVal = clEnqueueSVMMigrateMem(
|
|
|
|
pCommandQueue, // cl_command_queue command_queue
|
|
|
|
1, // cl_uint num_svm_pointers
|
|
|
|
svmPtrs, // const void **svm_pointers
|
|
|
|
sizes, // const size_t *sizes
|
|
|
|
0, // const cl_mem_migration_flags flags
|
|
|
|
0, // cl_uint num_events_in_wait_list
|
|
|
|
nullptr, // const cl_event *event_wait_list
|
|
|
|
nullptr // cl_event *event
|
2018-06-13 03:54:39 +08:00
|
|
|
);
|
2017-12-21 07:45:38 +08:00
|
|
|
EXPECT_EQ(CL_INVALID_VALUE, retVal);
|
|
|
|
|
|
|
|
clSVMFree(pContext, ptrSvm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-18 20:12:54 +08:00
|
|
|
TEST_F(clEnqueueSVMMigrateMemTests, GivenUnsupportedFlagsWhenMigratingSvmThenInvalidValueErrorIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
const DeviceInfo &devInfo = pPlatform->getDevice(0)->getDeviceInfo();
|
|
|
|
if (devInfo.svmCapabilities != 0) {
|
|
|
|
void *ptrSvm = clSVMAlloc(pContext, CL_MEM_READ_WRITE, 256, 4);
|
|
|
|
ASSERT_NE(nullptr, ptrSvm);
|
|
|
|
|
|
|
|
const void *svmPtrs[] = {ptrSvm};
|
|
|
|
auto retVal = clEnqueueSVMMigrateMem(
|
|
|
|
pCommandQueue, // cl_command_queue command_queue
|
|
|
|
1, // cl_uint num_svm_pointers
|
|
|
|
svmPtrs, // const void **svm_pointers
|
|
|
|
nullptr, // const size_t *sizes
|
|
|
|
0xAA55AA55AA55AA55, // const cl_mem_migration_flags flags
|
|
|
|
0, // cl_uint num_events_in_wait_list
|
|
|
|
nullptr, // const cl_event *event_wait_list
|
|
|
|
nullptr // cl_event *event
|
2018-06-13 03:54:39 +08:00
|
|
|
);
|
2017-12-21 07:45:38 +08:00
|
|
|
EXPECT_EQ(CL_INVALID_VALUE, retVal);
|
|
|
|
|
|
|
|
clSVMFree(pContext, ptrSvm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-18 20:12:54 +08:00
|
|
|
TEST_F(clEnqueueSVMMigrateMemTests, GivenNullEventWaitListAndNonZeroNumEventsWhenMigratingSvmThenInvalidEventWaitListErrorIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
auto retVal = clEnqueueSVMMigrateMem(
|
|
|
|
pCommandQueue, // cl_command_queue command_queue
|
|
|
|
0, // cl_uint num_svm_pointers
|
|
|
|
nullptr, // const void **svm_pointers
|
|
|
|
nullptr, // const size_t *sizes
|
|
|
|
0, // const cl_mem_migration_flags flags
|
|
|
|
1, // cl_uint num_events_in_wait_list
|
|
|
|
nullptr, // const cl_event *event_wait_list
|
|
|
|
nullptr // cl_event *event
|
2018-06-13 03:54:39 +08:00
|
|
|
);
|
2017-12-21 07:45:38 +08:00
|
|
|
EXPECT_EQ(CL_INVALID_EVENT_WAIT_LIST, retVal);
|
|
|
|
}
|
|
|
|
|
2019-02-18 20:12:54 +08:00
|
|
|
TEST_F(clEnqueueSVMMigrateMemTests, GivenNonNullEventWaitListAndZeroNumEventsWhenMigratingSvmThenInvalidEventWaitListErrorIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
UserEvent uEvent(pContext);
|
|
|
|
cl_event eventWaitList[] = {&uEvent};
|
|
|
|
auto retVal = clEnqueueSVMMigrateMem(
|
|
|
|
pCommandQueue, // cl_command_queue command_queue
|
|
|
|
0, // cl_uint num_svm_pointers
|
|
|
|
nullptr, // const void **svm_pointers
|
|
|
|
nullptr, // const size_t *sizes
|
|
|
|
0, // const cl_mem_migration_flags flags
|
|
|
|
0, // cl_uint num_events_in_wait_list
|
|
|
|
eventWaitList, // const cl_event *event_wait_list
|
|
|
|
nullptr // cl_event *event
|
2018-06-13 03:54:39 +08:00
|
|
|
);
|
2017-12-21 07:45:38 +08:00
|
|
|
EXPECT_EQ(CL_INVALID_EVENT_WAIT_LIST, retVal);
|
|
|
|
}
|
|
|
|
|
2019-02-18 20:12:54 +08:00
|
|
|
TEST_F(clEnqueueSVMMigrateMemTests, GivenDifferentContextCommandQueueAndEventsWhenMigratingSvmThenInvalidContextErrorIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
const DeviceInfo &devInfo = pPlatform->getDevice(0)->getDeviceInfo();
|
|
|
|
if (devInfo.svmCapabilities != 0) {
|
|
|
|
void *ptrSvm = clSVMAlloc(pContext, CL_MEM_READ_WRITE, 256, 4);
|
|
|
|
ASSERT_NE(nullptr, ptrSvm);
|
|
|
|
|
|
|
|
MockContext mockContext;
|
|
|
|
UserEvent uEvent(&mockContext);
|
|
|
|
cl_event eventWaitList[] = {&uEvent};
|
|
|
|
const void *svmPtrs[] = {ptrSvm};
|
|
|
|
auto retVal = clEnqueueSVMMigrateMem(
|
|
|
|
pCommandQueue, // cl_command_queue command_queue
|
|
|
|
1, // cl_uint num_svm_pointers
|
|
|
|
svmPtrs, // const void **svm_pointers
|
|
|
|
nullptr, // const size_t *sizes
|
|
|
|
0, // const cl_mem_migration_flags flags
|
|
|
|
1, // cl_uint num_events_in_wait_list
|
|
|
|
eventWaitList, // const cl_event *event_wait_list
|
|
|
|
nullptr // cl_event *event
|
2018-06-13 03:54:39 +08:00
|
|
|
);
|
2017-12-21 07:45:38 +08:00
|
|
|
EXPECT_EQ(CL_INVALID_CONTEXT, retVal);
|
|
|
|
|
|
|
|
clSVMFree(pContext, ptrSvm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-18 20:12:54 +08:00
|
|
|
TEST_F(clEnqueueSVMMigrateMemTests, GivenNullSizesWhenMigratingSvmThenSuccessIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
const DeviceInfo &devInfo = pPlatform->getDevice(0)->getDeviceInfo();
|
|
|
|
if (devInfo.svmCapabilities != 0) {
|
|
|
|
void *ptrSvm = clSVMAlloc(pContext, CL_MEM_READ_WRITE, 256, 4);
|
|
|
|
ASSERT_NE(nullptr, ptrSvm);
|
|
|
|
|
|
|
|
const void *svmPtrs[] = {ptrSvm};
|
|
|
|
auto retVal = clEnqueueSVMMigrateMem(
|
|
|
|
pCommandQueue, // cl_command_queue command_queue
|
|
|
|
1, // cl_uint num_svm_pointers
|
|
|
|
svmPtrs, // const void **svm_pointers
|
|
|
|
nullptr, // const size_t *sizes
|
|
|
|
0, // const cl_mem_migration_flags flags
|
|
|
|
0, // cl_uint num_events_in_wait_list
|
|
|
|
nullptr, // const cl_event *event_wait_list
|
|
|
|
nullptr // cl_event *event
|
2018-06-13 03:54:39 +08:00
|
|
|
);
|
2017-12-21 07:45:38 +08:00
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
clSVMFree(pContext, ptrSvm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-18 20:12:54 +08:00
|
|
|
TEST_F(clEnqueueSVMMigrateMemTests, GivenSizeZeroWhenMigratingSvmThenSuccessIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
const DeviceInfo &devInfo = pPlatform->getDevice(0)->getDeviceInfo();
|
|
|
|
if (devInfo.svmCapabilities != 0) {
|
|
|
|
void *ptrSvm = clSVMAlloc(pContext, CL_MEM_READ_WRITE, 256, 4);
|
|
|
|
ASSERT_NE(nullptr, ptrSvm);
|
|
|
|
|
|
|
|
const void *svmPtrs[] = {ptrSvm};
|
|
|
|
const size_t sizes[] = {0};
|
|
|
|
auto retVal = clEnqueueSVMMigrateMem(
|
|
|
|
pCommandQueue, // cl_command_queue command_queue
|
|
|
|
1, // cl_uint num_svm_pointers
|
|
|
|
svmPtrs, // const void **svm_pointers
|
|
|
|
sizes, // const size_t *sizes
|
|
|
|
0, // const cl_mem_migration_flags flags
|
|
|
|
0, // cl_uint num_events_in_wait_list
|
|
|
|
nullptr, // const cl_event *event_wait_list
|
|
|
|
nullptr // cl_event *event
|
2018-06-13 03:54:39 +08:00
|
|
|
);
|
2017-12-21 07:45:38 +08:00
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
clSVMFree(pContext, ptrSvm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-18 20:12:54 +08:00
|
|
|
TEST_F(clEnqueueSVMMigrateMemTests, GivenNonZeroSizeWhenMigratingSvmThenSuccessIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
const DeviceInfo &devInfo = pPlatform->getDevice(0)->getDeviceInfo();
|
|
|
|
if (devInfo.svmCapabilities != 0) {
|
|
|
|
void *ptrSvm = clSVMAlloc(pContext, CL_MEM_READ_WRITE, 256, 4);
|
|
|
|
ASSERT_NE(nullptr, ptrSvm);
|
|
|
|
|
|
|
|
const void *svmPtrs[] = {ptrSvm};
|
|
|
|
const size_t sizes[] = {256};
|
|
|
|
auto retVal = clEnqueueSVMMigrateMem(
|
|
|
|
pCommandQueue, // cl_command_queue command_queue
|
|
|
|
1, // cl_uint num_svm_pointers
|
|
|
|
svmPtrs, // const void **svm_pointers
|
|
|
|
sizes, // const size_t *sizes
|
|
|
|
0, // const cl_mem_migration_flags flags
|
|
|
|
0, // cl_uint num_events_in_wait_list
|
|
|
|
nullptr, // const cl_event *event_wait_list
|
|
|
|
nullptr // cl_event *event
|
2018-06-13 03:54:39 +08:00
|
|
|
);
|
2017-12-21 07:45:38 +08:00
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
clSVMFree(pContext, ptrSvm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-18 20:12:54 +08:00
|
|
|
TEST_F(clEnqueueSVMMigrateMemTests, GivenSameContextCommandQueueAndEventsWhenMigratingSvmThenSuccessIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
const DeviceInfo &devInfo = pPlatform->getDevice(0)->getDeviceInfo();
|
|
|
|
if (devInfo.svmCapabilities != 0) {
|
|
|
|
void *ptrSvm = clSVMAlloc(pContext, CL_MEM_READ_WRITE, 256, 4);
|
|
|
|
ASSERT_NE(nullptr, ptrSvm);
|
|
|
|
|
|
|
|
UserEvent uEvent(pContext);
|
|
|
|
cl_event eventWaitList[] = {&uEvent};
|
|
|
|
const void *svmPtrs[] = {ptrSvm};
|
|
|
|
auto retVal = clEnqueueSVMMigrateMem(
|
|
|
|
pCommandQueue, // cl_command_queue command_queue
|
|
|
|
1, // cl_uint num_svm_pointers
|
|
|
|
svmPtrs, // const void **svm_pointers
|
|
|
|
nullptr, // const size_t *sizes
|
|
|
|
0, // const cl_mem_migration_flags flags
|
|
|
|
1, // cl_uint num_events_in_wait_list
|
|
|
|
eventWaitList, // const cl_event *event_wait_list
|
|
|
|
nullptr // cl_event *event
|
2018-06-13 03:54:39 +08:00
|
|
|
);
|
2017-12-21 07:45:38 +08:00
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
clSVMFree(pContext, ptrSvm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace ULT
|