mirror of
https://github.com/Gericom/teak-llvm.git
synced 2025-06-19 19:45:40 -04:00

Summary: We were packing global device memory handles in `PackedKernelArgumentArray`, but as I was implementing the CUDA platform, I realized that CUDA wants the address of the handle, not the handle itself. So this patch switches to packing the address of the handle. Reviewers: jlebar Subscribers: jprice, jlebar, parallel_libs-commits Differential Revision: https://reviews.llvm.org/D24528 llvm-svn: 281424
151 lines
5.8 KiB
C++
151 lines
5.8 KiB
C++
//===-- PackedKernelArgumentArrayTest.cpp - tests for kernel arg packing --===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
///
|
|
/// \file
|
|
/// Unit tests for kernel argument packing.
|
|
///
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "streamexecutor/Device.h"
|
|
#include "streamexecutor/DeviceMemory.h"
|
|
#include "streamexecutor/PackedKernelArgumentArray.h"
|
|
#include "streamexecutor/PlatformDevice.h"
|
|
#include "streamexecutor/platforms/host/HostPlatformDevice.h"
|
|
|
|
#include "llvm/ADT/Twine.h"
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
namespace {
|
|
|
|
namespace se = ::streamexecutor;
|
|
|
|
using Type = se::KernelArgumentType;
|
|
|
|
// Test fixture class for testing argument packing.
|
|
//
|
|
// Basically defines a bunch of types to be packed so they don't have to be
|
|
// defined separately in each test.
|
|
class DeviceMemoryPackingTest : public ::testing::Test {
|
|
public:
|
|
DeviceMemoryPackingTest()
|
|
: Device(&PDevice), Value(42), Handle(&Value), ByteCount(15),
|
|
ElementCount(5),
|
|
TypedGlobal(getOrDie(Device.allocateDeviceMemory<int>(ElementCount))),
|
|
TypedShared(
|
|
se::SharedDeviceMemory<int>::makeFromElementCount(ElementCount)) {}
|
|
|
|
se::host::HostPlatformDevice PDevice;
|
|
se::Device Device;
|
|
int Value;
|
|
void *Handle;
|
|
size_t ByteCount;
|
|
size_t ElementCount;
|
|
se::GlobalDeviceMemory<int> TypedGlobal;
|
|
se::SharedDeviceMemory<int> TypedShared;
|
|
};
|
|
|
|
// Utility method to check the expected address, size, and type for a packed
|
|
// argument at the given index of a PackedKernelArgumentArray.
|
|
template <typename... ParameterTs>
|
|
static void
|
|
ExpectEqual(const void *ExpectedAddress, size_t ExpectedSize, Type ExpectedType,
|
|
const se::PackedKernelArgumentArray<ParameterTs...> &Observed,
|
|
size_t Index) {
|
|
SCOPED_TRACE(("Index = " + llvm::Twine(Index)).str());
|
|
EXPECT_EQ(ExpectedAddress, Observed.getAddress(Index));
|
|
EXPECT_EQ(ExpectedAddress, Observed.getAddresses()[Index]);
|
|
EXPECT_EQ(ExpectedSize, Observed.getSize(Index));
|
|
EXPECT_EQ(ExpectedSize, Observed.getSizes()[Index]);
|
|
EXPECT_EQ(ExpectedType, Observed.getType(Index));
|
|
EXPECT_EQ(ExpectedType, Observed.getTypes()[Index]);
|
|
}
|
|
|
|
TEST_F(DeviceMemoryPackingTest, SingleValue) {
|
|
auto Array = se::make_kernel_argument_pack(Value);
|
|
ExpectEqual(&Value, sizeof(Value), Type::VALUE, Array, 0);
|
|
EXPECT_EQ(1u, Array.getArgumentCount());
|
|
EXPECT_EQ(0u, Array.getSharedCount());
|
|
}
|
|
|
|
TEST_F(DeviceMemoryPackingTest, SingleTypedGlobal) {
|
|
auto Array = se::make_kernel_argument_pack(TypedGlobal);
|
|
ExpectEqual(TypedGlobal.getHandleAddress(), sizeof(void *),
|
|
Type::GLOBAL_DEVICE_MEMORY, Array, 0);
|
|
EXPECT_EQ(1u, Array.getArgumentCount());
|
|
EXPECT_EQ(0u, Array.getSharedCount());
|
|
}
|
|
|
|
TEST_F(DeviceMemoryPackingTest, SingleTypedGlobalPointer) {
|
|
auto Array = se::make_kernel_argument_pack(&TypedGlobal);
|
|
ExpectEqual(TypedGlobal.getHandleAddress(), sizeof(void *),
|
|
Type::GLOBAL_DEVICE_MEMORY, Array, 0);
|
|
EXPECT_EQ(1u, Array.getArgumentCount());
|
|
EXPECT_EQ(0u, Array.getSharedCount());
|
|
}
|
|
|
|
TEST_F(DeviceMemoryPackingTest, SingleConstTypedGlobalPointer) {
|
|
const se::GlobalDeviceMemory<int> *ArgumentPointer = &TypedGlobal;
|
|
auto Array = se::make_kernel_argument_pack(ArgumentPointer);
|
|
ExpectEqual(TypedGlobal.getHandleAddress(), sizeof(void *),
|
|
Type::GLOBAL_DEVICE_MEMORY, Array, 0);
|
|
EXPECT_EQ(1u, Array.getArgumentCount());
|
|
EXPECT_EQ(0u, Array.getSharedCount());
|
|
}
|
|
|
|
TEST_F(DeviceMemoryPackingTest, SingleTypedShared) {
|
|
auto Array = se::make_kernel_argument_pack(TypedShared);
|
|
ExpectEqual(nullptr, TypedShared.getByteCount(), Type::SHARED_DEVICE_MEMORY,
|
|
Array, 0);
|
|
EXPECT_EQ(1u, Array.getArgumentCount());
|
|
EXPECT_EQ(1u, Array.getSharedCount());
|
|
}
|
|
|
|
TEST_F(DeviceMemoryPackingTest, SingleTypedSharedPointer) {
|
|
auto Array = se::make_kernel_argument_pack(&TypedShared);
|
|
ExpectEqual(nullptr, TypedShared.getByteCount(), Type::SHARED_DEVICE_MEMORY,
|
|
Array, 0);
|
|
EXPECT_EQ(1u, Array.getArgumentCount());
|
|
EXPECT_EQ(1u, Array.getSharedCount());
|
|
}
|
|
|
|
TEST_F(DeviceMemoryPackingTest, SingleConstTypedSharedPointer) {
|
|
const se::SharedDeviceMemory<int> *ArgumentPointer = &TypedShared;
|
|
auto Array = se::make_kernel_argument_pack(ArgumentPointer);
|
|
ExpectEqual(nullptr, TypedShared.getByteCount(), Type::SHARED_DEVICE_MEMORY,
|
|
Array, 0);
|
|
EXPECT_EQ(1u, Array.getArgumentCount());
|
|
EXPECT_EQ(1u, Array.getSharedCount());
|
|
}
|
|
|
|
TEST_F(DeviceMemoryPackingTest, PackSeveralArguments) {
|
|
const se::GlobalDeviceMemory<int> *TypedGlobalPointer = &TypedGlobal;
|
|
const se::SharedDeviceMemory<int> *TypedSharedPointer = &TypedShared;
|
|
auto Array = se::make_kernel_argument_pack(Value, TypedGlobal, &TypedGlobal,
|
|
TypedGlobalPointer, TypedShared,
|
|
&TypedShared, TypedSharedPointer);
|
|
ExpectEqual(&Value, sizeof(Value), Type::VALUE, Array, 0);
|
|
ExpectEqual(TypedGlobal.getHandleAddress(), sizeof(void *),
|
|
Type::GLOBAL_DEVICE_MEMORY, Array, 1);
|
|
ExpectEqual(TypedGlobal.getHandleAddress(), sizeof(void *),
|
|
Type::GLOBAL_DEVICE_MEMORY, Array, 2);
|
|
ExpectEqual(TypedGlobal.getHandleAddress(), sizeof(void *),
|
|
Type::GLOBAL_DEVICE_MEMORY, Array, 3);
|
|
ExpectEqual(nullptr, TypedShared.getByteCount(), Type::SHARED_DEVICE_MEMORY,
|
|
Array, 4);
|
|
ExpectEqual(nullptr, TypedShared.getByteCount(), Type::SHARED_DEVICE_MEMORY,
|
|
Array, 5);
|
|
ExpectEqual(nullptr, TypedShared.getByteCount(), Type::SHARED_DEVICE_MEMORY,
|
|
Array, 6);
|
|
EXPECT_EQ(7u, Array.getArgumentCount());
|
|
EXPECT_EQ(3u, Array.getSharedCount());
|
|
}
|
|
|
|
} // namespace
|