[Parallel_libs-commits] [parallel-libs] r281384 - [SE] Use real HostPlatformDevice for testing

Jason Henline via Parallel_libs-commits parallel_libs-commits at lists.llvm.org
Tue Sep 13 13:14:44 PDT 2016


Author: jhen
Date: Tue Sep 13 15:14:44 2016
New Revision: 281384

URL: http://llvm.org/viewvc/llvm-project?rev=281384&view=rev
Log:
[SE] Use real HostPlatformDevice for testing

Summary:
Replace uses of SimpleHostPlatformDevice in tests with
HostPlatformDevice.

Reviewers: jlebar

Subscribers: jlebar, jprice, parallel_libs-commits

Differential Revision: https://reviews.llvm.org/D24519

Removed:
    parallel-libs/trunk/streamexecutor/include/streamexecutor/unittests/CoreTests/SimpleHostPlatformDevice.h
Modified:
    parallel-libs/trunk/streamexecutor/include/streamexecutor/platforms/host/HostPlatformDevice.h
    parallel-libs/trunk/streamexecutor/unittests/CoreTests/DeviceTest.cpp
    parallel-libs/trunk/streamexecutor/unittests/CoreTests/PackedKernelArgumentArrayTest.cpp
    parallel-libs/trunk/streamexecutor/unittests/CoreTests/StreamTest.cpp

Modified: parallel-libs/trunk/streamexecutor/include/streamexecutor/platforms/host/HostPlatformDevice.h
URL: http://llvm.org/viewvc/llvm-project/parallel-libs/trunk/streamexecutor/include/streamexecutor/platforms/host/HostPlatformDevice.h?rev=281384&r1=281383&r2=281384&view=diff
==============================================================================
--- parallel-libs/trunk/streamexecutor/include/streamexecutor/platforms/host/HostPlatformDevice.h (original)
+++ parallel-libs/trunk/streamexecutor/include/streamexecutor/platforms/host/HostPlatformDevice.h Tue Sep 13 15:14:44 2016
@@ -139,6 +139,14 @@ public:
     return 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];
