Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Fix mshadow broken basic_stream example #17373

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions 3rdparty/mshadow/guide/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
27 changes: 15 additions & 12 deletions 3rdparty/mshadow/guide/basic_stream.cu
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,30 @@ int main(void) {
// intialize tensor engine before using tensor operation, needed for CuBLAS
InitTensorEngine<gpu>();
// create a 2 x 5 tensor, from existing space
Stream<gpu> *sm1 = NewStream<gpu>();
Stream<gpu> *sm2 = NewStream<gpu>();
Tensor<gpu, 2, float> ts1 = NewTensor<gpu, float>(Shape2(2, 5), 0.0f, sm1);
Tensor<gpu, 2, float> ts2 = NewTensor<gpu, float>(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<gpu, 2> res = NewTensor<gpu, float>(Shape2(2, 2), 0.0f);
res.stream_ = NewStream<gpu>();
res = dot(ts1, ts2.T()); //Should use stream 2.
Stream<gpu> *sm1 = NewStream<gpu>(0);
Stream<gpu> *sm2 = NewStream<gpu>(0);
Tensor<gpu, 2, float> ts1 =
NewTensor<gpu, float>(Shape2(2, 5), 0.0f, false, sm1);
Tensor<gpu, 2, float> ts2 =
NewTensor<gpu, float>(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<gpu> *sm3 = NewStream<gpu>(0);
Tensor<gpu, 2> res = NewTensor<gpu, float>(Shape2(2, 2), 0.0f, false, sm3);
res = dot(ts1, ts2.T()); // Should use stream 3.

Tensor<cpu, 2> cpu_res = NewTensor<cpu, float>(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");
}
// shutdown tensor enigne after usage
DeleteStream(sm1);
DeleteStream(sm2);
DeleteStream(sm3);
ShutdownTensorEngine<gpu>();
return 0;
}
1 change: 1 addition & 0 deletions 3rdparty/mshadow/make/mshadow.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down