summaryrefslogtreecommitdiff
path: root/parallel-libs
diff options
context:
space:
mode:
authorJason Henline <jhen@google.com>2016-09-12 17:20:43 +0000
committerJason Henline <jhen@google.com>2016-09-12 17:20:43 +0000
commitfdfef2278ac7b2ea1260f2f485ba7e824acba99f (patch)
tree3a9046662cb2838cc4cb27644dc9eb79f55f168a /parallel-libs
parent47188cc81b68676716775b985b23ad88087fec7a (diff)
[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
Diffstat (limited to 'parallel-libs')
-rw-r--r--parallel-libs/streamexecutor/include/streamexecutor/DeviceMemory.h5
-rw-r--r--parallel-libs/streamexecutor/include/streamexecutor/HostMemory.h28
-rw-r--r--parallel-libs/streamexecutor/unittests/CoreTests/DeviceTest.cpp16
-rw-r--r--parallel-libs/streamexecutor/unittests/CoreTests/StreamTest.cpp8
4 files changed, 35 insertions, 22 deletions
diff --git a/parallel-libs/streamexecutor/include/streamexecutor/DeviceMemory.h b/parallel-libs/streamexecutor/include/streamexecutor/DeviceMemory.h
index ee4ebb621e9..bad6f6c99a1 100644
--- a/parallel-libs/streamexecutor/include/streamexecutor/DeviceMemory.h
+++ b/parallel-libs/streamexecutor/include/streamexecutor/DeviceMemory.h
@@ -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 &&
diff --git a/parallel-libs/streamexecutor/include/streamexecutor/HostMemory.h b/parallel-libs/streamexecutor/include/streamexecutor/HostMemory.h
index 2e8e961aca1..cea98f4ed74 100644
--- a/parallel-libs/streamexecutor/include/streamexecutor/HostMemory.h
+++ b/parallel-libs/streamexecutor/include/streamexecutor/HostMemory.h
@@ -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 DropCount elements of the slice.
+ LLVM_ATTRIBUTE_UNUSED_RESULT
+ MutableRegisteredHostMemorySlice slice(size_t DropCount) const {
+ return MutableRegisteredHostMemorySlice(MutableArrayRef.slice(DropCount));
}
- /// 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 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 N elements of the slice.
- MutableRegisteredHostMemorySlice drop_back(size_t N) const {
- return MutableRegisteredHostMemorySlice(MutableArrayRef.drop_back(N));
+ /// 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));
}
diff --git a/parallel-libs/streamexecutor/unittests/CoreTests/DeviceTest.cpp b/parallel-libs/streamexecutor/unittests/CoreTests/DeviceTest.cpp
index 897399c02a8..8537f0a3af0 100644
--- a/parallel-libs/streamexecutor/unittests/CoreTests/DeviceTest.cpp
+++ b/parallel-libs/streamexecutor/unittests/CoreTests/DeviceTest.cpp
@@ -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, SyncCopyD2HSliceToMutableArrayRef) {
}
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));
}
diff --git a/parallel-libs/streamexecutor/unittests/CoreTests/StreamTest.cpp b/parallel-libs/streamexecutor/unittests/CoreTests/StreamTest.cpp
index 34516e2c2da..f353ec28c90 100644
--- a/parallel-libs/streamexecutor/unittests/CoreTests/StreamTest.cpp
+++ b/parallel-libs/streamexecutor/unittests/CoreTests/StreamTest.cpp
@@ -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));