From b3804505e202700f1403c4076e5e25f2e1864716 Mon Sep 17 00:00:00 2001 From: Tao Li Date: Sat, 18 Jan 2020 16:50:05 +0800 Subject: [PATCH] Fix mshadow broken basic_stream example. The NewTensor and NewStream API signature has changed the sample was not updated. --- 3rdparty/mshadow/guide/Makefile | 5 +++++ 3rdparty/mshadow/guide/basic_stream.cu | 27 ++++++++++++++------------ 3rdparty/mshadow/make/mshadow.mk | 1 + 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/3rdparty/mshadow/guide/Makefile b/3rdparty/mshadow/guide/Makefile index bad7a8e94b1d..38d153e77cd7 100644 --- a/3rdparty/mshadow/guide/Makefile +++ b/3rdparty/mshadow/guide/Makefile @@ -12,7 +12,12 @@ export NVCCFLAGS = -O3 --use_fast_math -ccbin $(CXX) $(MSHADOW_NVCCFLAGS) BIN = basic defop OBJ = CUOBJ = +ifeq ($(USE_CUDA), 1) +CUBIN = basic_stream +else CUBIN = +endif + .PHONY: clean all all: $(BIN) $(OBJ) $(CUBIN) $(CUOBJ) diff --git a/3rdparty/mshadow/guide/basic_stream.cu b/3rdparty/mshadow/guide/basic_stream.cu index 930fc54710f7..d7dda7564787 100644 --- a/3rdparty/mshadow/guide/basic_stream.cu +++ b/3rdparty/mshadow/guide/basic_stream.cu @@ -9,20 +9,22 @@ int main(void) { // intialize tensor engine before using tensor operation, needed for CuBLAS InitTensorEngine(); // create a 2 x 5 tensor, from existing space - Stream *sm1 = NewStream(); - Stream *sm2 = NewStream(); - Tensor ts1 = NewTensor(Shape2(2, 5), 0.0f, sm1); - Tensor ts2 = NewTensor(Shape2(2, 5), 0.0f, sm2); - ts1 = 1; // Should use stream 0. - ts2 = 2; // Should use stream 1. Can run in parallel with stream 0. - Tensor res = NewTensor(Shape2(2, 2), 0.0f); - res.stream_ = NewStream(); - res = dot(ts1, ts2.T()); //Should use stream 2. + Stream *sm1 = NewStream(0); + Stream *sm2 = NewStream(0); + Tensor ts1 = + NewTensor(Shape2(2, 5), 0.0f, false, sm1); + Tensor ts2 = + NewTensor(Shape2(2, 5), 0.0f, false, sm2); + ts1 = 1; // Should use stream 1. + ts2 = 2; // Should use stream 2. Can run in parallel with stream 1. + Stream *sm3 = NewStream(0); + Tensor res = NewTensor(Shape2(2, 2), 0.0f, false, sm3); + res = dot(ts1, ts2.T()); // Should use stream 3. Tensor cpu_res = NewTensor(Shape2(2, 2), 0.0f); - Copy(cpu_res, res); // default stream, should be 0. - for (index_t i = 0; i < cpu_res.size(0); ++i){ - for (index_t j = 0; j < cpu_res.size(1); ++j){ + Copy(cpu_res, res, sm3); + for (index_t i = 0; i < cpu_res.size(0); ++i) { + for (index_t j = 0; j < cpu_res.size(1); ++j) { printf("%.2f ", cpu_res[i][j]); } printf("\n"); @@ -30,6 +32,7 @@ int main(void) { // shutdown tensor enigne after usage DeleteStream(sm1); DeleteStream(sm2); + DeleteStream(sm3); ShutdownTensorEngine(); return 0; } diff --git a/3rdparty/mshadow/make/mshadow.mk b/3rdparty/mshadow/make/mshadow.mk index 86155eaaadcf..3694772cd35c 100644 --- a/3rdparty/mshadow/make/mshadow.mk +++ b/3rdparty/mshadow/make/mshadow.mk @@ -64,6 +64,7 @@ endif ifeq ($(USE_CUDA), 0) MSHADOW_CFLAGS += -DMSHADOW_USE_CUDA=0 else + MSHADOW_CFLAGS += -DMSHADOW_USE_CUDA=1 MSHADOW_LDFLAGS += -lcudart -lcublas -lcurand -lcusolver endif ifneq ($(USE_CUDA_PATH), NONE)