Skip to content

Commit fc7a490

Browse files
authored
Split USM alignment tests into small and large alignments (#48)
Related-To: NEO-8431 Signed-off-by: Wenbin Lu <[email protected]>
1 parent d0522a0 commit fc7a490

File tree

3 files changed

+90
-54
lines changed

3 files changed

+90
-54
lines changed

conformance_tests/core/test_memory/src/test_memory.cpp

Lines changed: 82 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
/*
22
*
3-
* Copyright (C) 2019-2023 Intel Corporation
3+
* Copyright (C) 2019-2024 Intel Corporation
44
*
55
* SPDX-License-Identifier: MIT
66
*
77
*/
88

99
#include <boost/interprocess/shared_memory_object.hpp>
1010
#include <boost/interprocess/managed_shared_memory.hpp>
11-
#include <chrono>
12-
#include <thread>
1311

1412
#include "gtest/gtest.h"
1513

@@ -66,11 +64,17 @@ TEST_P(zeDriverAllocDeviceMemAlignmentTests,
6664
}
6765
}
6866

69-
INSTANTIATE_TEST_SUITE_P(zeDriverAllocDeviceMemTestVarySizeAndAlignment,
70-
zeDriverAllocDeviceMemAlignmentTests,
71-
::testing::Combine(::testing::Values(0),
72-
lzt::memory_allocation_sizes,
73-
lzt::memory_allocation_alignments));
67+
INSTANTIATE_TEST_SUITE_P(
68+
zeDriverAllocDeviceMemTestVarySizeAndAlignment,
69+
zeDriverAllocDeviceMemAlignmentTests,
70+
::testing::Combine(::testing::Values(0), lzt::memory_allocation_sizes,
71+
lzt::memory_allocation_alignments_small));
72+
73+
INSTANTIATE_TEST_SUITE_P(
74+
zeDriverAllocDeviceMemTestVarySizeAndLargeAlignment,
75+
zeDriverAllocDeviceMemAlignmentTests,
76+
::testing::Combine(::testing::Values(0), lzt::memory_allocation_sizes,
77+
lzt::memory_allocation_alignments_large));
7478

7579
class zeMemGetAllocPropertiesTests : public zeDriverAllocDeviceMemTests {};
7680

@@ -266,37 +270,53 @@ class zeDriverAllocSharedMemAlignmentTests
266270
: public ::testing::Test,
267271
public ::testing::WithParamInterface<
268272
std::tuple<ze_device_mem_alloc_flag_t, ze_host_mem_alloc_flag_t,
269-
size_t, size_t>> {};
273+
size_t, size_t>> {
274+
protected:
275+
void SetUp() override {
276+
const ze_device_mem_alloc_flag_t dev_flags = std::get<0>(GetParam());
277+
const ze_host_mem_alloc_flag_t host_flags = std::get<1>(GetParam());
278+
size_ = std::get<2>(GetParam());
279+
alignment_ = std::get<3>(GetParam());
270280

271-
TEST_P(zeDriverAllocSharedMemAlignmentTests,
272-
GivenSizeAndAlignmentWhenAllocatingSharedMemoryThenPointerIsAligned) {
281+
auto driver = lzt::get_default_driver();
282+
auto device = lzt::get_default_device(driver);
283+
context_ = lzt::create_context();
284+
memory_ = lzt::allocate_shared_memory(size_, alignment_, dev_flags,
285+
host_flags, device, context_);
286+
}
273287

274-
const ze_device_mem_alloc_flag_t dev_flags = std::get<0>(GetParam());
275-
const ze_host_mem_alloc_flag_t host_flags = std::get<1>(GetParam());
276-
const size_t size = std::get<2>(GetParam());
277-
const size_t alignment = std::get<3>(GetParam());
288+
void TearDown() override {
289+
lzt::free_memory(context_, memory_);
290+
lzt::destroy_context(context_);
291+
}
278292

279-
void *memory = nullptr;
280-
auto driver = lzt::get_default_driver();
281-
auto device = lzt::get_default_device(driver);
282-
auto context = lzt::create_context();
293+
size_t size_;
294+
size_t alignment_;
295+
void *memory_ = nullptr;
296+
ze_context_handle_t context_;
297+
};
283298

284-
memory = lzt::allocate_shared_memory(size, alignment, dev_flags, host_flags,
285-
device, context);
286-
EXPECT_NE(nullptr, memory);
287-
if (alignment != 0) {
288-
EXPECT_EQ(0u, reinterpret_cast<uintptr_t>(memory) % alignment);
299+
TEST_P(zeDriverAllocSharedMemAlignmentTests,
300+
GivenSizeAndAlignmentWhenAllocatingSharedMemoryThenPointerIsAligned) {
301+
EXPECT_NE(nullptr, memory_);
302+
if (alignment_ != 0) {
303+
EXPECT_EQ(0u, reinterpret_cast<uintptr_t>(memory_) % alignment_);
289304
}
290-
lzt::free_memory(context, memory);
291-
lzt::destroy_context(context);
292305
}
293306

294-
INSTANTIATE_TEST_SUITE_P(zeDriverAllocSharedMemTestVarySizeAndAlignment,
295-
zeDriverAllocSharedMemAlignmentTests,
296-
::testing::Combine(::testing::Values(0),
297-
::testing::Values(0),
298-
lzt::memory_allocation_sizes,
299-
lzt::memory_allocation_alignments));
307+
INSTANTIATE_TEST_SUITE_P(
308+
zeDriverAllocSharedMemTestVarySizeAndAlignment,
309+
zeDriverAllocSharedMemAlignmentTests,
310+
::testing::Combine(::testing::Values(0), ::testing::Values(0),
311+
lzt::memory_allocation_sizes,
312+
lzt::memory_allocation_alignments_small));
313+
314+
INSTANTIATE_TEST_SUITE_P(
315+
zeDriverAllocSharedMemTestVarySizeAndLargeAlignment,
316+
zeDriverAllocSharedMemAlignmentTests,
317+
::testing::Combine(::testing::Values(0), ::testing::Values(0),
318+
lzt::memory_allocation_sizes,
319+
lzt::memory_allocation_alignments_large));
300320

301321
class zeSharedMemGetPropertiesTests
302322
: public ::testing::Test,
@@ -433,33 +453,42 @@ INSTANTIATE_TEST_SUITE_P(
433453
ZE_HOST_MEM_ALLOC_FLAG_BIAS_WRITE_COMBINED),
434454
lzt::memory_allocation_sizes, lzt::memory_allocation_alignments));
435455

