Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
41844f2
Cit -m RAII guards for memory allocations and streams, define some co…
music-dino Sep 30, 2022
858da0e
Implement helper function for generating allocation flags
music-dino Oct 3, 2022
899b91f
Implement helper function DeviceAttributesSupport to check if a devic…
music-dino Oct 4, 2022
736eff8
EXSWHTEC-83 - Implement new and reimplement existing tests for hipMem…
music-dino Oct 4, 2022
5a1878c
EXSWHTEC-83 - Correct bug in Flags_Do_Not_Cause_Prefetch, and minor c…
music-dino Oct 4, 2022
56b5982
EXSWHTEC-83 - Implement additional negative parameter tests
music-dino Oct 4, 2022
8a0e740
Add error check after launching delay kernel
music-dino Oct 4, 2022
8ddd164
Merge remote-tracking branch 'origin/utils' into hipMemAdvise_tests
music-dino Oct 6, 2022
e534d2e
EXSWHTEC-94 - Implement helper classes and functions for memory tests
music-dino Oct 6, 2022
09ce86a
EXSWHTEC-94 - Remove c++14 standard constraint on memory tests
music-dino Oct 6, 2022
12627cf
Merge branch 'utils' into hipMemAdvise_tests
music-dino Oct 6, 2022
48b337f
EXSWHTEC-94 - Remove GenerateLinearAllocationFlagCombinations until f…
music-dino Oct 6, 2022
2d3b7a7
Merge branch 'develop' into utils
music-dino Oct 8, 2022
715cf30
EXSWHTEC-94 - Implement helper classes and functions for memory tests
music-dino Oct 6, 2022
a74fe21
EXSWHTEC-94 - Remove c++14 standard constraint on memory tests
music-dino Oct 6, 2022
350958e
EXSWHTEC-94 - Remove GenerateLinearAllocationFlagCombinations until f…
music-dino Oct 6, 2022
ea6689c
Merge branch 'develop' into utils
music-dino Oct 10, 2022
2a44046
Merge remote-tracking branch 'origin/utils' into utils
mirza-halilcevic Oct 10, 2022
691d00e
EXSWHTEC-94 - Implement helper classes and functions for memory tests
music-dino Oct 6, 2022
7bdf52f
EXSWHTEC-94 - Remove c++14 standard constraint on memory tests
music-dino Oct 6, 2022
1185c39
EXSWHTEC-94 - Remove GenerateLinearAllocationFlagCombinations until f…
music-dino Oct 6, 2022
8d2e833
Merge remote-tracking branch 'origin/utils' into utils
music-dino Oct 11, 2022
e003c4f
Merge remote-tracking branch 'origin/utils' into utils
mirza-halilcevic Oct 12, 2022
8911eb7
EXSWHTEC-94 - Implement resource guards for hipMallocPitch and 3D
mirza-halilcevic Oct 12, 2022
b1a68bd
Merge remote-tracking branch 'origin/utils' into utils
music-dino Oct 14, 2022
76c8e31
EXSWHTEC-94 - Add resource guards for 2D and 3D allocations and utils…
music-dino Oct 14, 2022
35f373e
Merge remote-tracking branch 'upstream/develop' into utils
music-dino Oct 14, 2022
73f5c14
Merge branch 'utils' into hipMemAdvise_tests
music-dino Oct 17, 2022
a724cb5
EXSWHTEC-83 - Add return value for default branches in helper functions
music-dino Oct 17, 2022
fb9db79
Merge remote-tracking branch 'origin/hipMemAdvise_tests' into hipMemA…
music-dino Oct 17, 2022
7734178
EXSWHTEC-94 - Implement resource guards for arrays.
mirza-halilcevic Oct 18, 2022
25679d8
Merge remote-tracking branch 'upstream/develop' into utils
mirza-halilcevic Oct 18, 2022
1fd1cb0
EXSWHTEC-94 - Add hip_array_common.hh.
mirza-halilcevic Oct 18, 2022
fc3a107
EXSWHTEC-94 - Remove redundancies between hip_array_common.hh and
mirza-halilcevic Oct 18, 2022
781cee5
Merge remote-tracking branch 'upstream/develop' into hipMemAdvise_tests
music-dino Nov 2, 2022
3505989
Merge branch 'develop' into hipMemAdvise_tests
music-dino Nov 3, 2022
995d5c3
Merge remote-tracking branch 'upstream/develop' into utils
music-dino Nov 4, 2022
4e2fe8d
EXSWHTEC-94 - Fix loop counter types in PitchedMemoryVerify and Pitch…
music-dino Nov 4, 2022
bb16633
Merge remote-tracking branch 'origin/utils' into hipMemAdvise_tests
music-dino Nov 4, 2022
432e44a
Merge remote-tracking branch 'origin/hipMemAdvise_tests' into hipMemA…
music-dino Nov 4, 2022
53e0893
Merge remote-tracking branch 'upstream/develop' into hipMemAdvise_tests
music-dino Nov 7, 2022
c4def8e
EXSWHTEC-83 - Disable test that fail due to defects
music-dino Nov 7, 2022
a1a45a9
Merge remote-tracking branch 'upstream/develop' into hipMemAdvise_tests
music-dino Nov 7, 2022
e9ca295
Merge branch 'develop' into hipMemAdvise_tests
mangupta Nov 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"Unit_hipGetDeviceFlags_Positive_Context",
"Unit_hipIpcCloseMemHandle_Negative_Close_In_Originating_Process",
"Unit_hipIpcOpenMemHandle_Negative_Open_In_Creating_Process",
"Unit_hipDeviceGetPCIBusId_Negative_PartialFill"
"Unit_hipDeviceGetPCIBusId_Negative_PartialFill",
"Unit_hipMemAdvise_AccessedBy_All_Devices",
"Unit_hipMemAdvise_No_Flag_Interference"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
"Unit_hipIpcOpenMemHandle_Negative_Open_In_Creating_Process",
"Unit_hipDeviceGetPCIBusId_Negative_PartialFill",
"Unit_hipDeviceGetSharedMemConfig_Positive_Basic",
"Unit_hipDeviceGetSharedMemConfig_Positive_Threaded"
"Unit_hipDeviceGetSharedMemConfig_Positive_Threaded",
"Unit_hipMemAdvise_AccessedBy_All_Devices",
"Unit_hipMemAdvise_No_Flag_Interference"
]
}
84 changes: 84 additions & 0 deletions tests/catch/include/hip_array_common.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