+  }
+
 private:
   static void *offset(const void *Base, size_t Offset) {
     return const_cast<char *>(static_cast<const char *>(Base) + Offset);

Removed: parallel-libs/trunk/streamexecutor/include/streamexecutor/unittests/CoreTests/SimpleHostPlatformDevice.h
URL: http://llvm.org/viewvc/llvm-project/parallel-libs/trunk/streamexecutor/include/streamexecutor/unittests/CoreTests/SimpleHostPlatformDevice.h?rev=281383&view=auto
==============================================================================
--- parallel-libs/trunk/streamexecutor/include/streamexecutor/unittests/CoreTests/SimpleHostPlatformDevice.h (original)
+++ parallel-libs/trunk/streamexecutor/include/streamexecutor/unittests/CoreTests/SimpleHostPlatformDevice.h (removed)
@@ -1,138 +0,0 @@
-//===-- 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

Modified: parallel-libs/trunk/streamexecutor/unittests/CoreTests/DeviceTest.cpp
URL: http://llvm.org/viewvc/llvm-project/parallel-libs/trunk/streamexecutor/unittests/CoreTests/DeviceTest.cpp?rev=281384&r1=281383&r2=281384&view=diff
==============================================================================
--- parallel-libs/trunk/streamexecutor/unittests/CoreTests/DeviceTest.cpp (original)
+++ parallel-libs/trunk/streamexecutor/unittests/CoreTests/DeviceTest.cpp Tue Sep 13 15:14:44 2016
@@ -17,7 +17,7 @@
 
 #include "streamexecutor/Device.h"
 #include "streamexecutor/PlatformDevice.h"
-#include "streamexecutor/unittests/CoreTests/SimpleHostPlatformDevice.h"
+#include "streamexecutor/platforms/host/HostPlatformDevice.h"
 
 #include "gtest/gtest.h"
 
@@ -25,8 +25,7 @@ namespace {
 
 namespace se = ::streamexecutor;
 
-const auto &getDeviceValue =
-    se::test::SimpleHostPlatformDevice::getDeviceValue<int>;
+const auto &getDeviceValue = se::host::HostPlatformDevice::getDeviceValue<int>;
 
 /// Test fixture to hold objects used by tests.
 class DeviceTest : public ::testing::Test {
@@ -45,7 +44,7 @@ public:
     se::dieIfError(Device.synchronousCopyH2D<int>(HostB7, DeviceB7));
   }
 
-  se::test::SimpleHostPlatformDevice PDevice;
+  se::host::HostPlatformDevice PDevice;
   se::Device Device;
 
   // Device memory is backed by host arrays.
@@ -74,9 +73,7 @@ public:
 using llvm::ArrayRef;
 using llvm::MutableArrayRef;
 
-TEST_F(DeviceTest, GetName) {
-  EXPECT_EQ(Device.getName(), "SimpleHostPlatformDevice");
-}
+TEST_F(DeviceTest, GetName) { EXPECT_EQ(Device.getName(), "host"); }
 
 TEST_F(DeviceTest, AllocateAndFreeDeviceMemory) {
   se::Expected<se::GlobalDeviceMemory<int>> MaybeMemory =

Modified: parallel-libs/trunk/streamexecutor/unittests/CoreTests/PackedKernelArgumentArrayTest.cpp
URL: http://llvm.org/viewvc/llvm-project/parallel-libs/trunk/streamexecutor/unittests/CoreTests/PackedKernelArgumentArrayTest.cpp?rev=281384&r1=281383&r2=281384&view=diff
==============================================================================
--- parallel-libs/trunk/streamexecutor/unittests/CoreTests/PackedKernelArgumentArrayTest.cpp (original)
+++ parallel-libs/trunk/streamexecutor/unittests/CoreTests/PackedKernelArgumentArrayTest.cpp Tue Sep 13 15:14:44 2016
@@ -16,7 +16,7 @@
 #include "streamexecutor/DeviceMemory.h"
 #include "streamexecutor/PackedKernelArgumentArray.h"
 #include "streamexecutor/PlatformDevice.h"
-#include "streamexecutor/unittests/CoreTests/SimpleHostPlatformDevice.h"
+#include "streamexecutor/platforms/host/HostPlatformDevice.h"
 
 #include "llvm/ADT/Twine.h"
 
@@ -41,7 +41,7 @@ public:
         TypedShared(
             se::SharedDeviceMemory<int>::makeFromElementCount(ElementCount)) {}
 
-  se::test::SimpleHostPlatformDevice PDevice;
+  se::host::HostPlatformDevice PDevice;
   se::Device Device;
   int Value;
   void *Handle;

Modified: parallel-libs/trunk/streamexecutor/unittests/CoreTests/StreamTest.cpp
URL: http://llvm.org/viewvc/llvm-project/parallel-libs/trunk/streamexecutor/unittests/CoreTests/StreamTest.cpp?rev=281384&r1=281383&r2=281384&view=diff
==============================================================================
--- parallel-libs/trunk/streamexecutor/unittests/CoreTests/StreamTest.cpp (original)
+++ parallel-libs/trunk/streamexecutor/unittests/CoreTests/StreamTest.cpp Tue Sep 13 15:14:44 2016
@@ -19,7 +19,7 @@
 #include "streamexecutor/KernelSpec.h"
 #include "streamexecutor/PlatformDevice.h"
 #include "streamexecutor/Stream.h"
-#include "streamexecutor/unittests/CoreTests/SimpleHostPlatformDevice.h"
+#include "streamexecutor/platforms/host/HostPlatformDevice.h"
 
 #include "gtest/gtest.h"
 
@@ -27,8 +27,7 @@ namespace {
 
 namespace se = ::streamexecutor;
 
-const auto &getDeviceValue =
-    se::test::SimpleHostPlatformDevice::getDeviceValue<int>;
+const auto &getDeviceValue = se::host::HostPlatformDevice::getDeviceValue<int>;
 
 /// Test fixture to hold objects used by tests.
 class StreamTest : public ::testing::Test {
@@ -56,7 +55,7 @@ public:
 protected:
   int DummyPlatformStream; // Mimicking a platform where the platform stream
                            // handle is just a stream number.
-  se::test::SimpleHostPlatformDevice PDevice;
+  se::host::HostPlatformDevice PDevice;
   se::Device Device;
   se::Stream Stream;
 




More information about the Parallel_libs-commits mailing list