436-
class zeDriverAllocHostMemAlignmentTests : public zeDriverAllocHostMemTests {};
437-
438-
TEST_P(zeDriverAllocHostMemAlignmentTests,
439-
GivenSizeAndAlignmentWhenAllocatingHostMemoryThenPointerIsAligned) {
440-
441-
const ze_host_mem_alloc_flag_t flags = std::get<0>(GetParam());
456+
class zeDriverAllocHostMemAlignmentTests : public zeDriverAllocHostMemTests {
457+
protected:
458+
void SetUp() override {
459+
const ze_host_mem_alloc_flag_t flags = std::get<0>(GetParam());
460+
size_ = std::get<1>(GetParam());
461+
alignment_ = std::get<2>(GetParam());
462+
memory_ = lzt::allocate_host_memory(size_, alignment_, flags, nullptr,
463+
lzt::get_default_context());
464+
}
442465

443-
const size_t size = std::get<1>(GetParam());
444-
const size_t alignment = std::get<2>(GetParam());
466+
void TearDown() override { lzt::free_memory(memory_); }
445467

446-
void *memory = nullptr;
447-
memory = lzt::allocate_host_memory(size, alignment, flags, nullptr,
448-
lzt::get_default_context());
468+
size_t size_;
469+
size_t alignment_;
470+
void *memory_ = nullptr;
471+
};
449472

450-
EXPECT_NE(nullptr, memory);
451-
if (alignment != 0) {
452-
EXPECT_EQ(0u, reinterpret_cast<uintptr_t>(memory) % alignment);
473+
TEST_P(zeDriverAllocHostMemAlignmentTests,
474+
GivenSizeAndAlignmentWhenAllocatingHostMemoryThenPointerIsAligned) {
475+
EXPECT_NE(nullptr, memory_);
476+
if (alignment_ != 0) {
477+
EXPECT_EQ(0u, reinterpret_cast<uintptr_t>(memory_) % alignment_);
453478
}
454-
455-
lzt::free_memory(memory);
456479
}
457480

458-
INSTANTIATE_TEST_SUITE_P(zeDriverAllocHostMemTestVarySizeAndAlignment,
459-
zeDriverAllocHostMemAlignmentTests,
460-
::testing::Combine(::testing::Values(0),
461-
lzt::memory_allocation_sizes,
462-
lzt::memory_allocation_alignments));
481+
INSTANTIATE_TEST_SUITE_P(
482+
zeDriverAllocHostMemTestVarySizeAndAlignment,
483+
zeDriverAllocHostMemAlignmentTests,
484+
::testing::Combine(::testing::Values(0), lzt::memory_allocation_sizes,
485+
lzt::memory_allocation_alignments_small));
486+
487+
INSTANTIATE_TEST_SUITE_P(
488+
zeDriverAllocHostMemTestVarySizeAndLargeAlignment,
489+
zeDriverAllocHostMemAlignmentTests,
490+
::testing::Combine(::testing::Values(0), lzt::memory_allocation_sizes,
491+
lzt::memory_allocation_alignments_large));
463492

464493
class zeHostMemPropertiesTests
465494
: public ::testing::Test,

scripts/level_zero_report_utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ def assign_test_feature_tag(test_feature: str, test_name: str, test_section: str
137137
(re.search('L0_CTS_zeDriverAllocSharedMemTestVarySizeAndAlignment_zeDriverAllocSharedMemAlignmentTests_GivenSizeAndAlignmentWhenAllocatingDeviceMemoryThenPointerIsAligned', test_name, re.IGNORECASE)) or \
138138
(re.search('L0_CTS_zeDriverAllocHostMemTestVarySizeAndAlignment_zeDriverAllocHostMemAlignmentTests_GivenSizeAndAlignmentWhenAllocatingHostMemoryThenPointerIsAligned', test_name, re.IGNORECASE)) or \
139139
(re.search('L0_CTS_zeDriverAllocDeviceMemTestVarySizeAndAlignment_zeDriverAllocDeviceMemAlignmentTests_GivenSizeAndAlignmentWhenAllocatingDeviceMemoryThenPointerIsAligned', test_name, re.IGNORECASE)) or \
140+
(re.search('L0_CTS_zeDriverAllocDeviceMemTestVarySizeAndLargeAlignment_zeDriverAllocDeviceMemAlignmentTests_GivenSizeAndAlignmentWhenAllocatingDeviceMemoryThenPointerIsAligned', test_name, re.IGNORECASE)) or \
141+
(re.search('L0_CTS_zeDriverAllocHostMemTestVarySizeAndLargeAlignment_zeDriverAllocHostMemAlignmentTests_GivenSizeAndAlignmentWhenAllocatingHostMemoryThenPointerIsAligned', test_name, re.IGNORECASE)) or \
142+
(re.search('L0_CTS_zeDriverAllocSharedMemTestVarySizeAndLargeAlignment_zeDriverAllocSharedMemAlignmentTests_GivenSizeAndAlignmentWhenAllocatingSharedMemoryThenPointerIsAligned', test_name, re.IGNORECASE)) or \
140143
(re.search('L0_CTS_IpcMemoryAccessTest_GivenL0MemoryAllocatedInChildProcessWhenUsingL0IPCOnImmediateCmdListThenParentProcessReadsMemoryCorrectly', test_name, re.IGNORECASE)) or \
141144
(re.search('L0_CTS_IpcMemoryAccessTest_GivenL0MemoryAllocatedInChildProcessBiasCachedWhenUsingL0IPCThenParentProcessReadsMemoryCorrectly', test_name, re.IGNORECASE)) or \
142145
(re.search('L0_CTS_IpcMemoryAccessTest_GivenL0MemoryAllocatedInChildProcessBiasCachedWhenUsingL0IPCOnImmediateCmdListThenParentProcessReadsMemoryCorrectly', test_name, re.IGNORECASE)) or \

utils/test_harness/include/test_harness/test_harness_memory.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#ifndef level_zero_tests_ZE_TEST_HARNESS_MEMORY_HPP
1010
#define level_zero_tests_ZE_TEST_HARNESS_MEMORY_HPP
1111

12-
#include "test_harness_device.hpp"
1312
#include <level_zero/ze_api.h>
1413
#include "gtest/gtest.h"
1514

@@ -29,6 +28,11 @@ const auto memory_allocation_sizes =
2928
const auto memory_allocation_alignments = ::testing::Values(
3029
0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384,
3130
32768, 65536, 1u << 17, 1u << 18, 1u << 19, 1u << 20, 1u << 21, 1u << 22);
31+
const auto memory_allocation_alignments_small =
32+
::testing::Values(0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048,
33+
4096, 8192, 16384, 32768, 65536);
34+
const auto memory_allocation_alignments_large = ::testing::Values(
35+
1u << 17, 1u << 18, 1u << 19, 1u << 20, 1u << 21, 1u << 22, 1u << 23);
3236

3337
void *allocate_host_memory(const size_t size);
3438
void *allocate_host_memory(const size_t size, const size_t alignment);

0 commit comments

Comments
 (0)