#pragma once

#include <hip_test_common.hh>

template <class T, size_t N, hipArray_Format Format> struct type_and_size_and_format {
using type = T;
static constexpr size_t size = N;
static constexpr hipArray_Format format = Format;
};

// Create a map of type to scalar type, vector size and scalar type format enum.
// This is useful for creating simpler function that depend on the vector size.
template <typename T> struct vector_info;
template <>
struct vector_info<int> : type_and_size_and_format<int, 1, HIP_AD_FORMAT_SIGNED_INT32> {};
template <> struct vector_info<float> : type_and_size_and_format<float, 1, HIP_AD_FORMAT_FLOAT> {};
template <>
struct vector_info<short> : type_and_size_and_format<short, 1, HIP_AD_FORMAT_SIGNED_INT16> {};
template <>
struct vector_info<char> : type_and_size_and_format<char, 1, HIP_AD_FORMAT_SIGNED_INT8> {};
template <>
struct vector_info<unsigned int>
: type_and_size_and_format<unsigned int, 1, HIP_AD_FORMAT_UNSIGNED_INT32> {};
template <>
struct vector_info<unsigned short>
: type_and_size_and_format<unsigned short, 1, HIP_AD_FORMAT_UNSIGNED_INT16> {};
template <>
struct vector_info<unsigned char>
: type_and_size_and_format<unsigned char, 1, HIP_AD_FORMAT_UNSIGNED_INT8> {};

template <>
struct vector_info<int2> : type_and_size_and_format<int, 2, HIP_AD_FORMAT_SIGNED_INT32> {};
template <> struct vector_info<float2> : type_and_size_and_format<float, 2, HIP_AD_FORMAT_FLOAT> {};
template <>
struct vector_info<short2> : type_and_size_and_format<short, 2, HIP_AD_FORMAT_SIGNED_INT16> {};
template <>
struct vector_info<char2> : type_and_size_and_format<char, 2, HIP_AD_FORMAT_SIGNED_INT8> {};
template <>
struct vector_info<uint2>
: type_and_size_and_format<unsigned int, 2, HIP_AD_FORMAT_UNSIGNED_INT32> {};
template <>
struct vector_info<ushort2>
: type_and_size_and_format<unsigned short, 2, HIP_AD_FORMAT_UNSIGNED_INT16> {};
template <>
struct vector_info<uchar2>
: type_and_size_and_format<unsigned char, 2, HIP_AD_FORMAT_UNSIGNED_INT8> {};

