Skip to content

Commit

Permalink
Split USM alignment tests into small and large alignments (#48)
Browse files Browse the repository at this point in the history
Related-To: NEO-8431

Signed-off-by: Wenbin Lu <wenbin.lu@intel.com>
  • Loading branch information
lyu committed Jul 8, 2024
1 parent d0522a0 commit fc7a490
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 54 deletions.
135 changes: 82 additions & 53 deletions conformance_tests/core/test_memory/src/test_memory.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
/*
*
* Copyright (C) 2019-2023 Intel Corporation
* Copyright (C) 2019-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/

#include <boost/interprocess/shared_memory_object.hpp>
#include <boost/interprocess/managed_shared_memory.hpp>
#include <chrono>
#include <thread>

#include "gtest/gtest.h"

Expand Down Expand Up @@ -66,11 +64,17 @@ TEST_P(zeDriverAllocDeviceMemAlignmentTests,
}
}

INSTANTIATE_TEST_SUITE_P(zeDriverAllocDeviceMemTestVarySizeAndAlignment,
zeDriverAllocDeviceMemAlignmentTests,
::testing::Combine(::testing::Values(0),
lzt::memory_allocation_sizes,
lzt::memory_allocation_alignments));
INSTANTIATE_TEST_SUITE_P(
zeDriverAllocDeviceMemTestVarySizeAndAlignment,
zeDriverAllocDeviceMemAlignmentTests,
::testing::Combine(::testing::Values(0), lzt::memory_allocation_sizes,
lzt::memory_allocation_alignments_small));

INSTANTIATE_TEST_SUITE_P(
zeDriverAllocDeviceMemTestVarySizeAndLargeAlignment,
zeDriverAllocDeviceMemAlignmentTests,
::testing::Combine(::testing::Values(0), lzt::memory_allocation_sizes,
lzt::memory_allocation_alignments_large));

class zeMemGetAllocPropertiesTests : public zeDriverAllocDeviceMemTests {};

Expand Down Expand Up @@ -266,37 +270,53 @@ class zeDriverAllocSharedMemAlignmentTests
: public ::testing::Test,
public ::testing::WithParamInterface<
std::tuple<ze_device_mem_alloc_flag_t, ze_host_mem_alloc_flag_t,
size_t, size_t>> {};
size_t, size_t>> {
protected:
void SetUp() override {
const ze_device_mem_alloc_flag_t dev_flags = std::get<0>(GetParam());
const ze_host_mem_alloc_flag_t host_flags = std::get<1>(GetParam());
size_ = std::get<2>(GetParam());
alignment_ = std::get<3>(GetParam());

TEST_P(zeDriverAllocSharedMemAlignmentTests,
GivenSizeAndAlignmentWhenAllocatingSharedMemoryThenPointerIsAligned) {
auto driver = lzt::get_default_driver();
auto device = lzt::get_default_device(driver);
context_ = lzt::create_context();
memory_ = lzt::allocate_shared_memory(size_, alignment_, dev_flags,
host_flags, device, context_);
}

const ze_device_mem_alloc_flag_t dev_flags = std::get<0>(GetParam());
const ze_host_mem_alloc_flag_t host_flags = std::get<1>(GetParam());
const size_t size = std::get<2>(GetParam());
const size_t alignment = std::get<3>(GetParam());
void TearDown() override {
lzt::free_memory(context_, memory_);
lzt::destroy_context(context_);
}

void *memory = nullptr;
auto driver = lzt::get_default_driver();
auto device = lzt::get_default_device(driver);
auto context = lzt::create_context();
size_t size_;
size_t alignment_;
void *memory_ = nullptr;
ze_context_handle_t context_;
};

memory = lzt::allocate_shared_memory(size, alignment, dev_flags, host_flags,
device, context);
EXPECT_NE(nullptr, memory);
if (alignment != 0) {
EXPECT_EQ(0u, reinterpret_cast<uintptr_t>(memory) % alignment);
TEST_P(zeDriverAllocSharedMemAlignmentTests,
GivenSizeAndAlignmentWhenAllocatingSharedMemoryThenPointerIsAligned) {
EXPECT_NE(nullptr, memory_);
if (alignment_ != 0) {
EXPECT_EQ(0u, reinterpret_cast<uintptr_t>(memory_) % alignment_);
}
lzt::free_memory(context, memory);
lzt::destroy_context(context);
}

INSTANTIATE_TEST_SUITE_P(zeDriverAllocSharedMemTestVarySizeAndAlignment,
zeDriverAllocSharedMemAlignmentTests,
::testing::Combine(::testing::Values(0),
::testing::Values(0),
lzt::memory_allocation_sizes,
lzt::memory_allocation_alignments));
INSTANTIATE_TEST_SUITE_P(
zeDriverAllocSharedMemTestVarySizeAndAlignment,
zeDriverAllocSharedMemAlignmentTests,
::testing::Combine(::testing::Values(0), ::testing::Values(0),
lzt::memory_allocation_sizes,
lzt::memory_allocation_alignments_small));

INSTANTIATE_TEST_SUITE_P(
zeDriverAllocSharedMemTestVarySizeAndLargeAlignment,
zeDriverAllocSharedMemAlignmentTests,
::testing::Combine(::testing::Values(0), ::testing::Values(0),
lzt::memory_allocation_sizes,
lzt::memory_allocation_alignments_large));

class zeSharedMemGetPropertiesTests
: public ::testing::Test,
Expand Down Expand Up @@ -433,33 +453,42 @@ INSTANTIATE_TEST_SUITE_P(
ZE_HOST_MEM_ALLOC_FLAG_BIAS_WRITE_COMBINED),
lzt::memory_allocation_sizes, lzt::memory_allocation_alignments));

class zeDriverAllocHostMemAlignmentTests : public zeDriverAllocHostMemTests {};

TEST_P(zeDriverAllocHostMemAlignmentTests,
GivenSizeAndAlignmentWhenAllocatingHostMemoryThenPointerIsAligned) {

const ze_host_mem_alloc_flag_t flags = std::get<0>(GetParam());
class zeDriverAllocHostMemAlignmentTests : public zeDriverAllocHostMemTests {
protected:
void SetUp() override {
const ze_host_mem_alloc_flag_t flags = std::get<0>(GetParam());
size_ = std::get<1>(GetParam());
alignment_ = std::get<2>(GetParam());
memory_ = lzt::allocate_host_memory(size_, alignment_, flags, nullptr,
lzt::get_default_context());
}

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

void *memory = nullptr;
memory = lzt::allocate_host_memory(size, alignment, flags, nullptr,
lzt::get_default_context());
size_t size_;
size_t alignment_;
void *memory_ = nullptr;
};

EXPECT_NE(nullptr, memory);
if (alignment != 0) {
EXPECT_EQ(0u, reinterpret_cast<uintptr_t>(memory) % alignment);
TEST_P(zeDriverAllocHostMemAlignmentTests,
GivenSizeAndAlignmentWhenAllocatingHostMemoryThenPointerIsAligned) {
EXPECT_NE(nullptr, memory_);
if (alignment_ != 0) {
EXPECT_EQ(0u, reinterpret_cast<uintptr_t>(memory_) % alignment_);
}

lzt::free_memory(memory);
}

INSTANTIATE_TEST_SUITE_P(zeDriverAllocHostMemTestVarySizeAndAlignment,
zeDriverAllocHostMemAlignmentTests,
::testing::Combine(::testing::Values(0),
lzt::memory_allocation_sizes,
lzt::memory_allocation_alignments));
INSTANTIATE_TEST_SUITE_P(
zeDriverAllocHostMemTestVarySizeAndAlignment,
zeDriverAllocHostMemAlignmentTests,
::testing::Combine(::testing::Values(0), lzt::memory_allocation_sizes,
lzt::memory_allocation_alignments_small));

INSTANTIATE_TEST_SUITE_P(
zeDriverAllocHostMemTestVarySizeAndLargeAlignment,
zeDriverAllocHostMemAlignmentTests,
::testing::Combine(::testing::Values(0), lzt::memory_allocation_sizes,
lzt::memory_allocation_alignments_large));

class zeHostMemPropertiesTests
: public ::testing::Test,
Expand Down
3 changes: 3 additions & 0 deletions scripts/level_zero_report_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ def assign_test_feature_tag(test_feature: str, test_name: str, test_section: str
(re.search('L0_CTS_zeDriverAllocSharedMemTestVarySizeAndAlignment_zeDriverAllocSharedMemAlignmentTests_GivenSizeAndAlignmentWhenAllocatingDeviceMemoryThenPointerIsAligned', test_name, re.IGNORECASE)) or \
(re.search('L0_CTS_zeDriverAllocHostMemTestVarySizeAndAlignment_zeDriverAllocHostMemAlignmentTests_GivenSizeAndAlignmentWhenAllocatingHostMemoryThenPointerIsAligned', test_name, re.IGNORECASE)) or \
(re.search('L0_CTS_zeDriverAllocDeviceMemTestVarySizeAndAlignment_zeDriverAllocDeviceMemAlignmentTests_GivenSizeAndAlignmentWhenAllocatingDeviceMemoryThenPointerIsAligned', test_name, re.IGNORECASE)) or \
(re.search('L0_CTS_zeDriverAllocDeviceMemTestVarySizeAndLargeAlignment_zeDriverAllocDeviceMemAlignmentTests_GivenSizeAndAlignmentWhenAllocatingDeviceMemoryThenPointerIsAligned', test_name, re.IGNORECASE)) or \
(re.search('L0_CTS_zeDriverAllocHostMemTestVarySizeAndLargeAlignment_zeDriverAllocHostMemAlignmentTests_GivenSizeAndAlignmentWhenAllocatingHostMemoryThenPointerIsAligned', test_name, re.IGNORECASE)) or \
(re.search('L0_CTS_zeDriverAllocSharedMemTestVarySizeAndLargeAlignment_zeDriverAllocSharedMemAlignmentTests_GivenSizeAndAlignmentWhenAllocatingSharedMemoryThenPointerIsAligned', test_name, re.IGNORECASE)) or \
(re.search('L0_CTS_IpcMemoryAccessTest_GivenL0MemoryAllocatedInChildProcessWhenUsingL0IPCOnImmediateCmdListThenParentProcessReadsMemoryCorrectly', test_name, re.IGNORECASE)) or \
(re.search('L0_CTS_IpcMemoryAccessTest_GivenL0MemoryAllocatedInChildProcessBiasCachedWhenUsingL0IPCThenParentProcessReadsMemoryCorrectly', test_name, re.IGNORECASE)) or \
(re.search('L0_CTS_IpcMemoryAccessTest_GivenL0MemoryAllocatedInChildProcessBiasCachedWhenUsingL0IPCOnImmediateCmdListThenParentProcessReadsMemoryCorrectly', test_name, re.IGNORECASE)) or \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#ifndef level_zero_tests_ZE_TEST_HARNESS_MEMORY_HPP
#define level_zero_tests_ZE_TEST_HARNESS_MEMORY_HPP

#include "test_harness_device.hpp"
#include <level_zero/ze_api.h>
#include "gtest/gtest.h"

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

void *allocate_host_memory(const size_t size);
void *allocate_host_memory(const size_t size, const size_t alignment);
Expand Down

0 comments on commit fc7a490

Please sign in to comment.