Index: parallel-libs/trunk/streamexecutor/include/streamexecutor/DeviceMemory.h =================================================================== --- parallel-libs/trunk/streamexecutor/include/streamexecutor/DeviceMemory.h +++ parallel-libs/trunk/streamexecutor/include/streamexecutor/DeviceMemory.h @@ -77,7 +77,8 @@ size_t getByteCount() const { return ElementCount * sizeof(ElemT); } /// Creates a slice of the memory with the first DropCount elements removed. - GlobalDeviceMemorySlice drop_front(size_t DropCount) const { + LLVM_ATTRIBUTE_UNUSED_RESULT + GlobalDeviceMemorySlice slice(size_t DropCount) const { assert(DropCount <= ElementCount && "dropping more than the size of a slice"); return GlobalDeviceMemorySlice(BaseMemory, ElementOffset + DropCount, @@ -85,6 +86,7 @@ } /// Creates a slice of the memory with the last DropCount elements removed. + LLVM_ATTRIBUTE_UNUSED_RESULT GlobalDeviceMemorySlice drop_back(size_t DropCount) const { assert(DropCount <= ElementCount && "dropping more than the size of a slice"); @@ -94,6 +96,7 @@ /// Creates a slice of the memory that chops off the first DropCount elements /// and keeps the next TakeCount elements. + LLVM_ATTRIBUTE_UNUSED_RESULT GlobalDeviceMemorySlice slice(size_t DropCount, size_t TakeCount) const { assert(DropCount + TakeCount <= ElementCount && Index: parallel-libs/trunk/streamexecutor/include/streamexecutor/HostMemory.h =================================================================== --- parallel-libs/trunk/streamexecutor/include/streamexecutor/HostMemory.h +++ parallel-libs/trunk/streamexecutor/include/streamexecutor/HostMemory.h @@ -47,19 +47,26 @@ 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 @@ 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)); } Index: parallel-libs/trunk/streamexecutor/unittests/CoreTests/DeviceTest.cpp =================================================================== --- parallel-libs/trunk/streamexecutor/unittests/CoreTests/DeviceTest.cpp +++ parallel-libs/trunk/streamexecutor/unittests/CoreTests/DeviceTest.cpp @@ -141,7 +141,7 @@ TEST_F(DeviceTest, SyncCopyD2HSliceToMutableArrayRefByCount) { EXPECT_NO_ERROR(Device.synchronousCopyD2H( - DeviceA5.asSlice().drop_front(1), MutableArrayRef(Host5 + 1, 4), 4)); + DeviceA5.asSlice().slice(1), MutableArrayRef(Host5 + 1, 4), 4)); for (int I = 1; I < 5; ++I) { EXPECT_EQ(HostA5[I], Host5[I]); } @@ -177,8 +177,8 @@ } 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, SyncCopyH2DSliceToArrayRefByCount) { - EXPECT_NO_ERROR(Device.synchronousCopyH2D( - ArrayRef(Host5 + 1, 4), DeviceA5.asSlice().drop_front(1), 4)); + EXPECT_NO_ERROR(Device.synchronousCopyH2D(ArrayRef(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, 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 @@ } 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, 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)); } Index: parallel-libs/trunk/streamexecutor/unittests/CoreTests/StreamTest.cpp =================================================================== --- parallel-libs/trunk/streamexecutor/unittests/CoreTests/StreamTest.cpp +++ parallel-libs/trunk/streamexecutor/unittests/CoreTests/StreamTest.cpp @@ -114,7 +114,7 @@ } 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, 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, 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, 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));