Index: streamexecutor/include/streamexecutor/Device.h =================================================================== --- streamexecutor/include/streamexecutor/Device.h +++ streamexecutor/include/streamexecutor/Device.h @@ -165,19 +165,19 @@ } template - Error synchronousCopyD2H(GlobalDeviceMemory Src, + Error synchronousCopyD2H(const GlobalDeviceMemory &Src, llvm::MutableArrayRef Dst, size_t ElementCount) { return synchronousCopyD2H(Src.asSlice(), Dst, ElementCount); } template - Error synchronousCopyD2H(GlobalDeviceMemory Src, + Error synchronousCopyD2H(const GlobalDeviceMemory &Src, llvm::MutableArrayRef Dst) { return synchronousCopyD2H(Src.asSlice(), Dst); } template - Error synchronousCopyD2H(GlobalDeviceMemory Src, T *Dst, + Error synchronousCopyD2H(const GlobalDeviceMemory &Src, T *Dst, size_t ElementCount) { return synchronousCopyD2H(Src.asSlice(), Dst, ElementCount); } @@ -220,20 +220,20 @@ } template - Error synchronousCopyH2D(llvm::ArrayRef Src, GlobalDeviceMemory Dst, + Error synchronousCopyH2D(llvm::ArrayRef Src, GlobalDeviceMemory *Dst, size_t ElementCount) { - return synchronousCopyH2D(Src, Dst.asSlice(), ElementCount); + return synchronousCopyH2D(Src, Dst->asSlice(), ElementCount); } template - Error synchronousCopyH2D(llvm::ArrayRef Src, GlobalDeviceMemory Dst) { - return synchronousCopyH2D(Src, Dst.asSlice()); + Error synchronousCopyH2D(llvm::ArrayRef Src, GlobalDeviceMemory *Dst) { + return synchronousCopyH2D(Src, Dst->asSlice()); } template - Error synchronousCopyH2D(T *Src, GlobalDeviceMemory Dst, + Error synchronousCopyH2D(T *Src, GlobalDeviceMemory *Dst, size_t ElementCount) { - return synchronousCopyH2D(Src, Dst.asSlice(), ElementCount); + return synchronousCopyH2D(Src, Dst->asSlice(), ElementCount); } template @@ -269,40 +269,40 @@ } template - Error synchronousCopyD2D(GlobalDeviceMemory Src, + Error synchronousCopyD2D(const GlobalDeviceMemory &Src, GlobalDeviceMemorySlice Dst, size_t ElementCount) { return synchronousCopyD2D(Src.asSlice(), Dst, ElementCount); } template - Error synchronousCopyD2D(GlobalDeviceMemory Src, + Error synchronousCopyD2D(const GlobalDeviceMemory &Src, GlobalDeviceMemorySlice Dst) { return synchronousCopyD2D(Src.asSlice(), Dst); } template Error synchronousCopyD2D(GlobalDeviceMemorySlice Src, - GlobalDeviceMemory Dst, size_t ElementCount) { - return synchronousCopyD2D(Src, Dst.asSlice(), ElementCount); + GlobalDeviceMemory *Dst, size_t ElementCount) { + return synchronousCopyD2D(Src, Dst->asSlice(), ElementCount); } template Error synchronousCopyD2D(GlobalDeviceMemorySlice Src, - GlobalDeviceMemory Dst) { - return synchronousCopyD2D(Src, Dst.asSlice()); + GlobalDeviceMemory *Dst) { + return synchronousCopyD2D(Src, Dst->asSlice()); } template - Error synchronousCopyD2D(GlobalDeviceMemory Src, GlobalDeviceMemory Dst, - size_t ElementCount) { - return synchronousCopyD2D(Src.asSlice(), Dst.asSlice(), ElementCount); + Error synchronousCopyD2D(const GlobalDeviceMemory &Src, + GlobalDeviceMemory *Dst, size_t ElementCount) { + return synchronousCopyD2D(Src.asSlice(), Dst->asSlice(), ElementCount); } template - Error synchronousCopyD2D(GlobalDeviceMemory Src, - GlobalDeviceMemory Dst) { - return synchronousCopyD2D(Src.asSlice(), Dst.asSlice()); + Error synchronousCopyD2D(const GlobalDeviceMemory &Src, + GlobalDeviceMemory *Dst) { + return synchronousCopyD2D(Src.asSlice(), Dst->asSlice()); } ///@} End host-synchronous device memory copying functions Index: streamexecutor/include/streamexecutor/DeviceMemory.h =================================================================== --- streamexecutor/include/streamexecutor/DeviceMemory.h +++ streamexecutor/include/streamexecutor/DeviceMemory.h @@ -192,7 +192,7 @@ size_t getElementCount() const { return getByteCount() / sizeof(ElemT); } /// Converts this memory object into a slice. - GlobalDeviceMemorySlice asSlice() { + GlobalDeviceMemorySlice asSlice() const { return GlobalDeviceMemorySlice(*this); } Index: streamexecutor/include/streamexecutor/Stream.h =================================================================== --- streamexecutor/include/streamexecutor/Stream.h +++ streamexecutor/include/streamexecutor/Stream.h @@ -164,20 +164,20 @@ } template - Stream &thenCopyD2H(GlobalDeviceMemory Src, llvm::MutableArrayRef Dst, + Stream &thenCopyD2H(const GlobalDeviceMemory &Src, llvm::MutableArrayRef Dst, size_t ElementCount) { thenCopyD2H(Src.asSlice(), Dst, ElementCount); return *this; } template - Stream &thenCopyD2H(GlobalDeviceMemory Src, llvm::MutableArrayRef Dst) { + Stream &thenCopyD2H(const GlobalDeviceMemory &Src, llvm::MutableArrayRef Dst) { thenCopyD2H(Src.asSlice(), Dst); return *this; } template - Stream &thenCopyD2H(GlobalDeviceMemory Src, T *Dst, size_t ElementCount) { + Stream &thenCopyD2H(const GlobalDeviceMemory &Src, T *Dst, size_t ElementCount) { thenCopyD2H(Src.asSlice(), Dst, ElementCount); return *this; } @@ -221,21 +221,21 @@ } template - Stream &thenCopyH2D(llvm::ArrayRef Src, GlobalDeviceMemory Dst, + Stream &thenCopyH2D(llvm::ArrayRef Src, GlobalDeviceMemory *Dst, size_t ElementCount) { - thenCopyH2D(Src, Dst.asSlice(), ElementCount); + thenCopyH2D(Src, Dst->asSlice(), ElementCount); return *this; } template - Stream &thenCopyH2D(llvm::ArrayRef Src, GlobalDeviceMemory Dst) { - thenCopyH2D(Src, Dst.asSlice()); + Stream &thenCopyH2D(llvm::ArrayRef Src, GlobalDeviceMemory *Dst) { + thenCopyH2D(Src, Dst->asSlice()); return *this; } template - Stream &thenCopyH2D(T *Src, GlobalDeviceMemory Dst, size_t ElementCount) { - thenCopyH2D(Src, Dst.asSlice(), ElementCount); + Stream &thenCopyH2D(T *Src, GlobalDeviceMemory *Dst, size_t ElementCount) { + thenCopyH2D(Src, Dst->asSlice(), ElementCount); return *this; } @@ -272,43 +272,44 @@ } template - Stream &thenCopyD2D(GlobalDeviceMemory Src, GlobalDeviceMemorySlice Dst, + Stream &thenCopyD2D(const GlobalDeviceMemory &Src, GlobalDeviceMemorySlice Dst, size_t ElementCount) { thenCopyD2D(Src.asSlice(), Dst, ElementCount); return *this; } template - Stream &thenCopyD2D(GlobalDeviceMemory Src, + Stream &thenCopyD2D(const GlobalDeviceMemory &Src, GlobalDeviceMemorySlice Dst) { thenCopyD2D(Src.asSlice(), Dst); return *this; } template - Stream &thenCopyD2D(GlobalDeviceMemorySlice Src, GlobalDeviceMemory Dst, + Stream &thenCopyD2D(GlobalDeviceMemorySlice Src, GlobalDeviceMemory *Dst, size_t ElementCount) { - thenCopyD2D(Src, Dst.asSlice(), ElementCount); + thenCopyD2D(Src, Dst->asSlice(), ElementCount); return *this; } template Stream &thenCopyD2D(GlobalDeviceMemorySlice Src, - GlobalDeviceMemory Dst) { - thenCopyD2D(Src, Dst.asSlice()); + GlobalDeviceMemory *Dst) { + thenCopyD2D(Src, Dst->asSlice()); return *this; } template - Stream &thenCopyD2D(GlobalDeviceMemory Src, GlobalDeviceMemory Dst, - size_t ElementCount) { - thenCopyD2D(Src.asSlice(), Dst.asSlice(), ElementCount); + Stream &thenCopyD2D(const GlobalDeviceMemory &Src, + GlobalDeviceMemory *Dst, size_t ElementCount) { + thenCopyD2D(Src.asSlice(), Dst->asSlice(), ElementCount); return *this; } template - Stream &thenCopyD2D(GlobalDeviceMemory Src, GlobalDeviceMemory Dst) { - thenCopyD2D(Src.asSlice(), Dst.asSlice()); + Stream &thenCopyD2D(const GlobalDeviceMemory &Src, + GlobalDeviceMemory *Dst) { + thenCopyD2D(Src.asSlice(), Dst->asSlice()); return *this; } Index: streamexecutor/lib/unittests/DeviceTest.cpp =================================================================== --- streamexecutor/lib/unittests/DeviceTest.cpp +++ streamexecutor/lib/unittests/DeviceTest.cpp @@ -191,41 +191,41 @@ // H2D tests TEST_F(DeviceTest, SyncCopyH2DToArrayRefByCount) { - EXPECT_NO_ERROR(Device.synchronousCopyH2D(ArrayRef(Host5), DeviceA5, 5)); + EXPECT_NO_ERROR(Device.synchronousCopyH2D(ArrayRef(Host5), &DeviceA5, 5)); for (int I = 0; I < 5; ++I) { EXPECT_EQ(getDeviceValue(DeviceA5, I), Host5[I]); } - EXPECT_NO_ERROR(Device.synchronousCopyH2D(ArrayRef(Host5), DeviceB5, 2)); + EXPECT_NO_ERROR(Device.synchronousCopyH2D(ArrayRef(Host5), &DeviceB5, 2)); for (int I = 0; I < 2; ++I) { EXPECT_EQ(getDeviceValue(DeviceB5, I), Host5[I]); } - EXPECT_ERROR(Device.synchronousCopyH2D(ArrayRef(Host7), DeviceA5, 7)); + EXPECT_ERROR(Device.synchronousCopyH2D(ArrayRef(Host7), &DeviceA5, 7)); - EXPECT_ERROR(Device.synchronousCopyH2D(ArrayRef(Host5), DeviceA7, 7)); + EXPECT_ERROR(Device.synchronousCopyH2D(ArrayRef(Host5), &DeviceA7, 7)); - EXPECT_ERROR(Device.synchronousCopyH2D(ArrayRef(Host5), DeviceA5, 7)); + EXPECT_ERROR(Device.synchronousCopyH2D(ArrayRef(Host5), &DeviceA5, 7)); } TEST_F(DeviceTest, SyncCopyH2DToArrayRef) { - EXPECT_NO_ERROR(Device.synchronousCopyH2D(ArrayRef(Host5), DeviceA5)); + EXPECT_NO_ERROR(Device.synchronousCopyH2D(ArrayRef(Host5), &DeviceA5)); for (int I = 0; I < 5; ++I) { EXPECT_EQ(getDeviceValue(DeviceA5, I), Host5[I]); } - EXPECT_ERROR(Device.synchronousCopyH2D(ArrayRef(Host5), DeviceA7)); + EXPECT_ERROR(Device.synchronousCopyH2D(ArrayRef(Host5), &DeviceA7)); - EXPECT_ERROR(Device.synchronousCopyH2D(ArrayRef(Host7), DeviceA5)); + EXPECT_ERROR(Device.synchronousCopyH2D(ArrayRef(Host7), &DeviceA5)); } TEST_F(DeviceTest, SyncCopyH2DToPointer) { - EXPECT_NO_ERROR(Device.synchronousCopyH2D(Host5, DeviceA5, 5)); + EXPECT_NO_ERROR(Device.synchronousCopyH2D(Host5, &DeviceA5, 5)); for (int I = 0; I < 5; ++I) { EXPECT_EQ(getDeviceValue(DeviceA5, I), Host5[I]); } - EXPECT_ERROR(Device.synchronousCopyH2D(Host7, DeviceA5, 7)); + EXPECT_ERROR(Device.synchronousCopyH2D(Host7, &DeviceA5, 7)); } TEST_F(DeviceTest, SyncCopyH2DSliceToArrayRefByCount) { @@ -277,66 +277,66 @@ // D2D tests TEST_F(DeviceTest, SyncCopyD2DByCount) { - EXPECT_NO_ERROR(Device.synchronousCopyD2D(DeviceA5, DeviceB5, 5)); + EXPECT_NO_ERROR(Device.synchronousCopyD2D(DeviceA5, &DeviceB5, 5)); for (int I = 0; I < 5; ++I) { EXPECT_EQ(getDeviceValue(DeviceA5, I), getDeviceValue(DeviceB5, I)); } - EXPECT_NO_ERROR(Device.synchronousCopyD2D(DeviceA7, DeviceB7, 2)); + EXPECT_NO_ERROR(Device.synchronousCopyD2D(DeviceA7, &DeviceB7, 2)); for (int I = 0; I < 2; ++I) { EXPECT_EQ(getDeviceValue(DeviceA7, I), getDeviceValue(DeviceB7, I)); } - EXPECT_ERROR(Device.synchronousCopyD2D(DeviceA5, DeviceB5, 7)); + EXPECT_ERROR(Device.synchronousCopyD2D(DeviceA5, &DeviceB5, 7)); - EXPECT_ERROR(Device.synchronousCopyD2D(DeviceA7, DeviceB5, 7)); + EXPECT_ERROR(Device.synchronousCopyD2D(DeviceA7, &DeviceB5, 7)); - EXPECT_ERROR(Device.synchronousCopyD2D(DeviceA5, DeviceB7, 7)); + EXPECT_ERROR(Device.synchronousCopyD2D(DeviceA5, &DeviceB7, 7)); } TEST_F(DeviceTest, SyncCopyD2D) { - EXPECT_NO_ERROR(Device.synchronousCopyD2D(DeviceA5, DeviceB5)); + EXPECT_NO_ERROR(Device.synchronousCopyD2D(DeviceA5, &DeviceB5)); for (int I = 0; I < 5; ++I) { EXPECT_EQ(getDeviceValue(DeviceA5, I), getDeviceValue(DeviceB5, I)); } - EXPECT_ERROR(Device.synchronousCopyD2D(DeviceA7, DeviceB5)); + EXPECT_ERROR(Device.synchronousCopyD2D(DeviceA7, &DeviceB5)); - EXPECT_ERROR(Device.synchronousCopyD2D(DeviceA5, DeviceB7)); + EXPECT_ERROR(Device.synchronousCopyD2D(DeviceA5, &DeviceB7)); } TEST_F(DeviceTest, SyncCopySliceD2DByCount) { EXPECT_NO_ERROR( - Device.synchronousCopyD2D(DeviceA5.asSlice().drop_front(1), DeviceB5, 4)); + Device.synchronousCopyD2D(DeviceA5.asSlice().drop_front(1), &DeviceB5, 4)); for (int I = 0; I < 4; ++I) { EXPECT_EQ(getDeviceValue(DeviceA5, I + 1), getDeviceValue(DeviceB5, I)); } EXPECT_NO_ERROR( - Device.synchronousCopyD2D(DeviceA7.asSlice().drop_back(1), DeviceB7, 2)); + Device.synchronousCopyD2D(DeviceA7.asSlice().drop_back(1), &DeviceB7, 2)); for (int I = 0; I < 2; ++I) { EXPECT_EQ(getDeviceValue(DeviceA7, I), getDeviceValue(DeviceB7, I)); } - EXPECT_ERROR(Device.synchronousCopyD2D(DeviceA5.asSlice(), DeviceB5, 7)); + EXPECT_ERROR(Device.synchronousCopyD2D(DeviceA5.asSlice(), &DeviceB5, 7)); - EXPECT_ERROR(Device.synchronousCopyD2D(DeviceA7.asSlice(), DeviceB5, 7)); + EXPECT_ERROR(Device.synchronousCopyD2D(DeviceA7.asSlice(), &DeviceB5, 7)); - EXPECT_ERROR(Device.synchronousCopyD2D(DeviceA5.asSlice(), DeviceB7, 7)); + EXPECT_ERROR(Device.synchronousCopyD2D(DeviceA5.asSlice(), &DeviceB7, 7)); } TEST_F(DeviceTest, SyncCopySliceD2D) { EXPECT_NO_ERROR( - Device.synchronousCopyD2D(DeviceA7.asSlice().drop_back(2), DeviceB5)); + Device.synchronousCopyD2D(DeviceA7.asSlice().drop_back(2), &DeviceB5)); for (int I = 0; I < 5; ++I) { EXPECT_EQ(getDeviceValue(DeviceA7, I), getDeviceValue(DeviceB5, I)); } EXPECT_ERROR( - Device.synchronousCopyD2D(DeviceA7.asSlice().drop_front(1), DeviceB5)); + Device.synchronousCopyD2D(DeviceA7.asSlice().drop_front(1), &DeviceB5)); EXPECT_ERROR( - Device.synchronousCopyD2D(DeviceA5.asSlice().drop_back(1), DeviceB7)); + Device.synchronousCopyD2D(DeviceA5.asSlice().drop_back(1), &DeviceB7)); } TEST_F(DeviceTest, SyncCopyD2DSliceByCount) { Index: streamexecutor/lib/unittests/StreamTest.cpp =================================================================== --- streamexecutor/lib/unittests/StreamTest.cpp +++ streamexecutor/lib/unittests/StreamTest.cpp @@ -160,41 +160,41 @@ // H2D tests TEST_F(StreamTest, CopyH2DToArrayRefByCount) { - Stream.thenCopyH2D(ArrayRef(Host5), DeviceA5, 5); + Stream.thenCopyH2D(ArrayRef(Host5), &DeviceA5, 5); EXPECT_TRUE(Stream.isOK()); for (int I = 0; I < 5; ++I) { EXPECT_EQ(getDeviceValue(DeviceA5, I), Host5[I]); } - Stream.thenCopyH2D(ArrayRef(Host5), DeviceB5, 2); + Stream.thenCopyH2D(ArrayRef(Host5), &DeviceB5, 2); EXPECT_TRUE(Stream.isOK()); for (int I = 0; I < 2; ++I) { EXPECT_EQ(getDeviceValue(DeviceB5, I), Host5[I]); } - Stream.thenCopyH2D(ArrayRef(Host7), DeviceA5, 7); + Stream.thenCopyH2D(ArrayRef(Host7), &DeviceA5, 7); EXPECT_FALSE(Stream.isOK()); } TEST_F(StreamTest, CopyH2DToArrayRef) { - Stream.thenCopyH2D(ArrayRef(Host5), DeviceA5); + Stream.thenCopyH2D(ArrayRef(Host5), &DeviceA5); EXPECT_TRUE(Stream.isOK()); for (int I = 0; I < 5; ++I) { EXPECT_EQ(getDeviceValue(DeviceA5, I), Host5[I]); } - Stream.thenCopyH2D(ArrayRef(Host7), DeviceA5); + Stream.thenCopyH2D(ArrayRef(Host7), &DeviceA5); EXPECT_FALSE(Stream.isOK()); } TEST_F(StreamTest, CopyH2DToPointer) { - Stream.thenCopyH2D(Host5, DeviceA5, 5); + Stream.thenCopyH2D(Host5, &DeviceA5, 5); EXPECT_TRUE(Stream.isOK()); for (int I = 0; I < 5; ++I) { EXPECT_EQ(getDeviceValue(DeviceA5, I), Host5[I]); } - Stream.thenCopyH2D(Host7, DeviceA5, 7); + Stream.thenCopyH2D(Host7, &DeviceA5, 7); EXPECT_FALSE(Stream.isOK()); } @@ -242,59 +242,59 @@ // D2D tests TEST_F(StreamTest, CopyD2DByCount) { - Stream.thenCopyD2D(DeviceA5, DeviceB5, 5); + Stream.thenCopyD2D(DeviceA5, &DeviceB5, 5); EXPECT_TRUE(Stream.isOK()); for (int I = 0; I < 5; ++I) { EXPECT_EQ(getDeviceValue(DeviceA5, I), getDeviceValue(DeviceB5, I)); } - Stream.thenCopyD2D(DeviceA7, DeviceB7, 2); + Stream.thenCopyD2D(DeviceA7, &DeviceB7, 2); EXPECT_TRUE(Stream.isOK()); for (int I = 0; I < 2; ++I) { EXPECT_EQ(getDeviceValue(DeviceA7, I), getDeviceValue(DeviceB7, I)); } - Stream.thenCopyD2D(DeviceA7, DeviceB5, 7); + Stream.thenCopyD2D(DeviceA7, &DeviceB5, 7); EXPECT_FALSE(Stream.isOK()); } TEST_F(StreamTest, CopyD2D) { - Stream.thenCopyD2D(DeviceA5, DeviceB5); + Stream.thenCopyD2D(DeviceA5, &DeviceB5); EXPECT_TRUE(Stream.isOK()); for (int I = 0; I < 5; ++I) { EXPECT_EQ(getDeviceValue(DeviceA5, I), getDeviceValue(DeviceB5, I)); } - Stream.thenCopyD2D(DeviceA7, DeviceB5); + Stream.thenCopyD2D(DeviceA7, &DeviceB5); EXPECT_FALSE(Stream.isOK()); } TEST_F(StreamTest, CopySliceD2DByCount) { - Stream.thenCopyD2D(DeviceA5.asSlice().drop_front(1), DeviceB5, 4); + Stream.thenCopyD2D(DeviceA5.asSlice().drop_front(1), &DeviceB5, 4); EXPECT_TRUE(Stream.isOK()); for (int I = 0; I < 4; ++I) { EXPECT_EQ(getDeviceValue(DeviceA5, I + 1), getDeviceValue(DeviceB5, I)); } - Stream.thenCopyD2D(DeviceA7.asSlice().drop_back(1), DeviceB7, 2); + Stream.thenCopyD2D(DeviceA7.asSlice().drop_back(1), &DeviceB7, 2); EXPECT_TRUE(Stream.isOK()); for (int I = 0; I < 2; ++I) { EXPECT_EQ(getDeviceValue(DeviceA7, I), getDeviceValue(DeviceB7, I)); } - Stream.thenCopyD2D(DeviceA5.asSlice(), DeviceB5, 7); + Stream.thenCopyD2D(DeviceA5.asSlice(), &DeviceB5, 7); EXPECT_FALSE(Stream.isOK()); } TEST_F(StreamTest, CopySliceD2D) { - Stream.thenCopyD2D(DeviceA7.asSlice().drop_back(2), DeviceB5); + Stream.thenCopyD2D(DeviceA7.asSlice().drop_back(2), &DeviceB5); EXPECT_TRUE(Stream.isOK()); for (int I = 0; I < 5; ++I) { EXPECT_EQ(getDeviceValue(DeviceA7, I), getDeviceValue(DeviceB5, I)); } - Stream.thenCopyD2D(DeviceA5.asSlice().drop_back(1), DeviceB7); + Stream.thenCopyD2D(DeviceA5.asSlice().drop_back(1), &DeviceB7); EXPECT_FALSE(Stream.isOK()); }