--- /dev/null
+Checks: '-*,clang-diagnostic-*,llvm-*,misc-*,-misc-unused-parameters,readability-identifier-naming'
+CheckOptions:
+ - key: readability-identifier-naming.ClassCase
+ value: CamelCase
+ - key: readability-identifier-naming.EnumCase
+ value: CamelCase
+ - key: readability-identifier-naming.FunctionCase
+ value: lowerCase
+ - key: readability-identifier-naming.MemberCase
+ value: CamelCase
+ - key: readability-identifier-naming.ParameterCase
+ value: CamelCase
+ - key: readability-identifier-naming.UnionCase
+ value: CamelCase
+ - key: readability-identifier-naming.VariableCase
+ value: CamelCase
+
KernelT>::type>
createKernel(const MultiKernelLoaderSpec &Spec) {
Expected<const void *> MaybeKernelHandle = PDevice->createKernel(Spec);
- if (!MaybeKernelHandle) {
+ if (!MaybeKernelHandle)
return MaybeKernelHandle.takeError();
- }
return KernelT(PDevice, *MaybeKernelHandle, Spec.getKernelName());
}
Expected<RegisteredHostMemory<T>>
registerHostMemory(llvm::MutableArrayRef<T> Memory) {
if (Error E = PDevice->registerHostMemory(Memory.data(),
- Memory.size() * sizeof(T))) {
+ Memory.size() * sizeof(T)))
return std::move(E);
- }
return RegisteredHostMemory<T>(this, Memory.data(), Memory.size());
}
: TheDevice(D), Handle(Handle), ByteCount(ByteCount) {}
/// Transfer ownership of the underlying handle.
- GlobalDeviceMemoryBase(GlobalDeviceMemoryBase &&Other)
+ GlobalDeviceMemoryBase(GlobalDeviceMemoryBase &&Other) noexcept
: TheDevice(Other.TheDevice), Handle(Other.Handle),
ByteCount(Other.ByteCount) {
Other.TheDevice = nullptr;
Other.ByteCount = 0;
}
- GlobalDeviceMemoryBase &operator=(GlobalDeviceMemoryBase &&Other) {
+ GlobalDeviceMemoryBase &operator=(GlobalDeviceMemoryBase &&Other) noexcept {
TheDevice = Other.TheDevice;
Handle = Other.Handle;
ByteCount = Other.ByteCount;
public:
using ElementTy = ElemT;
- GlobalDeviceMemory(GlobalDeviceMemory &&Other) = default;
- GlobalDeviceMemory &operator=(GlobalDeviceMemory &&Other) = default;
+ GlobalDeviceMemory(GlobalDeviceMemory &&) noexcept;
+ GlobalDeviceMemory &operator=(GlobalDeviceMemory &&) noexcept;
/// Returns the number of elements of type ElemT that constitute this
/// allocation.
: GlobalDeviceMemoryBase(D, Handle, ElementCount * sizeof(ElemT)) {}
};
+template <typename ElemT>
+GlobalDeviceMemory<ElemT>::GlobalDeviceMemory(
+ GlobalDeviceMemory<ElemT> &&) noexcept = default;
+
+template <typename ElemT>
+GlobalDeviceMemory<ElemT> &GlobalDeviceMemory<ElemT>::
+operator=(GlobalDeviceMemory<ElemT> &&) noexcept = default;
+
/// A class to represent the size of a dynamic shared memory buffer of elements
/// of type T on a device.
///
using llvm::Twine;
/// Makes an Error object from an error message.
-Error make_error(Twine Message);
+Error make_error(const Twine &Message);
/// Consumes the input error and returns its error message.
///
RegisteredHostMemory(const RegisteredHostMemory &) = delete;
RegisteredHostMemory &operator=(const RegisteredHostMemory &) = delete;
- RegisteredHostMemory(RegisteredHostMemory &&Other)
+ RegisteredHostMemory(RegisteredHostMemory &&Other) noexcept
: TheDevice(Other.TheDevice), Pointer(Other.Pointer),
ElementCount(Other.ElementCount) {
Other.TheDevice = nullptr;
Other.Pointer = nullptr;
}
- RegisteredHostMemory &operator=(RegisteredHostMemory &&Other) {
+ RegisteredHostMemory &operator=(RegisteredHostMemory &&Other) noexcept {
TheDevice = Other.TheDevice;
Pointer = Other.Pointer;
ElementCount = Other.ElementCount;
KernelBase(const KernelBase &Other) = delete;
KernelBase &operator=(const KernelBase &Other) = delete;
- KernelBase(KernelBase &&Other);
- KernelBase &operator=(KernelBase &&Other);
+ KernelBase(KernelBase &&Other) noexcept;
+ KernelBase &operator=(KernelBase &&Other) noexcept;
~KernelBase();
llvm::StringRef Name)
: KernelBase(D, PlatformKernelHandle, Name) {}
- Kernel(Kernel &&Other) = default;
- Kernel &operator=(Kernel &&Other) = default;
+ Kernel(Kernel &&Other) noexcept;
+ Kernel &operator=(Kernel &&Other) noexcept;
};
+template <typename... ParameterTs>
+Kernel<ParameterTs...>::Kernel(Kernel<ParameterTs...> &&) noexcept = default;
+
+template <typename... ParameterTs>
+Kernel<ParameterTs...> &Kernel<ParameterTs...>::
+operator=(Kernel<ParameterTs...> &&) noexcept = default;
+
} // namespace streamexecutor
#endif // STREAMEXECUTOR_KERNEL_H
class MultiKernelLoaderSpec {
public:
std::string getKernelName() const {
- if (TheKernelName) {
+ if (TheKernelName)
return *TheKernelName;
- }
return "";
}
Stream(const Stream &Other) = delete;
Stream &operator=(const Stream &Other) = delete;
- Stream(Stream &&Other);
- Stream &operator=(Stream &&Other);
+ Stream(Stream &&Other) noexcept;
+ Stream &operator=(Stream &&Other) noexcept;
~Stream();
/// Sets the error state from an error message.
///
/// Does not overwrite the error if it is already set.
- void setError(llvm::Twine Message) {
+ void setError(const llvm::Twine &Message) {
llvm::sys::ScopedWriter WriterLock(*ErrorMessageMutex);
if (!ErrorMessage)
ErrorMessage = Message.str();
--- /dev/null
+//===-- SimpleHostPlatformDevice.h - Host device for testing ----*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// The SimpleHostPlatformDevice class is a streamexecutor::PlatformDevice that
+/// is really just the host processor and memory. It is useful for testing
+/// because no extra device platform is required.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef STREAMEXECUTOR_UNITTESTS_CORETESTS_SIMPLEHOSTPLATFORMDEVICE_H
+#define STREAMEXECUTOR_UNITTESTS_CORETESTS_SIMPLEHOSTPLATFORMDEVICE_H
+
+#include <cstdlib>
+#include <cstring>
+
+#include "streamexecutor/PlatformDevice.h"
+
+namespace streamexecutor {
+namespace test {
+
+/// A streamexecutor::PlatformDevice that simply forwards all operations to the
+/// host platform.
+///
+/// The allocate and copy methods are simple wrappers for std::malloc and
+/// std::memcpy.
+class SimpleHostPlatformDevice : public streamexecutor::PlatformDevice {
+public:
+ std::string getName() const override { return "SimpleHostPlatformDevice"; }
+
+ streamexecutor::Expected<const void *> createStream() override {
+ return nullptr;
+ }
+
+ streamexecutor::Expected<void *>
+ allocateDeviceMemory(size_t ByteCount) override {
+ return std::malloc(ByteCount);
+ }
+
+ streamexecutor::Error freeDeviceMemory(const void *Handle) override {
+ std::free(const_cast<void *>(Handle));
+ return streamexecutor::Error::success();
+ }
+
+ streamexecutor::Error registerHostMemory(void *Memory,
+ size_t ByteCount) override {
+ return streamexecutor::Error::success();
+ }
+
+ streamexecutor::Error unregisterHostMemory(const void *Memory) override {
+ return streamexecutor::Error::success();
+ }
+
+ streamexecutor::Error copyD2H(const void *StreamHandle,
+ const void *DeviceHandleSrc,
+ size_t SrcByteOffset, void *HostDst,
+ size_t DstByteOffset,
+ size_t ByteCount) override {
+ std::memcpy(static_cast<char *>(HostDst) + DstByteOffset,
+ static_cast<const char *>(DeviceHandleSrc) + SrcByteOffset,
+ ByteCount);
+ return streamexecutor::Error::success();
+ }
+
+ streamexecutor::Error copyH2D(const void *StreamHandle, const void *HostSrc,
+ size_t SrcByteOffset,
+ const void *DeviceHandleDst,
+ size_t DstByteOffset,
+ size_t ByteCount) override {
+ std::memcpy(static_cast<char *>(const_cast<void *>(DeviceHandleDst)) +
+ DstByteOffset,
+ static_cast<const char *>(HostSrc) + SrcByteOffset, ByteCount);
+ return streamexecutor::Error::success();
+ }
+
+ streamexecutor::Error
+ copyD2D(const void *StreamHandle, const void *DeviceHandleSrc,
+ size_t SrcByteOffset, const void *DeviceHandleDst,
+ size_t DstByteOffset, size_t ByteCount) override {
+ std::memcpy(static_cast<char *>(const_cast<void *>(DeviceHandleDst)) +
+ DstByteOffset,
+ static_cast<const char *>(DeviceHandleSrc) + SrcByteOffset,
+ ByteCount);
+ return streamexecutor::Error::success();
+ }
+
+ streamexecutor::Error synchronousCopyD2H(const void *DeviceHandleSrc,
+ size_t SrcByteOffset, void *HostDst,
+ size_t DstByteOffset,
+ size_t ByteCount) override {
+ std::memcpy(static_cast<char *>(HostDst) + DstByteOffset,
+ static_cast<const char *>(DeviceHandleSrc) + SrcByteOffset,
+ ByteCount);
+ return streamexecutor::Error::success();
+ }
+
+ streamexecutor::Error synchronousCopyH2D(const void *HostSrc,
+ size_t SrcByteOffset,
+ const void *DeviceHandleDst,
+ size_t DstByteOffset,
+ size_t ByteCount) override {
+ std::memcpy(static_cast<char *>(const_cast<void *>(DeviceHandleDst)) +
+ DstByteOffset,
+ static_cast<const char *>(HostSrc) + SrcByteOffset, ByteCount);
+ return streamexecutor::Error::success();
+ }
+
+ streamexecutor::Error synchronousCopyD2D(const void *DeviceHandleSrc,
+ size_t SrcByteOffset,
+ const void *DeviceHandleDst,
+ size_t DstByteOffset,
+ size_t ByteCount) override {
+ std::memcpy(static_cast<char *>(const_cast<void *>(DeviceHandleDst)) +
+ DstByteOffset,
+ static_cast<const char *>(DeviceHandleSrc) + SrcByteOffset,
+ ByteCount);
+ return streamexecutor::Error::success();
+ }
+
+ /// Gets the value at the given index from a GlobalDeviceMemory<T> instance
+ /// created by this class.
+ template <typename T>
+ static T getDeviceValue(const streamexecutor::GlobalDeviceMemory<T> &Memory,
+ size_t Index) {
+ return static_cast<const T *>(Memory.getHandle())[Index];
+ }
+};
+
+} // namespace test
+} // namespace streamexecutor
+
+#endif // STREAMEXECUTOR_UNITTESTS_CORETESTS_SIMPLEHOSTPLATFORMDEVICE_H
Expected<Stream> Device::createStream() {
Expected<const void *> MaybePlatformStream = PDevice->createStream();
- if (!MaybePlatformStream) {
+ if (!MaybePlatformStream)
return MaybePlatformStream.takeError();
- }
return Stream(PDevice, *MaybePlatformStream);
}
namespace streamexecutor {
GlobalDeviceMemoryBase::~GlobalDeviceMemoryBase() {
- if (Handle) {
+ if (Handle)
// TODO(jhen): How to handle errors here.
consumeError(TheDevice->freeDeviceMemory(*this));
- }
}
} // namespace streamexecutor
namespace streamexecutor {
-Error make_error(Twine Message) {
+Error make_error(const Twine &Message) {
return llvm::make_error<StreamExecutorError>(Message.str());
}
std::string consumeAndGetMessage(Error &&E) {
- if (!E) {
+ if (!E)
return "success";
- }
std::string Message;
llvm::handleAllErrors(std::move(E),
[&Message](const StreamExecutorError &SEE) {
void destroyRegisteredHostMemoryInternals(Device *TheDevice, void *Pointer) {
// TODO(jhen): How to handle errors here?
- if (Pointer) {
+ if (Pointer)
consumeError(TheDevice->unregisterHostMemory(Pointer));
- }
}
} // namespace internal
"cannot construct a kernel object with a null platform kernel handle");
}
-KernelBase::KernelBase(KernelBase &&Other)
+KernelBase::KernelBase(KernelBase &&Other) noexcept
: PDevice(Other.PDevice), PlatformKernelHandle(Other.PlatformKernelHandle),
Name(std::move(Other.Name)),
DemangledName(std::move(Other.DemangledName)) {
Other.PlatformKernelHandle = nullptr;
}
-KernelBase &KernelBase::operator=(KernelBase &&Other) {
+KernelBase &KernelBase::operator=(KernelBase &&Other) noexcept {
PDevice = Other.PDevice;
PlatformKernelHandle = Other.PlatformKernelHandle;
Name = std::move(Other.Name);
llvm::StringRef KernelName,
const llvm::ArrayRef<CUDAPTXInMemorySpec::PTXSpec> SpecList)
: KernelLoaderSpec(KernelName) {
- for (const auto &Spec : SpecList) {
+ for (const auto &Spec : SpecList)
PTXByComputeCapability.emplace(Spec.TheComputeCapability, Spec.PTXCode);
- }
}
const char *CUDAPTXInMemorySpec::getCode(int ComputeCapabilityMajor,
auto PTXIter =
PTXByComputeCapability.find(CUDAPTXInMemorySpec::ComputeCapability{
ComputeCapabilityMajor, ComputeCapabilityMinor});
- if (PTXIter == PTXByComputeCapability.end()) {
+ if (PTXIter == PTXByComputeCapability.end())
return nullptr;
- }
return PTXIter->second;
}
: KernelLoaderSpec(KernelName), Text(Text) {}
void MultiKernelLoaderSpec::setKernelName(llvm::StringRef KernelName) {
- if (TheKernelName) {
+ if (TheKernelName)
assert(KernelName.equals(*TheKernelName) &&
"different kernel names in one MultiKernelLoaderSpec");
- } else {
+ else
TheKernelName = llvm::make_unique<std::string>(KernelName);
- }
}
MultiKernelLoaderSpec &MultiKernelLoaderSpec::addCUDAPTXInMemory(
"cannot construct a stream object with a null platform stream handle");
}
-Stream::Stream(Stream &&Other)
+Stream::Stream(Stream &&Other) noexcept
: PDevice(Other.PDevice), PlatformStreamHandle(Other.PlatformStreamHandle),
ErrorMessageMutex(std::move(Other.ErrorMessageMutex)),
ErrorMessage(std::move(Other.ErrorMessage)) {
Other.PlatformStreamHandle = nullptr;
}
-Stream &Stream::operator=(Stream &&Other) {
+Stream &Stream::operator=(Stream &&Other) noexcept {
PDevice = Other.PDevice;
PlatformStreamHandle = Other.PlatformStreamHandle;
ErrorMessageMutex = std::move(Other.ErrorMessageMutex);
#include <cstdlib>
#include <cstring>
-#include "SimpleHostPlatformDevice.h"
#include "streamexecutor/Device.h"
#include "streamexecutor/PlatformDevice.h"
+#include "streamexecutor/unittests/CoreTests/SimpleHostPlatformDevice.h"
#include "gtest/gtest.h"
TEST_F(DeviceTest, SyncCopyD2HToMutableArrayRefByCount) {
EXPECT_NO_ERROR(
Device.synchronousCopyD2H(DeviceA5, MutableArrayRef<int>(Host5), 5));
- for (int I = 0; I < 5; ++I) {
+ for (int I = 0; I < 5; ++I)
EXPECT_EQ(HostA5[I], Host5[I]);
- }
EXPECT_NO_ERROR(
Device.synchronousCopyD2H(DeviceB5, MutableArrayRef<int>(Host5), 2));
- for (int I = 0; I < 2; ++I) {
+ for (int I = 0; I < 2; ++I)
EXPECT_EQ(HostB5[I], Host5[I]);
- }
EXPECT_ERROR(
Device.synchronousCopyD2H(DeviceA7, MutableArrayRef<int>(Host5), 7));
TEST_F(DeviceTest, SyncCopyD2HToMutableArrayRef) {
EXPECT_NO_ERROR(
Device.synchronousCopyD2H(DeviceA5, MutableArrayRef<int>(Host5)));
- for (int I = 0; I < 5; ++I) {
+ for (int I = 0; I < 5; ++I)
EXPECT_EQ(HostA5[I], Host5[I]);
- }
EXPECT_ERROR(
Device.synchronousCopyD2H(DeviceA7, MutableArrayRef<int>(Host5)));
TEST_F(DeviceTest, SyncCopyD2HToPointer) {
EXPECT_NO_ERROR(Device.synchronousCopyD2H(DeviceA5, Host5, 5));
- for (int I = 0; I < 5; ++I) {
+ for (int I = 0; I < 5; ++I)
EXPECT_EQ(HostA5[I], Host5[I]);
- }
EXPECT_ERROR(Device.synchronousCopyD2H(DeviceA5, Host7, 7));
}
TEST_F(DeviceTest, SyncCopyD2HSliceToMutableArrayRefByCount) {
EXPECT_NO_ERROR(Device.synchronousCopyD2H(
DeviceA5.asSlice().slice(1), MutableArrayRef<int>(Host5 + 1, 4), 4));
- for (int I = 1; I < 5; ++I) {
+ for (int I = 1; I < 5; ++I)
EXPECT_EQ(HostA5[I], Host5[I]);
- }
EXPECT_NO_ERROR(Device.synchronousCopyD2H(DeviceB5.asSlice().drop_back(1),
MutableArrayRef<int>(Host5), 2));
- for (int I = 0; I < 2; ++I) {
+ for (int I = 0; I < 2; ++I)
EXPECT_EQ(HostB5[I], Host5[I]);
- }
EXPECT_ERROR(Device.synchronousCopyD2H(DeviceA7.asSlice(),
MutableArrayRef<int>(Host5), 7));
TEST_F(DeviceTest, SyncCopyD2HSliceToMutableArrayRef) {
EXPECT_NO_ERROR(Device.synchronousCopyD2H(DeviceA7.asSlice().slice(1, 5),
MutableArrayRef<int>(Host5)));
- for (int I = 0; I < 5; ++I) {
+ for (int I = 0; I < 5; ++I)
EXPECT_EQ(HostA7[I + 1], Host5[I]);
- }
EXPECT_ERROR(Device.synchronousCopyD2H(DeviceA7.asSlice().drop_back(1),
MutableArrayRef<int>(Host5)));
TEST_F(DeviceTest, SyncCopyD2HSliceToPointer) {
EXPECT_NO_ERROR(
Device.synchronousCopyD2H(DeviceA5.asSlice().slice(1), Host5 + 1, 4));
- for (int I = 1; I < 5; ++I) {
+ for (int I = 1; I < 5; ++I)
EXPECT_EQ(HostA5[I], Host5[I]);
- }
EXPECT_ERROR(Device.synchronousCopyD2H(DeviceA5.asSlice(), Host7, 7));
}
TEST_F(DeviceTest, SyncCopyH2DToArrayRefByCount) {
EXPECT_NO_ERROR(Device.synchronousCopyH2D(ArrayRef<int>(Host5), DeviceA5, 5));
- for (int I = 0; I < 5; ++I) {
+ for (int I = 0; I < 5; ++I)
EXPECT_EQ(getDeviceValue(DeviceA5, I), Host5[I]);
- }
EXPECT_NO_ERROR(Device.synchronousCopyH2D(ArrayRef<int>(Host5), DeviceB5, 2));
- for (int I = 0; I < 2; ++I) {
+ for (int I = 0; I < 2; ++I)
EXPECT_EQ(getDeviceValue(DeviceB5, I), Host5[I]);
- }
EXPECT_ERROR(Device.synchronousCopyH2D(ArrayRef<int>(Host7), DeviceA5, 7));
TEST_F(DeviceTest, SyncCopyH2DToArrayRef) {
EXPECT_NO_ERROR(Device.synchronousCopyH2D(ArrayRef<int>(Host5), DeviceA5));
- for (int I = 0; I < 5; ++I) {
+ for (int I = 0; I < 5; ++I)
EXPECT_EQ(getDeviceValue(DeviceA5, I), Host5[I]);
- }
EXPECT_ERROR(Device.synchronousCopyH2D(ArrayRef<int>(Host5), DeviceA7));
TEST_F(DeviceTest, SyncCopyH2DToPointer) {
EXPECT_NO_ERROR(Device.synchronousCopyH2D(Host5, DeviceA5, 5));
- for (int I = 0; I < 5; ++I) {
+ for (int I = 0; I < 5; ++I)
EXPECT_EQ(getDeviceValue(DeviceA5, I), Host5[I]);
- }
EXPECT_ERROR(Device.synchronousCopyH2D(Host7, DeviceA5, 7));
}
TEST_F(DeviceTest, SyncCopyH2DSliceToArrayRefByCount) {
EXPECT_NO_ERROR(Device.synchronousCopyH2D(ArrayRef<int>(Host5 + 1, 4),
DeviceA5.asSlice().slice(1), 4));
- for (int I = 1; I < 5; ++I) {
+ for (int I = 1; I < 5; ++I)
EXPECT_EQ(getDeviceValue(DeviceA5, I), Host5[I]);
- }
EXPECT_NO_ERROR(Device.synchronousCopyH2D(
ArrayRef<int>(Host5), DeviceB5.asSlice().drop_back(1), 2));
- for (int I = 0; I < 2; ++I) {
+ for (int I = 0; I < 2; ++I)
EXPECT_EQ(getDeviceValue(DeviceB5, I), Host5[I]);
- }
EXPECT_ERROR(
Device.synchronousCopyH2D(ArrayRef<int>(Host7), DeviceA5.asSlice(), 7));
TEST_F(DeviceTest, SyncCopyH2DSliceToArrayRef) {
EXPECT_NO_ERROR(
Device.synchronousCopyH2D(ArrayRef<int>(Host5), DeviceA5.asSlice()));
- for (int I = 0; I < 5; ++I) {
+ for (int I = 0; I < 5; ++I)
EXPECT_EQ(getDeviceValue(DeviceA5, I), Host5[I]);
- }
EXPECT_ERROR(
Device.synchronousCopyH2D(ArrayRef<int>(Host5), DeviceA7.asSlice()));
TEST_F(DeviceTest, SyncCopyH2DSliceToPointer) {
EXPECT_NO_ERROR(Device.synchronousCopyH2D(Host5, DeviceA5.asSlice(), 5));
- for (int I = 0; I < 5; ++I) {
+ for (int I = 0; I < 5; ++I)
EXPECT_EQ(getDeviceValue(DeviceA5, I), Host5[I]);
- }
EXPECT_ERROR(Device.synchronousCopyH2D(Host7, DeviceA5.asSlice(), 7));
}
TEST_F(DeviceTest, SyncCopyD2DByCount) {
EXPECT_NO_ERROR(Device.synchronousCopyD2D(DeviceA5, DeviceB5, 5));
- for (int I = 0; I < 5; ++I) {
+ for (int I = 0; I < 5; ++I)
EXPECT_EQ(getDeviceValue(DeviceA5, I), getDeviceValue(DeviceB5, I));
- }
EXPECT_NO_ERROR(Device.synchronousCopyD2D(DeviceA7, DeviceB7, 2));
- for (int I = 0; I < 2; ++I) {
+ for (int I = 0; I < 2; ++I)
EXPECT_EQ(getDeviceValue(DeviceA7, I), getDeviceValue(DeviceB7, I));
- }
EXPECT_ERROR(Device.synchronousCopyD2D(DeviceA5, DeviceB5, 7));
TEST_F(DeviceTest, SyncCopyD2D) {
EXPECT_NO_ERROR(Device.synchronousCopyD2D(DeviceA5, DeviceB5));
- for (int I = 0; I < 5; ++I) {
+ for (int I = 0; I < 5; ++I)
EXPECT_EQ(getDeviceValue(DeviceA5, I), getDeviceValue(DeviceB5, I));
- }
EXPECT_ERROR(Device.synchronousCopyD2D(DeviceA7, DeviceB5));
TEST_F(DeviceTest, SyncCopySliceD2DByCount) {
EXPECT_NO_ERROR(
Device.synchronousCopyD2D(DeviceA5.asSlice().slice(1), DeviceB5, 4));
- for (int I = 0; I < 4; ++I) {
+ for (int I = 0; I < 4; ++I)
EXPECT_EQ(getDeviceValue(DeviceA5, I + 1), getDeviceValue(DeviceB5, I));
- }
EXPECT_NO_ERROR(
Device.synchronousCopyD2D(DeviceA7.asSlice().drop_back(1), DeviceB7, 2));
- for (int I = 0; I < 2; ++I) {
+ for (int I = 0; I < 2; ++I)
EXPECT_EQ(getDeviceValue(DeviceA7, I), getDeviceValue(DeviceB7, I));
- }
EXPECT_ERROR(Device.synchronousCopyD2D(DeviceA5.asSlice(), DeviceB5, 7));
TEST_F(DeviceTest, SyncCopySliceD2D) {
EXPECT_NO_ERROR(
Device.synchronousCopyD2D(DeviceA7.asSlice().drop_back(2), DeviceB5));
- for (int I = 0; I < 5; ++I) {
+ for (int I = 0; I < 5; ++I)
EXPECT_EQ(getDeviceValue(DeviceA7, I), getDeviceValue(DeviceB5, I));
- }
EXPECT_ERROR(
Device.synchronousCopyD2D(DeviceA7.asSlice().slice(1), DeviceB5));
TEST_F(DeviceTest, SyncCopyD2DSliceByCount) {
EXPECT_NO_ERROR(
Device.synchronousCopyD2D(DeviceA5, DeviceB7.asSlice().slice(2), 5));
- for (int I = 0; I < 5; ++I) {
+ for (int I = 0; I < 5; ++I)
EXPECT_EQ(getDeviceValue(DeviceA5, I), getDeviceValue(DeviceB7, I + 2));
- }
EXPECT_NO_ERROR(
Device.synchronousCopyD2D(DeviceA7, DeviceB7.asSlice().drop_back(3), 2));
- for (int I = 0; I < 2; ++I) {
+ for (int I = 0; I < 2; ++I)
EXPECT_EQ(getDeviceValue(DeviceA7, I), getDeviceValue(DeviceB7, I));
- }
EXPECT_ERROR(Device.synchronousCopyD2D(DeviceA5, DeviceB5.asSlice(), 7));
TEST_F(DeviceTest, SyncCopyD2DSlice) {
EXPECT_NO_ERROR(
Device.synchronousCopyD2D(DeviceA5, DeviceB7.asSlice().drop_back(2)));
- for (int I = 0; I < 5; ++I) {
+ for (int I = 0; I < 5; ++I)
EXPECT_EQ(getDeviceValue(DeviceA5, I), getDeviceValue(DeviceB7, I));
- }
EXPECT_ERROR(Device.synchronousCopyD2D(DeviceA7, DeviceB5.asSlice()));
TEST_F(DeviceTest, SyncCopySliceD2DSliceByCount) {
EXPECT_NO_ERROR(
Device.synchronousCopyD2D(DeviceA5.asSlice(), DeviceB5.asSlice(), 5));
- for (int I = 0; I < 5; ++I) {
+ for (int I = 0; I < 5; ++I)
EXPECT_EQ(getDeviceValue(DeviceA5, I), getDeviceValue(DeviceB5, I));
- }
EXPECT_NO_ERROR(
Device.synchronousCopyD2D(DeviceA7.asSlice(), DeviceB7.asSlice(), 2));
- for (int I = 0; I < 2; ++I) {
+ for (int I = 0; I < 2; ++I)
EXPECT_EQ(getDeviceValue(DeviceA7, I), getDeviceValue(DeviceB7, I));
- }
EXPECT_ERROR(
Device.synchronousCopyD2D(DeviceA5.asSlice(), DeviceB5.asSlice(), 7));
TEST_F(DeviceTest, SyncCopySliceD2DSlice) {
EXPECT_NO_ERROR(
Device.synchronousCopyD2D(DeviceA5.asSlice(), DeviceB5.asSlice()));
- for (int I = 0; I < 5; ++I) {
+ for (int I = 0; I < 5; ++I)
EXPECT_EQ(getDeviceValue(DeviceA5, I), getDeviceValue(DeviceB5, I));
- }
EXPECT_ERROR(
Device.synchronousCopyD2D(DeviceA7.asSlice(), DeviceB5.asSlice()));
///
//===----------------------------------------------------------------------===//
-#include "SimpleHostPlatformDevice.h"
#include "streamexecutor/Device.h"
#include "streamexecutor/DeviceMemory.h"
#include "streamexecutor/PackedKernelArgumentArray.h"
#include "streamexecutor/PlatformDevice.h"
+#include "streamexecutor/unittests/CoreTests/SimpleHostPlatformDevice.h"
#include "llvm/ADT/Twine.h"
+++ /dev/null
-//===-- SimpleHostPlatformDevice.h - Host device for testing ----*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-///
-/// \file
-/// The SimpleHostPlatformDevice class is a streamexecutor::PlatformDevice that
-/// is really just the host processor and memory. It is useful for testing
-/// because no extra device platform is required.
-///
-//===----------------------------------------------------------------------===//
-
-#ifndef STREAMEXECUTOR_LIB_UNITTESTS_SIMPLEHOSTPLATFORMDEVICE_H
-#define STREAMEXECUTOR_LIB_UNITTESTS_SIMPLEHOSTPLATFORMDEVICE_H
-
-#include <cstdlib>
-#include <cstring>
-
-#include "streamexecutor/PlatformDevice.h"
-
-namespace streamexecutor {
-namespace test {
-
-/// A streamexecutor::PlatformDevice that simply forwards all operations to the
-/// host platform.
-///
-/// The allocate and copy methods are simple wrappers for std::malloc and
-/// std::memcpy.
-class SimpleHostPlatformDevice : public streamexecutor::PlatformDevice {
-public:
- std::string getName() const override { return "SimpleHostPlatformDevice"; }
-
- streamexecutor::Expected<const void *> createStream() override {
- return nullptr;
- }
-
- streamexecutor::Expected<void *>
- allocateDeviceMemory(size_t ByteCount) override {
- return std::malloc(ByteCount);
- }
-
- streamexecutor::Error freeDeviceMemory(const void *Handle) override {
- std::free(const_cast<void *>(Handle));
- return streamexecutor::Error::success();
- }
-
- streamexecutor::Error registerHostMemory(void *Memory,
- size_t ByteCount) override {
- return streamexecutor::Error::success();
- }
-
- streamexecutor::Error unregisterHostMemory(const void *Memory) override {
- return streamexecutor::Error::success();
- }
-
- streamexecutor::Error copyD2H(const void *StreamHandle,
- const void *DeviceHandleSrc,
- size_t SrcByteOffset, void *HostDst,
- size_t DstByteOffset,
- size_t ByteCount) override {
- std::memcpy(static_cast<char *>(HostDst) + DstByteOffset,
- static_cast<const char *>(DeviceHandleSrc) + SrcByteOffset,
- ByteCount);
- return streamexecutor::Error::success();
- }
-
- streamexecutor::Error copyH2D(const void *StreamHandle, const void *HostSrc,
- size_t SrcByteOffset,
- const void *DeviceHandleDst,
- size_t DstByteOffset,
- size_t ByteCount) override {
- std::memcpy(static_cast<char *>(const_cast<void *>(DeviceHandleDst)) +
- DstByteOffset,
- static_cast<const char *>(HostSrc) + SrcByteOffset, ByteCount);
- return streamexecutor::Error::success();
- }
-
- streamexecutor::Error
- copyD2D(const void *StreamHandle, const void *DeviceHandleSrc,
- size_t SrcByteOffset, const void *DeviceHandleDst,
- size_t DstByteOffset, size_t ByteCount) override {
- std::memcpy(static_cast<char *>(const_cast<void *>(DeviceHandleDst)) +
- DstByteOffset,
- static_cast<const char *>(DeviceHandleSrc) + SrcByteOffset,
- ByteCount);
- return streamexecutor::Error::success();
- }
-
- streamexecutor::Error synchronousCopyD2H(const void *DeviceHandleSrc,
- size_t SrcByteOffset, void *HostDst,
- size_t DstByteOffset,
- size_t ByteCount) override {
- std::memcpy(static_cast<char *>(HostDst) + DstByteOffset,
- static_cast<const char *>(DeviceHandleSrc) + SrcByteOffset,
- ByteCount);
- return streamexecutor::Error::success();
- }
-
- streamexecutor::Error synchronousCopyH2D(const void *HostSrc,
- size_t SrcByteOffset,
- const void *DeviceHandleDst,
- size_t DstByteOffset,
- size_t ByteCount) override {
- std::memcpy(static_cast<char *>(const_cast<void *>(DeviceHandleDst)) +
- DstByteOffset,
- static_cast<const char *>(HostSrc) + SrcByteOffset, ByteCount);
- return streamexecutor::Error::success();
- }
-
- streamexecutor::Error synchronousCopyD2D(const void *DeviceHandleSrc,
- size_t SrcByteOffset,
- const void *DeviceHandleDst,
- size_t DstByteOffset,
- size_t ByteCount) override {
- std::memcpy(static_cast<char *>(const_cast<void *>(DeviceHandleDst)) +
- DstByteOffset,
- static_cast<const char *>(DeviceHandleSrc) + SrcByteOffset,
- ByteCount);
- return streamexecutor::Error::success();
- }
-
- /// Gets the value at the given index from a GlobalDeviceMemory<T> instance
- /// created by this class.
- template <typename T>
- static T getDeviceValue(const streamexecutor::GlobalDeviceMemory<T> &Memory,
- size_t Index) {
- return static_cast<const T *>(Memory.getHandle())[Index];
- }
-};
-
-} // namespace test
-} // namespace streamexecutor
-
-#endif // STREAMEXECUTOR_LIB_UNITTESTS_SIMPLEHOSTPLATFORMDEVICE_H
#include <cstring>
-#include "SimpleHostPlatformDevice.h"
#include "streamexecutor/Device.h"
#include "streamexecutor/Kernel.h"
#include "streamexecutor/KernelSpec.h"
#include "streamexecutor/PlatformDevice.h"
#include "streamexecutor/Stream.h"
+#include "streamexecutor/unittests/CoreTests/SimpleHostPlatformDevice.h"
#include "gtest/gtest.h"
se::GlobalDeviceMemory<int> DeviceB7;
};
-using llvm::ArrayRef;
-using llvm::MutableArrayRef;
-
// D2H tests
TEST_F(StreamTest, CopyD2HToRegisteredRefByCount) {
Stream.thenCopyD2H(DeviceA5, RegisteredHost5, 5);
EXPECT_TRUE(Stream.isOK());
- for (int I = 0; I < 5; ++I) {
+ for (int I = 0; I < 5; ++I)
EXPECT_EQ(HostA5[I], Host5[I]);
- }
Stream.thenCopyD2H(DeviceB5, RegisteredHost5, 2);
EXPECT_TRUE(Stream.isOK());
- for (int I = 0; I < 2; ++I) {
+ for (int I = 0; I < 2; ++I)
EXPECT_EQ(HostB5[I], Host5[I]);
- }
Stream.thenCopyD2H(DeviceA7, RegisteredHost5, 7);
EXPECT_FALSE(Stream.isOK());
TEST_F(StreamTest, CopyD2HToRegistered) {
Stream.thenCopyD2H(DeviceA5, RegisteredHost5);
EXPECT_TRUE(Stream.isOK());
- for (int I = 0; I < 5; ++I) {
+ for (int I = 0; I < 5; ++I)
EXPECT_EQ(HostA5[I], Host5[I]);
- }
Stream.thenCopyD2H(DeviceA5, RegisteredHost7);
EXPECT_FALSE(Stream.isOK());
Stream.thenCopyD2H(DeviceA5.asSlice().slice(1),
RegisteredHost5.asSlice().slice(1, 4), 4);
EXPECT_TRUE(Stream.isOK());
- for (int I = 1; I < 5; ++I) {
+ for (int I = 1; I < 5; ++I)
EXPECT_EQ(HostA5[I], Host5[I]);
- }
Stream.thenCopyD2H(DeviceB5.asSlice().drop_back(1), RegisteredHost5, 2);
EXPECT_TRUE(Stream.isOK());
- for (int I = 0; I < 2; ++I) {
+ for (int I = 0; I < 2; ++I)
EXPECT_EQ(HostB5[I], Host5[I]);
- }
Stream.thenCopyD2H(DeviceA5.asSlice(), RegisteredHost7, 7);
EXPECT_FALSE(Stream.isOK());
TEST_F(StreamTest, CopyD2HSliceToRegistered) {
Stream.thenCopyD2H(DeviceA7.asSlice().slice(1, 5), RegisteredHost5);
EXPECT_TRUE(Stream.isOK());
- for (int I = 0; I < 5; ++I) {
+ for (int I = 0; I < 5; ++I)
EXPECT_EQ(HostA7[I + 1], Host5[I]);
- }
Stream.thenCopyD2H(DeviceA5.asSlice(), RegisteredHost7);
EXPECT_FALSE(Stream.isOK());
TEST_F(StreamTest, CopyH2DFromRegisterdByCount) {
Stream.thenCopyH2D(RegisteredHost5, DeviceA5, 5);
EXPECT_TRUE(Stream.isOK());
- for (int I = 0; I < 5; ++I) {
+ for (int I = 0; I < 5; ++I)
EXPECT_EQ(getDeviceValue(DeviceA5, I), Host5[I]);
- }
Stream.thenCopyH2D(RegisteredHost5, DeviceB5, 2);
EXPECT_TRUE(Stream.isOK());
- for (int I = 0; I < 2; ++I) {
+ for (int I = 0; I < 2; ++I)
EXPECT_EQ(getDeviceValue(DeviceB5, I), Host5[I]);
- }
Stream.thenCopyH2D(RegisteredHost7, DeviceA5, 7);
EXPECT_FALSE(Stream.isOK());
TEST_F(StreamTest, CopyH2DFromRegistered) {
Stream.thenCopyH2D(RegisteredHost5, DeviceA5);
EXPECT_TRUE(Stream.isOK());
- for (int I = 0; I < 5; ++I) {
+ for (int I = 0; I < 5; ++I)
EXPECT_EQ(getDeviceValue(DeviceA5, I), Host5[I]);
- }
Stream.thenCopyH2D(RegisteredHost7, DeviceA5);
EXPECT_FALSE(Stream.isOK());
Stream.thenCopyH2D(RegisteredHost5.asSlice().slice(1, 4),
DeviceA5.asSlice().slice(1), 4);
EXPECT_TRUE(Stream.isOK());
- for (int I = 1; I < 5; ++I) {
+ for (int I = 1; I < 5; ++I)
EXPECT_EQ(getDeviceValue(DeviceA5, I), Host5[I]);
- }
Stream.thenCopyH2D(RegisteredHost5, DeviceB5.asSlice().drop_back(1), 2);
EXPECT_TRUE(Stream.isOK());
- for (int I = 0; I < 2; ++I) {
+ for (int I = 0; I < 2; ++I)
EXPECT_EQ(getDeviceValue(DeviceB5, I), Host5[I]);
- }
Stream.thenCopyH2D(RegisteredHost5, DeviceA5.asSlice(), 7);
EXPECT_FALSE(Stream.isOK());
TEST_F(StreamTest, CopyH2DRegisteredToSlice) {
Stream.thenCopyH2D(RegisteredHost5, DeviceA5.asSlice());
EXPECT_TRUE(Stream.isOK());
- for (int I = 0; I < 5; ++I) {
+ for (int I = 0; I < 5; ++I)
EXPECT_EQ(getDeviceValue(DeviceA5, I), Host5[I]);
- }
Stream.thenCopyH2D(RegisteredHost7, DeviceA5.asSlice());
EXPECT_FALSE(Stream.isOK());
TEST_F(StreamTest, CopyD2DByCount) {
Stream.thenCopyD2D(DeviceA5, DeviceB5, 5);
EXPECT_TRUE(Stream.isOK());
- for (int I = 0; I < 5; ++I) {
+ for (int I = 0; I < 5; ++I)
EXPECT_EQ(getDeviceValue(DeviceA5, I), getDeviceValue(DeviceB5, I));
- }
Stream.thenCopyD2D(DeviceA7, DeviceB7, 2);
EXPECT_TRUE(Stream.isOK());
- for (int I = 0; I < 2; ++I) {
+ for (int I = 0; I < 2; ++I)
EXPECT_EQ(getDeviceValue(DeviceA7, I), getDeviceValue(DeviceB7, I));
- }
Stream.thenCopyD2D(DeviceA7, DeviceB5, 7);
EXPECT_FALSE(Stream.isOK());
TEST_F(StreamTest, CopyD2D) {
Stream.thenCopyD2D(DeviceA5, DeviceB5);
EXPECT_TRUE(Stream.isOK());
- for (int I = 0; I < 5; ++I) {
+ for (int I = 0; I < 5; ++I)
EXPECT_EQ(getDeviceValue(DeviceA5, I), getDeviceValue(DeviceB5, I));
- }
Stream.thenCopyD2D(DeviceA7, DeviceB5);
EXPECT_FALSE(Stream.isOK());
TEST_F(StreamTest, CopySliceD2DByCount) {
Stream.thenCopyD2D(DeviceA5.asSlice().slice(1), DeviceB5, 4);
EXPECT_TRUE(Stream.isOK());
- for (int I = 0; I < 4; ++I) {
+ for (int I = 0; I < 4; ++I)
EXPECT_EQ(getDeviceValue(DeviceA5, I + 1), getDeviceValue(DeviceB5, I));
- }
Stream.thenCopyD2D(DeviceA7.asSlice().drop_back(1), DeviceB7, 2);
EXPECT_TRUE(Stream.isOK());
- for (int I = 0; I < 2; ++I) {
+ for (int I = 0; I < 2; ++I)
EXPECT_EQ(getDeviceValue(DeviceA7, I), getDeviceValue(DeviceB7, I));
- }
Stream.thenCopyD2D(DeviceA5.asSlice(), DeviceB5, 7);
EXPECT_FALSE(Stream.isOK());
TEST_F(StreamTest, CopySliceD2D) {
Stream.thenCopyD2D(DeviceA7.asSlice().drop_back(2), DeviceB5);
EXPECT_TRUE(Stream.isOK());
- for (int I = 0; I < 5; ++I) {
+ for (int I = 0; I < 5; ++I)
EXPECT_EQ(getDeviceValue(DeviceA7, I), getDeviceValue(DeviceB5, I));
- }
Stream.thenCopyD2D(DeviceA5.asSlice().drop_back(1), DeviceB7);
EXPECT_FALSE(Stream.isOK());
TEST_F(StreamTest, CopyD2DSliceByCount) {
Stream.thenCopyD2D(DeviceA5, DeviceB7.asSlice().slice(2), 5);
EXPECT_TRUE(Stream.isOK());
- for (int I = 0; I < 5; ++I) {
+ for (int I = 0; I < 5; ++I)
EXPECT_EQ(getDeviceValue(DeviceA5, I), getDeviceValue(DeviceB7, I + 2));
- }
Stream.thenCopyD2D(DeviceA7, DeviceB7.asSlice().drop_back(3), 2);
EXPECT_TRUE(Stream.isOK());
- for (int I = 0; I < 2; ++I) {
+ for (int I = 0; I < 2; ++I)
EXPECT_EQ(getDeviceValue(DeviceA7, I), getDeviceValue(DeviceB7, I));
- }
Stream.thenCopyD2D(DeviceA5, DeviceB7.asSlice(), 7);
EXPECT_FALSE(Stream.isOK());
TEST_F(StreamTest, CopyD2DSlice) {
Stream.thenCopyD2D(DeviceA5, DeviceB7.asSlice().drop_back(2));
EXPECT_TRUE(Stream.isOK());
- for (int I = 0; I < 5; ++I) {
+ for (int I = 0; I < 5; ++I)
EXPECT_EQ(getDeviceValue(DeviceA5, I), getDeviceValue(DeviceB7, I));
- }
Stream.thenCopyD2D(DeviceA5, DeviceB7.asSlice());
EXPECT_FALSE(Stream.isOK());
TEST_F(StreamTest, CopySliceD2DSliceByCount) {
Stream.thenCopyD2D(DeviceA5.asSlice(), DeviceB5.asSlice(), 5);
EXPECT_TRUE(Stream.isOK());
- for (int I = 0; I < 5; ++I) {
+ for (int I = 0; I < 5; ++I)
EXPECT_EQ(getDeviceValue(DeviceA5, I), getDeviceValue(DeviceB5, I));
- }
Stream.thenCopyD2D(DeviceA7.asSlice(), DeviceB7.asSlice(), 2);
EXPECT_TRUE(Stream.isOK());
- for (int I = 0; I < 2; ++I) {
+ for (int I = 0; I < 2; ++I)
EXPECT_EQ(getDeviceValue(DeviceA7, I), getDeviceValue(DeviceB7, I));
- }
Stream.thenCopyD2D(DeviceA7.asSlice(), DeviceB5.asSlice(), 7);
EXPECT_FALSE(Stream.isOK());
TEST_F(StreamTest, CopySliceD2DSlice) {
Stream.thenCopyD2D(DeviceA5.asSlice(), DeviceB5.asSlice());
EXPECT_TRUE(Stream.isOK());
- for (int I = 0; I < 5; ++I) {
+ for (int I = 0; I < 5; ++I)
EXPECT_EQ(getDeviceValue(DeviceA5, I), getDeviceValue(DeviceB5, I));
- }
Stream.thenCopyD2D(DeviceA5.asSlice(), DeviceB7.asSlice());
EXPECT_FALSE(Stream.isOK());