[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 llvm-svn: 281239
This commit is contained in:
parent
8d4be3aacf
commit
c16fb8748d
|
@ -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 &&
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Reference in New Issue