Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
Merge pull request #18 from SiNZeRo/master
Browse files Browse the repository at this point in the history
Thanks! This is very helpful! I noticed that only change of Makefile is needed. 
BTW I am working on a refactored version of mshadow and it is comming soon. 

https://github.com/tqchen/mshadow/tree/refactor

It would be great if you like to try it out latter
  • Loading branch information
tqchen committed Dec 28, 2014
2 parents c87fa59 + 5bdd59d commit 843e51d
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 0 deletions.
37 changes: 37 additions & 0 deletions example/Makefile.openblas
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# set LD_LIBRARY_PATH
# echo "Link mshadow with precomplied Openblas"
export OPENBLAS_ROOT=../../OpenBLAS-v0.2.13-Win64-int32
export CC = gcc
export CXX = g++
export NVCC =nvcc
export CFLAGS = -Wall -O3 -msse3 -Wno-unknown-pragmas -funroll-loops -I../ -I$(OPENBLAS_ROOT)/include -DMSHADOW_USE_CUDA=0 -DMSHADOW_USE_MKL=0 -DMSHADOW_USE_CBLAS=1 -D__APPLE__
export LDFLAGS= -static -lpthread -lopenblas -L$(OPENBLAS_ROOT)/lib
export NVCCFLAGS = -O3 --use_fast_math -ccbin $(CXX)

# specify tensor path
BIN = basic defop basic-matrix-dot
OBJ =
CUOBJ =
CUBIN =
.PHONY: clean all

all: $(BIN) $(OBJ) $(CUBIN) $(CUOBJ)

basic: basic.cpp
defop: defop.cpp
basic-matrix-dot: basic-matrix-dot.cpp

$(BIN) :
$(CXX) $(CFLAGS) -o $@ $(filter %.cpp %.o %.c, $^) $(LDFLAGS)

$(OBJ) :
$(CXX) -c $(CFLAGS) -o $@ $(firstword $(filter %.cpp %.c, $^) )

$(CUOBJ) :
$(NVCC) -c -o $@ $(NVCCFLAGS) -Xcompiler "$(CFLAGS)" $(filter %.cu, $^)

$(CUBIN) :
$(NVCC) -o $@ $(NVCCFLAGS) -Xcompiler "$(CFLAGS)" -Xlinker "$(LDFLAGS)" $(filter %.cu %.cpp %.o, $^)

clean:
$(RM) $(OBJ) $(BIN) $(CUBIN) $(CUOBJ) *~
20 changes: 20 additions & 0 deletions example/basic-matrix-dot.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// header file to use mshadow
#include "mshadow/tensor.h"
// this namespace contains all data structures, functions
using namespace mshadow;
// this namespace contains all operator overloads
using namespace mshadow::expr;

int main( void ){
// intialize tensor engine before using tensor operation, needed for CuBLAS
InitTensorEngine();

Tensor<cpu,2> mat = NewTensor<cpu>( Shape2(1000,1000), 1.0 );
for (int i=0;i<100;i++)
mat = dot(mat, mat);
FreeSpace(mat);
// shutdown tensor enigne after usage

ShutdownTensorEngine();
return 0;
}
36 changes: 36 additions & 0 deletions example/neuralnet/Makefile.openblas
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# set LD_LIBRARY_PATH
# echo "Link mshadow with precomplied Openblas"
export OPENBLAS_ROOT=../../../OpenBLAS-v0.2.13-Win64-int32
export CC = gcc
export CXX = g++
export NVCC =nvcc
export CFLAGS = -Wall -O3 -msse3 -Wno-unknown-pragmas -funroll-loops -I../../ -I$(OPENBLAS_ROOT)/include -DMSHADOW_USE_CUDA=0 -DMSHADOW_USE_MKL=0 -DMSHADOW_USE_CBLAS=1 -D__APPLE__
export LDFLAGS= -static -lpthread -lopenblas -L$(OPENBLAS_ROOT)/lib
export NVCCFLAGS = -O3 --use_fast_math -ccbin $(CXX)

# specify tensor path
BIN = nnet convnet
OBJ =
CUOBJ =
CUBIN =
.PHONY: clean all

all: $(BIN) $(OBJ) $(CUBIN) $(CUOBJ)

nnet: nnet.cpp
convnet: convnet.cpp

$(BIN) :
$(CXX) $(CFLAGS) -o $@ $(filter %.cpp %.o %.c, $^) $(LDFLAGS)

$(OBJ) :
$(CXX) -c $(CFLAGS) -o $@ $(firstword $(filter %.cpp %.c, $^) )

$(CUOBJ) :
$(NVCC) -c -o $@ $(NVCCFLAGS) -Xcompiler "$(CFLAGS)" $(filter %.cu, $^)

$(CUBIN) :
$(NVCC) -o $@ $(NVCCFLAGS) -Xcompiler "$(CFLAGS)" -Xlinker "$(LDFLAGS)" $(filter %.cu %.cpp %.o, $^)

clean:
$(RM) $(OBJ) $(BIN) $(CUBIN) $(CUOBJ) *~
3 changes: 3 additions & 0 deletions example/neuralnet/build_openblash.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mv nnet.cu nnet.cpp
mv convnet.cu convnet.cpp
make -f Makefile.openblas
2 changes: 2 additions & 0 deletions example/neuralnet/convnet.cu
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ int main( int argc, char *argv[] ){
// choose which version to use
INNet *net;
if( !strcmp( argv[1], "gpu") ) {
#if DMSHADOW_USE_CUDA==1
net = new ConvNet<gpu>( batch_size, insize, nchannel, ksize, kstride, psize, num_out );
#endif
}else{
net = new ConvNet<cpu>( batch_size, insize, nchannel, ksize, kstride, psize, num_out );
}
Expand Down
2 changes: 2 additions & 0 deletions example/neuralnet/nnet.cu
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ int main( int argc, char *argv[] ){
// choose which version to use
INNet *net;
if( !strcmp( argv[1], "gpu") ) {
#if DMSHADOW_USE_CUDA==1
net = new NNet<gpu>( batch_size, num_in, num_hidden, num_out );
#endif
}else{
net = new NNet<cpu>( batch_size, num_in, num_hidden, num_out );
}
Expand Down

0 comments on commit 843e51d

Please sign in to comment.