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,
}
/// 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");
/// 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 &&
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:
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));
}
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]);
}
}
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]);
}
}
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]);
}
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));
}
}
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));
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));
}
}
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) {
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]);
}
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));
}
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));