[Parallel_libs-commits] [parallel-libs] r281239 - [SE] Clean up device and host memory slices

Jason Henline via Parallel_libs-commits parallel_libs-commits at lists.llvm.org
Mon Sep 12 10:20:44 PDT 2016


Author: jhen
Date: Mon Sep 12 12:20:43 2016
New Revision: 281239

URL: http://llvm.org/viewvc/llvm-project?rev=281239&view=rev
Log:
[SE] Clean up device and host memory slices

Summary:
* Add LLVM_ATTRIBUTE_UNUSED_RESULT used to slicing methods in order to
  emphasize that the slicing is not done in place.
* Change device memory slice function name from `drop_front` to `slice`
  in order to match the naming convention of `llvm::ArrayRef` and host
  memory slice.
* Change the parameter names of host memory slice functions to
  `DropCount` and `TakeCount` to match device memory slice declarations.

Reviewers: jlebar

Subscribers: jprice, parallel_libs-commits

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

Modified:
    parallel-libs/trunk/streamexecutor/include/streamexecutor/DeviceMemory.h
    parallel-libs/trunk/streamexecutor/include/streamexecutor/HostMemory.h
    parallel-libs/trunk/streamexecutor/unittests/CoreTests/DeviceTest.cpp
    parallel-libs/trunk/streamexecutor/unittests/CoreTests/StreamTest.cpp

Modified: parallel-libs/trunk/streamexecutor/include/streamexecutor/DeviceMemory.h
URL: http://llvm.org/viewvc/llvm-project/parallel-libs/trunk/streamexecutor/include/streamexecutor/DeviceMemory.h?rev=281239&r1=281238&r2=281239&view=diff
==============================================================================
--- parallel-libs/trunk/streamexecutor/include/streamexecutor/DeviceMemory.h (original)
+++ parallel-libs/trunk/streamexecutor/include/streamexecutor/DeviceMemory.h Mon Sep 12 12:20:43 2016
@@ -77,7 +77,8 @@ public:
   size_t getByteCount() const { return ElementCount * sizeof(ElemT); }
 
   /// Creates a slice of the memory with the first DropCount elements removed.
