Skip to content

Commit bd78b3e

Browse files
Extend AppendMemoryCopy tests with memory advise (#312)
Signed-off-by: Misiak, Konstanty <[email protected]>
1 parent bd353ca commit bd78b3e

File tree

3 files changed

+46
-11
lines changed

3 files changed

+46
-11
lines changed

conformance_tests/core/test_copy/src/test_copy.cpp

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -776,12 +776,12 @@ LZT_TEST_F(
776776
class zeCommandListAppendMemoryBackToBackTests
777777
: public ::testing::Test,
778778
public ::testing::WithParamInterface<
779-
std::tuple<bool, bool, bool, bool, size_t>> {
779+
std::tuple<bool, bool, bool, bool, bool, size_t>> {
780780

781781
protected:
782782
void RunGivenCopyBetweenUsmAndSharedSystemUsmAndVerifyCorrect(
783783
bool is_src_shared_system, bool is_dst_shared_system, bool is_immediate,
784-
bool isCopyOnly, size_t size) {
784+
bool is_copy_only, bool use_madvise, size_t size) {
785785
const uint8_t value = to_u8(rand()) & 0xFF;
786786
const uint8_t init = (value + 0x22) & 0xFF;
787787

@@ -791,26 +791,40 @@ class zeCommandListAppendMemoryBackToBackTests
791791
size, is_dst_shared_system);
792792

793793
uint32_t ordinal = 0;
794-
if (isCopyOnly) {
794+
if (is_copy_only) {
795795
ordinal = 1;
796796
}
797797

798798
const char *src_memory_type = is_src_shared_system ? "SVM" : "USM";
799799
const char *dst_memory_type = is_dst_shared_system ? "SVM" : "USM";
800800

801-
printf("src_memory (%s)= %p dst_memory (%s)= %p immediate = %d isCopyOnly "
802-
"= %d size = %zu\n",
803-
src_memory_type, src_memory, dst_memory_type, dst_memory,
804-
is_immediate, isCopyOnly, size);
801+
LOG_INFO << "src_memory (" << src_memory_type << ")= " << src_memory
802+
<< " dst_memory (" << dst_memory_type << ")= " << dst_memory
803+
<< " immediate = " << is_immediate
804+
<< " is_copy_only = " << is_copy_only
805+
<< " use_madvise = " << use_madvise << " size = " << size;
805806

806807
memset(src_memory, value, size);
807808
memset(dst_memory, init, size);
808809

810+
auto device = zeDevice::get_instance()->get_device();
809811
auto cmd_bundle = lzt::create_command_bundle(
810-
lzt::get_default_context(), zeDevice::get_instance()->get_device(), 0,
812+
lzt::get_default_context(), device, 0,
811813
ZE_COMMAND_QUEUE_MODE_ASYNCHRONOUS, ZE_COMMAND_QUEUE_PRIORITY_NORMAL, 0,
812814
ordinal, 0, is_immediate);
813815

816+
if (is_src_shared_system && use_madvise) {
817+
lzt::append_memory_advise(
818+
cmd_bundle.list, device, src_memory, size,
819+
ZE_MEMORY_ADVICE_SET_SYSTEM_MEMORY_PREFERRED_LOCATION);
820+
}
821+
822+
if (is_dst_shared_system && use_madvise) {
823+
lzt::append_memory_advise(
824+
cmd_bundle.list, device, dst_memory, size,
825+
ZE_MEMORY_ADVICE_SET_SYSTEM_MEMORY_PREFERRED_LOCATION);
826+
}
827+
814828
lzt::append_memory_copy(cmd_bundle.list, static_cast<void *>(dst_memory),
815829
static_cast<void *>(src_memory), size);
816830

@@ -827,15 +841,21 @@ LZT_TEST_P(
827841
zeCommandListAppendMemoryBackToBackTests,
828842
GivenAllUsmAndSvmPermutationsConfirmSuccessfulExecutionBackToBackWithSharedSystemAllocator) {
829843
SKIP_IF_SHARED_SYSTEM_ALLOC_UNSUPPORTED();
844+
bool is_src_shared_system = std::get<0>(GetParam());
845+
bool is_dst_shared_system = std::get<1>(GetParam());
846+
bool use_madvise = std::get<4>(GetParam());
847+
if (use_madvise && !is_src_shared_system && !is_dst_shared_system) {
848+
GTEST_SKIP() << "Skipping redundant case.";
849+
}
830850
RunGivenCopyBetweenUsmAndSharedSystemUsmAndVerifyCorrect(
831-
std::get<0>(GetParam()), std::get<1>(GetParam()), std::get<2>(GetParam()),
832-
std::get<3>(GetParam()), std::get<4>(GetParam()));
851+
is_src_shared_system, is_dst_shared_system, std::get<2>(GetParam()),
852+
std::get<3>(GetParam()), use_madvise, std::get<5>(GetParam()));
833853
}
834854

835855
INSTANTIATE_TEST_SUITE_P(
836856
ParameterizedTests, zeCommandListAppendMemoryBackToBackTests,
837857
::testing::Combine(::testing::Bool(), ::testing::Bool(), ::testing::Bool(),
838-
::testing::Bool(),
858+
::testing::Bool(), ::testing::Bool(),
839859
::testing::Values(10, 10 * 1024, 32 * 1024 * 1024)));
840860

841861
class zeCommandListAppendMemoryCopyFromContextWithDataVerificationTests

utils/test_harness/include/test_harness/test_harness_cmdlist.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ zeCommandBundle create_command_bundle(
9292
ze_command_queue_priority_t priority, ze_command_list_flags_t listFlags,
9393
uint32_t ordinal, uint32_t index, bool isImmediate);
9494

95+
void append_memory_advise(ze_command_list_handle_t cl,
96+
ze_device_handle_t device, const void *ptr,
97+
size_t size, ze_memory_advice_t advice);
98+
9599
void append_memory_set(ze_command_list_handle_t cl, void *dstptr,
96100
const uint8_t *value, size_t size);
97101
void append_memory_set(ze_command_list_handle_t cl, void *dstptr,

utils/test_harness/src/test_harness_cmdlist.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,17 @@ zeCommandBundle create_command_bundle(
247247
return {queue, list};
248248
}
249249

250+
void append_memory_advise(ze_command_list_handle_t cl,
251+
ze_device_handle_t device, const void *ptr,
252+
size_t size, ze_memory_advice_t advice) {
253+
auto command_list_initial = cl;
254+
auto device_initial = device;
255+
EXPECT_ZE_RESULT_SUCCESS(
256+
zeCommandListAppendMemAdvise(cl, device, ptr, size, advice));
257+
EXPECT_EQ(cl, command_list_initial);
258+
EXPECT_EQ(device, device_initial);
259+
}
260+
250261
void append_memory_set(ze_command_list_handle_t cl, void *dstptr,
251262
const uint8_t *value, size_t size) {
252263
append_memory_set(cl, dstptr, value, size, nullptr);

0 commit comments

Comments
 (0)