template <>
struct vector_info<int4> : type_and_size_and_format<int, 4, HIP_AD_FORMAT_SIGNED_INT32> {};
template <> struct vector_info<float4> : type_and_size_and_format<float, 4, HIP_AD_FORMAT_FLOAT> {};
template <>
struct vector_info<short4> : type_and_size_and_format<short, 4, HIP_AD_FORMAT_SIGNED_INT16> {};
template <>
struct vector_info<char4> : type_and_size_and_format<char, 4, HIP_AD_FORMAT_SIGNED_INT8> {};
template <>
struct vector_info<uint4>
: type_and_size_and_format<unsigned int, 4, HIP_AD_FORMAT_UNSIGNED_INT32> {};
template <>
struct vector_info<ushort4>
: type_and_size_and_format<unsigned short, 4, HIP_AD_FORMAT_UNSIGNED_INT16> {};
template <>
struct vector_info<uchar4>
: type_and_size_and_format<unsigned char, 4, HIP_AD_FORMAT_UNSIGNED_INT8> {};
113 changes: 109 additions & 4 deletions tests/catch/include/resource_guards.hh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ THE SOFTWARE.

#pragma once

#include <hip_array_common.hh>
#include <hip_test_common.hh>
#include <hip/hip_runtime_api.h>

Expand Down Expand Up @@ -80,17 +81,121 @@ template <typename T> class LinearAllocGuard {
}
}

T* ptr() { return ptr_; };
T* const ptr() const { return ptr_; };
T* host_ptr() { return host_ptr_; }
T* const host_ptr() const { return host_ptr(); }
T* ptr() const { return ptr_; };
T* host_ptr() const { return host_ptr_; }

private:
const LinearAllocs allocation_type_;
T* ptr_ = nullptr;
T* host_ptr_ = nullptr;
};

template <typename T> class LinearAllocGuardMultiDim {
protected:
LinearAllocGuardMultiDim(hipExtent extent) : extent_{extent} {}

~LinearAllocGuardMultiDim() { static_cast<void>(hipFree(pitched_ptr_.ptr)); }

public:
T* ptr() const { return reinterpret_cast<T*>(pitched_ptr_.ptr); };

size_t pitch() const { return pitched_ptr_.pitch; }

hipExtent extent() const { return extent_; }

hipPitchedPtr pitched_ptr() const { return pitched_ptr_; }

size_t width() const { return extent_.width; }

size_t width_logical() const { return extent_.width / sizeof(T); }

size_t height() const { return extent_.height; }

public:
hipPitchedPtr pitched_ptr_;
const hipExtent extent_;
};

template <typename T> class LinearAllocGuard2D : public LinearAllocGuardMultiDim<T> {
public:
LinearAllocGuard2D(const size_t width_logical, const size_t height)
: LinearAllocGuardMultiDim<T>{make_hipExtent(width_logical * sizeof(T), height, 1)} {
HIP_CHECK(hipMallocPitch(&this->pitched_ptr_.ptr, &this->pitched_ptr_.pitch,
this->extent_.width, this->extent_.height));
}

LinearAllocGuard2D(const LinearAllocGuard2D&) = delete;
LinearAllocGuard2D(LinearAllocGuard2D&&) = delete;
};

template <typename T> class LinearAllocGuard3D : public LinearAllocGuardMultiDim<T> {
public:
LinearAllocGuard3D(const size_t width_logical, const size_t height, const size_t depth)
: LinearAllocGuardMultiDim<T>{make_hipExtent(width_logical * sizeof(T), height, depth)} {
HIP_CHECK(hipMalloc3D(&this->pitched_ptr_, this->extent_));
}

LinearAllocGuard3D(const hipExtent extent) : LinearAllocGuardMultiDim<T>(extent) {
HIP_CHECK(hipMalloc3D(&this->pitched_ptr_, this->extent_));
}

LinearAllocGuard3D(const LinearAllocGuard3D&) = delete;
LinearAllocGuard3D(LinearAllocGuard3D&&) = delete;

size_t depth() const { return this->extent_.depth; }
};

template <typename T> class ArrayAllocGuard {
public:
// extent should contain logical width
ArrayAllocGuard(const hipExtent extent, const unsigned int flags = 0u) : extent_{extent} {
hipChannelFormatDesc desc = hipCreateChannelDesc<T>();
HIP_CHECK(hipMalloc3DArray(&ptr_, &desc, extent_, flags));
}

~ArrayAllocGuard() { static_cast<void>(hipFreeArray(ptr_)); }

ArrayAllocGuard(const ArrayAllocGuard&) = delete;
ArrayAllocGuard(ArrayAllocGuard&&) = delete;

hipArray_t ptr() const { return ptr_; }

hipExtent extent() const { return extent_; }

private:
hipArray_t ptr_ = nullptr;
const hipExtent extent_;
};