-  GlobalDeviceMemorySlice<ElemT> drop_front(size_t DropCount) const {
+  LLVM_ATTRIBUTE_UNUSED_RESULT
+  GlobalDeviceMemorySlice<ElemT> slice(size_t DropCount) const {
     assert(DropCount <= ElementCount &&
            "dropping more than the size of a slice");
     return GlobalDeviceMemorySlice<ElemT>(BaseMemory, ElementOffset + DropCount,
@@ -85,6 +86,7 @@ public:
   }
 
   /// Creates a slice of the memory with the last DropCount elements removed.
+  LLVM_ATTRIBUTE_UNUSED_RESULT
   GlobalDeviceMemorySlice<ElemT> drop_back(size_t DropCount) const {
     assert(DropCount <= ElementCount &&
            "dropping more than the size of a slice");
@@ -94,6 +96,7 @@ public:
 
   /// Creates a slice of the memory that chops off the first DropCount elements
   /// and keeps the next TakeCount elements.
+  LLVM_ATTRIBUTE_UNUSED_RESULT
   GlobalDeviceMemorySlice<ElemT> slice(size_t DropCount,
                                        size_t TakeCount) const {
     assert(DropCount + TakeCount <= ElementCount &&

Modified: parallel-libs/trunk/streamexecutor/include/streamexecutor/HostMemory.h
URL: http://llvm.org/viewvc/llvm-project/parallel-libs/trunk/streamexecutor/include/streamexecutor/HostMemory.h?rev=281239&r1=281238&r2=281239&view=diff
==============================================================================
--- parallel-libs/trunk/streamexecutor/include/streamexecutor/HostMemory.h (original)
+++ parallel-libs/trunk/streamexecutor/include/streamexecutor/HostMemory.h Mon Sep 12 12:20:43 2016
@@ -47,19 +47,26 @@ public:
   ElemT *getPointer() const { return MutableArrayRef.data(); }
   size_t getElementCount() const { return MutableArrayRef.size(); }
 
-  /// Chops off the first N elements of the slice.
-  MutableRegisteredHostMemorySlice slice(size_t N) const {
-    return MutableRegisteredHostMemorySlice(MutableArrayRef.slice(N));
-  }
-
-  /// Chops off the first N elements of the slice and keeps the next M elements.
-  MutableRegisteredHostMemorySlice slice(size_t N, size_t M) const {
-    return MutableRegisteredHostMemorySlice(MutableArrayRef.slice(N, M));
-  }
-
-  /// Chops off the last N elements of the slice.
-  MutableRegisteredHostMemorySlice drop_back(size_t N) const {
-    return MutableRegisteredHostMemorySlice(MutableArrayRef.drop_back(N));
+  /// Chops off the first DropCount elements of the slice.
+  LLVM_ATTRIBUTE_UNUSED_RESULT
+  MutableRegisteredHostMemorySlice slice(size_t DropCount) const {
+    return MutableRegisteredHostMemorySlice(MutableArrayRef.slice(DropCount));
+  }
+
+  /// Chops off the first DropCount elements of the slice and keeps the next
+  /// TakeCount elements.
+  LLVM_ATTRIBUTE_UNUSED_RESULT
+  MutableRegisteredHostMemorySlice slice(size_t DropCount,
+                                         size_t TakeCount) const {
+    return MutableRegisteredHostMemorySlice(
+        MutableArrayRef.slice(DropCount, TakeCount));
+  }
+
+  /// Chops off the last DropCount elements of the slice.
+  LLVM_ATTRIBUTE_UNUSED_RESULT
+  MutableRegisteredHostMemorySlice drop_back(size_t DropCount) const {
+    return MutableRegisteredHostMemorySlice(
+        MutableArrayRef.drop_back(DropCount));
   }
 
 private:
@@ -91,16 +98,19 @@ public:
   size_t getElementCount() const { return ArrayRef.size(); }
 
   /// Chops off the first N elements of the slice.
+  LLVM_ATTRIBUTE_UNUSED_RESULT
   RegisteredHostMemorySlice slice(size_t N) const {
     return RegisteredHostMemorySlice(ArrayRef.slice(N));
   }
 
   /// Chops off the first N elements of the slice and keeps the next M elements.
+  LLVM_ATTRIBUTE_UNUSED_RESULT
   RegisteredHostMemorySlice slice(size_t N, size_t M) const {
     return RegisteredHostMemorySlice(ArrayRef.slice(N, M));
   }
 
   /// Chops off the last N elements of the slice.
+  LLVM_ATTRIBUTE_UNUSED_RESULT
   RegisteredHostMemorySlice drop_back(size_t N) const {
     return RegisteredHostMemorySlice(ArrayRef.drop_back(N));
   }

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=281239&r1=281238&r2=281239&view=diff
==============================================================================
--- parallel-libs/trunk/streamexecutor/unittests/CoreTests/DeviceTest.cpp (original)
+++ parallel-libs/trunk/streamexecutor/unittests/CoreTests/DeviceTest.cpp Mon Sep 12 12:20:43 2016
@@ -141,7 +141,7 @@ TEST_F(DeviceTest, SyncCopyD2HToPointer)
 
 TEST_F(DeviceTest, SyncCopyD2HSliceToMutableArrayRefByCount) {
   EXPECT_NO_ERROR(Device.synchronousCopyD2H(
-      DeviceA5.asSlice().drop_front(1), MutableArrayRef<int>(Host5 + 1, 4), 4));
+      DeviceA5.asSlice().slice(1), MutableArrayRef<int>(Host5 + 1, 4), 4));
   for (int I = 1; I < 5; ++I) {
     EXPECT_EQ(HostA5[I], Host5[I]);
   }
@@ -177,8 +177,8 @@ TEST_F(DeviceTest, SyncCopyD2HSliceToMut
 }
 
 TEST_F(DeviceTest, SyncCopyD2HSliceToPointer) {
-  EXPECT_NO_ERROR(Device.synchronousCopyD2H(DeviceA5.asSlice().drop_front(1),
-                                            Host5 + 1, 4));
+  EXPECT_NO_ERROR(
+      Device.synchronousCopyD2H(DeviceA5.asSlice().slice(1), Host5 + 1, 4));
   for (int I = 1; I < 5; ++I) {
     EXPECT_EQ(HostA5[I], Host5[I]);
   }
@@ -227,8 +227,8 @@ TEST_F(DeviceTest, SyncCopyH2DToPointer)
 }
 
 TEST_F(DeviceTest, SyncCopyH2DSliceToArrayRefByCount) {
-  EXPECT_NO_ERROR(Device.synchronousCopyH2D(
-      ArrayRef<int>(Host5 + 1, 4), DeviceA5.asSlice().drop_front(1), 4));
+  EXPECT_NO_ERROR(Device.synchronousCopyH2D(ArrayRef<int>(Host5 + 1, 4),
+                                            DeviceA5.asSlice().slice(1), 4));
   for (int I = 1; I < 5; ++I) {
     EXPECT_EQ(getDeviceValue(DeviceA5, I), Host5[I]);
   }
@@ -305,7 +305,7 @@ TEST_F(DeviceTest, SyncCopyD2D) {
 
 TEST_F(DeviceTest, SyncCopySliceD2DByCount) {
   EXPECT_NO_ERROR(
-      Device.synchronousCopyD2D(DeviceA5.asSlice().drop_front(1), DeviceB5, 4));
+      Device.synchronousCopyD2D(DeviceA5.asSlice().slice(1), DeviceB5, 4));
   for (int I = 0; I < 4; ++I) {
     EXPECT_EQ(getDeviceValue(DeviceA5, I + 1), getDeviceValue(DeviceB5, I));
   }
@@ -331,7 +331,7 @@ TEST_F(DeviceTest, SyncCopySliceD2D) {
   }
 
   EXPECT_ERROR(
-      Device.synchronousCopyD2D(DeviceA7.asSlice().drop_front(1), DeviceB5));
+      Device.synchronousCopyD2D(DeviceA7.asSlice().slice(1), DeviceB5));
 
   EXPECT_ERROR(
       Device.synchronousCopyD2D(DeviceA5.asSlice().drop_back(1), DeviceB7));
@@ -339,7 +339,7 @@ TEST_F(DeviceTest, SyncCopySliceD2D) {
 
 TEST_F(DeviceTest, SyncCopyD2DSliceByCount) {
   EXPECT_NO_ERROR(
-      Device.synchronousCopyD2D(DeviceA5, DeviceB7.asSlice().drop_front(2), 5));
+      Device.synchronousCopyD2D(DeviceA5, DeviceB7.asSlice().slice(2), 5));
   for (int I = 0; I < 5; ++I) {
     EXPECT_EQ(getDeviceValue(DeviceA5, I), getDeviceValue(DeviceB7, I + 2));
   }

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=281239&r1=281238&r2=281239&view=diff
==============================================================================
--- parallel-libs/trunk/streamexecutor/unittests/CoreTests/StreamTest.cpp (original)
+++ parallel-libs/trunk/streamexecutor/unittests/CoreTests/StreamTest.cpp Mon Sep 12 12:20:43 2016
@@ -114,7 +114,7 @@ TEST_F(StreamTest, CopyD2HToRegistered)
 }
 
 TEST_F(StreamTest, CopyD2HSliceToRegiseredSliceByCount) {
-  Stream.thenCopyD2H(DeviceA5.asSlice().drop_front(1),
+  Stream.thenCopyD2H(DeviceA5.asSlice().slice(1),
                      RegisteredHost5.asSlice().slice(1, 4), 4);
   EXPECT_TRUE(Stream.isOK());
   for (int I = 1; I < 5; ++I) {
@@ -174,7 +174,7 @@ TEST_F(StreamTest, CopyH2DFromRegistered
 
 TEST_F(StreamTest, CopyH2DFromRegisteredSliceToSlice) {
   Stream.thenCopyH2D(RegisteredHost5.asSlice().slice(1, 4),
-                     DeviceA5.asSlice().drop_front(1), 4);
+                     DeviceA5.asSlice().slice(1), 4);
   EXPECT_TRUE(Stream.isOK());
   for (int I = 1; I < 5; ++I) {
     EXPECT_EQ(getDeviceValue(DeviceA5, I), Host5[I]);
@@ -232,7 +232,7 @@ TEST_F(StreamTest, CopyD2D) {
 }
 
 TEST_F(StreamTest, CopySliceD2DByCount) {
-  Stream.thenCopyD2D(DeviceA5.asSlice().drop_front(1), DeviceB5, 4);
+  Stream.thenCopyD2D(DeviceA5.asSlice().slice(1), DeviceB5, 4);
   EXPECT_TRUE(Stream.isOK());
   for (int I = 0; I < 4; ++I) {
     EXPECT_EQ(getDeviceValue(DeviceA5, I + 1), getDeviceValue(DeviceB5, I));
@@ -260,7 +260,7 @@ TEST_F(StreamTest, CopySliceD2D) {
 }
 
 TEST_F(StreamTest, CopyD2DSliceByCount) {
-  Stream.thenCopyD2D(DeviceA5, DeviceB7.asSlice().drop_front(2), 5);
+  Stream.thenCopyD2D(DeviceA5, DeviceB7.asSlice().slice(2), 5);
   EXPECT_TRUE(Stream.isOK());
   for (int I = 0; I < 5; ++I) {
     EXPECT_EQ(getDeviceValue(DeviceA5, I), getDeviceValue(DeviceB7, I + 2));




More information about the Parallel_libs-commits mailing list