template <typename T> class DrvArrayAllocGuard {
public:
// extent should contain width in bytes
DrvArrayAllocGuard(const hipExtent extent, const unsigned int flags = 0u) : extent_{extent} {
HIP_ARRAY3D_DESCRIPTOR desc{};
using vec_info = vector_info<T>;
desc.Format = vec_info::format;
desc.NumChannels = vec_info::size;
desc.Width = extent_.width / sizeof(T);
desc.Height = extent_.height;
desc.Depth = extent_.depth;
desc.Flags = flags;
HIP_CHECK(hipArray3DCreate(&ptr_, &desc));
}

~DrvArrayAllocGuard() { static_cast<void>(hipArrayDestroy(ptr_)); }

DrvArrayAllocGuard(const DrvArrayAllocGuard&) = delete;
DrvArrayAllocGuard(DrvArrayAllocGuard&&) = delete;

hiparray ptr() const { return ptr_; }

hipExtent extent() const { return extent_; }

private:
hiparray ptr_ = nullptr;
const hipExtent extent_;
};

enum class Streams { nullstream, perThread, created };

class StreamGuard {
Expand Down
43 changes: 43 additions & 0 deletions tests/catch/include/utils.hh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,37 @@ void ArrayFindIfNot(T* const array, const T expected_value, const size_t num_ele
ArrayFindIfNot(array, array + num_elements, expected_value);
}

template <typename T, typename F>
void PitchedMemoryVerify(T* const ptr, const size_t pitch, const size_t width, const size_t height,
const size_t depth, F expected_value_generator) {
for (size_t z = 0; z < depth; ++z) {
for (size_t y = 0; y < height; ++y) {
for (size_t x = 0; x < width; ++x) {
const auto slice = reinterpret_cast<uint8_t*>(ptr) + pitch * height * z;
const auto row = slice + pitch * y;
if (reinterpret_cast<T*>(row)[x] != expected_value_generator(x, y, z)) {
INFO("Mismatch at indices: " << x << ", " << y << ", " << z);
REQUIRE(reinterpret_cast<T*>(row)[x] == expected_value_generator(x, y, z));
}
}
}
}
}

template <typename T, typename F>
void PitchedMemorySet(T* const ptr, const size_t pitch, const size_t width, const size_t height,
const size_t depth, F expected_value_generator) {
for (size_t z = 0; z < depth; ++z) {
for (size_t y = 0; y < height; ++y) {
for (size_t x = 0; x < width; ++x) {
const auto slice = reinterpret_cast<uint8_t*>(ptr) + pitch * height * z;
const auto row = slice + pitch * y;
reinterpret_cast<T*>(row)[x] = expected_value_generator(x, y, z);
}
}
}
}

template <typename T>
__global__ void VectorIncrement(T* const vec, const T increment_value, size_t N) {
size_t offset = (blockIdx.x * blockDim.x + threadIdx.x);
Expand Down Expand Up @@ -82,6 +113,18 @@ static __global__ void Delay(uint32_t interval, const uint32_t ticks_per_ms) {
}
}

template <typename T>
__global__ void Iota(T* const out, size_t pitch, size_t w, size_t h, size_t d) {
const auto x = blockIdx.x * blockDim.x + threadIdx.x;
const auto y = blockIdx.y * blockDim.y + threadIdx.y;
const auto z = blockIdx.z * blockDim.z + threadIdx.z;
if (x < w && y < h && z < d) {
char* const slice = reinterpret_cast<char*>(out) + pitch * h * z;
char* const row = slice + pitch * y;
reinterpret_cast<T*>(row)[x] = z * w * h + y * w + x;
}
}

inline void LaunchDelayKernel(const std::chrono::milliseconds interval, const hipStream_t stream) {
int ticks_per_ms = 0;
// Clock rate is in kHz => number of clock ticks in a millisecond
Expand Down
2 changes: 2 additions & 0 deletions tests/catch/unit/memory/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ set(TEST_SRC
hipMemsetSync.cc
hipMemsetAsync.cc
hipMemAdvise.cc
hipMemAdvise_old.cc
hipMemRangeGetAttributes.cc
)
else()
Expand Down Expand Up @@ -171,6 +172,7 @@ set(TEST_SRC
hipMemsetSync.cc
hipMemsetAsync.cc
hipMemAdvise.cc
hipMemAdvise_old.cc
hipMemRangeGetAttributes.cc
)
endif()
Expand Down
1 change: 1 addition & 0 deletions tests/catch/unit/memory/hipArray3DCreate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ THE SOFTWARE.
#include <limits>
#include "DriverContext.hh"
#include "hipArrayCommon.hh"
#include "hip_array_common.hh"
#include "hip_test_common.hh"

namespace {
Expand Down
60 changes: 0 additions & 60 deletions tests/catch/unit/memory/hipArrayCommon.hh
Original file line number Diff line number Diff line change
Expand Up @@ -26,66 +26,6 @@ THE SOFTWARE.

constexpr size_t BlockSize = 16;

template <class T, size_t N, hipArray_Format Format> struct type_and_size_and_format {
using type = T;
static constexpr size_t size = N;
static constexpr hipArray_Format format = Format;
};

// Create a map of type to scalar type, vector size and scalar type format enum.
// This is useful for creating simpler function that depend on the vector size.
template <typename T> struct vector_info;
template <>
struct vector_info<int> : type_and_size_and_format<int, 1, HIP_AD_FORMAT_SIGNED_INT32> {};
template <> struct vector_info<float> : type_and_size_and_format<float, 1, HIP_AD_FORMAT_FLOAT> {};
template <>
struct vector_info<short> : type_and_size_and_format<short, 1, HIP_AD_FORMAT_SIGNED_INT16> {};
template <>
struct vector_info<char> : type_and_size_and_format<char, 1, HIP_AD_FORMAT_SIGNED_INT8> {};
template <>
struct vector_info<unsigned int>
: type_and_size_and_format<unsigned int, 1, HIP_AD_FORMAT_UNSIGNED_INT32> {};
template <>
struct vector_info<unsigned short>
: type_and_size_and_format<unsigned short, 1, HIP_AD_FORMAT_UNSIGNED_INT16> {};
template <>
struct vector_info<unsigned char>
: type_and_size_and_format<unsigned char, 1, HIP_AD_FORMAT_UNSIGNED_INT8> {};

template <>
struct vector_info<int2> : type_and_size_and_format<int, 2, HIP_AD_FORMAT_SIGNED_INT32> {};
template <> struct vector_info<float2> : type_and_size_and_format<float, 2, HIP_AD_FORMAT_FLOAT> {};
template <>
struct vector_info<short2> : type_and_size_and_format<short, 2, HIP_AD_FORMAT_SIGNED_INT16> {};
template <>
struct vector_info<char2> : type_and_size_and_format<char, 2, HIP_AD_FORMAT_SIGNED_INT8> {};
template <>
struct vector_info<uint2>
: type_and_size_and_format<unsigned int, 2, HIP_AD_FORMAT_UNSIGNED_INT32> {};
template <>
struct vector_info<ushort2>
: type_and_size_and_format<unsigned short, 2, HIP_AD_FORMAT_UNSIGNED_INT16> {};
template <>
struct vector_info<uchar2>
: type_and_size_and_format<unsigned char, 2, HIP_AD_FORMAT_UNSIGNED_INT8> {};

template <>
struct vector_info<int4> : type_and_size_and_format<int, 4, HIP_AD_FORMAT_SIGNED_INT32> {};
template <> struct vector_info<float4> : type_and_size_and_format<float, 4, HIP_AD_FORMAT_FLOAT> {};
template <>
struct vector_info<short4> : type_and_size_and_format<short, 4, HIP_AD_FORMAT_SIGNED_INT16> {};
template <>
struct vector_info<char4> : type_and_size_and_format<char, 4, HIP_AD_FORMAT_SIGNED_INT8> {};
template <>
struct vector_info<uint4>
: type_and_size_and_format<unsigned int, 4, HIP_AD_FORMAT_UNSIGNED_INT32> {};
template <>
struct vector_info<ushort4>
: type_and_size_and_format<unsigned short, 4, HIP_AD_FORMAT_UNSIGNED_INT16> {};
template <>
struct vector_info<uchar4>
: type_and_size_and_format<unsigned char, 4, HIP_AD_FORMAT_UNSIGNED_INT8> {};

// read from a texture using normalized coordinates
constexpr size_t ChannelToRead = 1;
template <typename T>
Expand Down
1 change: 1 addition & 0 deletions tests/catch/unit/memory/hipArrayCreate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ hipArrayCreate API test scenarios
#include <array>
#include <numeric>
#include <hip_test_common.hh>
#include <hip_array_common.hh>
#include "hipArrayCommon.hh"
#include "DriverContext.hh"

Expand Down
Loading