Skip to content

Commit

Permalink
Fixed compile on GPU
Browse files Browse the repository at this point in the history
Former-commit-id: 3a93e2b
  • Loading branch information
neubig committed Jul 10, 2017
1 parent c1d0a56 commit 786d3a2
Show file tree
Hide file tree
Showing 30 changed files with 118 additions and 9 deletions.
45 changes: 42 additions & 3 deletions dynet/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,46 @@ if(ENABLE_BOOST)
list(APPEND dynet_library_HDRS mp.h)
endif()

set(dynet_gpu_SRCS
cuda.cc
cudnn-ops.cu
gpu-ops.cu
gpu-nodes-activations.cu
gpu-nodes-affinetransform.cu
gpu-nodes-arith-const.cu
gpu-nodes-arith-cwise.cu
gpu-nodes-arith-scalar.cu
gpu-nodes-arith-sum.cu
gpu-nodes-arith-unary.cu
gpu-nodes-concat.cu
gpu-nodes-const.cu
gpu-nodes-contract.cu
gpu-nodes-conv2d.cu
gpu-nodes-conv.cu
gpu-nodes-dropout.cu
gpu-nodes-flow.cu
gpu-nodes-hinge.cu
gpu-nodes-linalg.cu
gpu-nodes-logsumexp.cu
gpu-nodes-losses.cu
gpu-nodes-matrixmultiply.cu
gpu-nodes-maxpooling2d.cu
gpu-nodes-minmax.cu
gpu-nodes-moments.cu
gpu-nodes-normalization.cu
gpu-nodes-norms.cu
gpu-nodes-pickneglogsoftmax.cu
gpu-nodes-random.cu
gpu-nodes-select.cu
gpu-nodes-similarities.cu
gpu-nodes-softmaxes.cu
gpu-nodes-trig.cu
gpu-param-nodes.cu
gpu-tensor.cu
gpu-training.cu
gpu-model.cu
)

file(GLOB TEST_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} tests/*.cc)
if (NOT MSVC)
set(BUILD_SHARED_LIBS ON)
Expand Down Expand Up @@ -175,10 +215,10 @@ if(WITH_CUDA_BACKEND)
list(APPEND CUDA_NVCC_FLAGS_DEBUG "--compiler-options \"/MDd\"")
list(APPEND CUDA_NVCC_FLAGS_RELEASE "--compiler-options \"/MD\"")
SET(CUDA_PROPAGATE_HOST_FLAGS OFF)
cuda_add_library(gdynet ${dynet_library_SRCS} ${dynet_library_HDRS} cuda.cc cudnn-ops.cu gpu-ops.cu gpu-nodes.cu gpu-nodes-contract.cu gpu-nodes-conv.cu gpu-nodes-conv2d.cu gpu-nodes-maxpooling2d.cu gpu-param-nodes.cu gpu-tensor.cu gpu-training.cu gpu-model.cu gpu-nodes-pickneglogsoftmax.cu gpu-nodes-matrixmultiply.cu gpu-nodes-hinge.cu gpu-nodes-affinetransform.cu gpu-nodes-similarities.cu gpu-nodes-norms.cu gpu-nodes-unary-arith.cu)
cuda_add_library(gdynet ${dynet_library_SRCS} ${dynet_library_HDRS} ${dynet_gpu_SRCS})
else()
SET(CUDA_PROPAGATE_HOST_FLAGS OFF)
cuda_add_library(gdynet ${dynet_library_SRCS} ${dynet_library_HDRS} cuda.cc cudnn-ops.cu gpu-ops.cu gpu-nodes.cu gpu-nodes-contract.cu gpu-nodes-conv.cu gpu-nodes-conv2d.cu gpu-nodes-maxpooling2d.cu gpu-param-nodes.cu gpu-tensor.cu gpu-training.cu gpu-model.cu gpu-nodes-pickneglogsoftmax.cu gpu-nodes-matrixmultiply.cu gpu-nodes-hinge.cu gpu-nodes-affinetransform.cu gpu-nodes-similarities.cu gpu-nodes-norms.cu gpu-nodes-unary-arith.cu OPTIONS --compiler-options "-fPIC")
cuda_add_library(gdynet ${dynet_library_SRCS} ${dynet_library_HDRS} ${dynet_gpu_SRCS} OPTIONS --compiler-options "-fPIC")
endif()
set_target_properties(gdynet PROPERTIES
COMPILE_DEFINITIONS HAVE_CUDA)
Expand All @@ -197,4 +237,3 @@ if(WITH_CUDA_BACKEND)
endif(WITH_CUDA_BACKEND)

# target_compile_features(dynet PRIVATE cxx_range_for)

3 changes: 3 additions & 0 deletions dynet/gpu-nodes-activations.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This is a dummy file that contains the same content as nodes.cc but compiled
// on CUDA
#include "nodes-activations.cc"
3 changes: 3 additions & 0 deletions dynet/gpu-nodes-arith-const.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This is a dummy file that contains the same content as nodes.cc but compiled
// on CUDA
#include "nodes-arith-const.cc"
3 changes: 3 additions & 0 deletions dynet/gpu-nodes-arith-cwise.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This is a dummy file that contains the same content as nodes.cc but compiled
// on CUDA
#include "nodes-arith-cwise.cc"
3 changes: 3 additions & 0 deletions dynet/gpu-nodes-arith-scalar.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This is a dummy file that contains the same content as nodes.cc but compiled
// on CUDA
#include "nodes-arith-scalar.cc"
3 changes: 3 additions & 0 deletions dynet/gpu-nodes-arith-sum.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This is a dummy file that contains the same content as nodes.cc but compiled
// on CUDA
#include "nodes-arith-sum.cc"
2 changes: 1 addition & 1 deletion dynet/gpu-nodes-arith-unary.cu
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// This is a dummy file that contains the same content as nodes-unary-arith.cc but compiled
// This is a dummy file that contains the same content as nodes.cc but compiled
// on CUDA
#include "nodes-arith-unary.cc"
3 changes: 3 additions & 0 deletions dynet/gpu-nodes-concat.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This is a dummy file that contains the same content as nodes.cc but compiled
// on CUDA
#include "nodes-concat.cc"
3 changes: 3 additions & 0 deletions dynet/gpu-nodes-const.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This is a dummy file that contains the same content as nodes.cc but compiled
// on CUDA
#include "nodes-const.cc"
2 changes: 1 addition & 1 deletion dynet/gpu-nodes-conv.cu
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// This is a dummy file that contains the same content as nodes-conv.cc but compiled
// This is a dummy file that contains the same content as nodes.cc but compiled
// on CUDA
#include "nodes-conv.cc"
2 changes: 2 additions & 0 deletions dynet/gpu-nodes-conv2d.cu
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
// This is a dummy file that contains the same content as nodes.cc but compiled
// on CUDA
#include "nodes-conv2d.cc"
3 changes: 3 additions & 0 deletions dynet/gpu-nodes-dropout.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This is a dummy file that contains the same content as nodes.cc but compiled
// on CUDA
#include "nodes-dropout.cc"
3 changes: 3 additions & 0 deletions dynet/gpu-nodes-flow.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This is a dummy file that contains the same content as nodes.cc but compiled
// on CUDA
#include "nodes-flow.cc"
3 changes: 3 additions & 0 deletions dynet/gpu-nodes-linalg.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This is a dummy file that contains the same content as nodes.cc but compiled
// on CUDA
#include "nodes-linalg.cc"
3 changes: 3 additions & 0 deletions dynet/gpu-nodes-logsumexp.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This is a dummy file that contains the same content as nodes.cc but compiled
// on CUDA
#include "nodes-logsumexp.cc"
3 changes: 3 additions & 0 deletions dynet/gpu-nodes-losses.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This is a dummy file that contains the same content as nodes.cc but compiled
// on CUDA
#include "nodes-losses.cc"
2 changes: 2 additions & 0 deletions dynet/gpu-nodes-maxpooling2d.cu
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
// This is a dummy file that contains the same content as nodes.cc but compiled
// on CUDA
#include "nodes-maxpooling2d.cc"
3 changes: 3 additions & 0 deletions dynet/gpu-nodes-minmax.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This is a dummy file that contains the same content as nodes.cc but compiled
// on CUDA
#include "nodes-minmax.cc"
3 changes: 3 additions & 0 deletions dynet/gpu-nodes-moments.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This is a dummy file that contains the same content as nodes.cc but compiled
// on CUDA
#include "nodes-moments.cc"
3 changes: 3 additions & 0 deletions dynet/gpu-nodes-normalization.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This is a dummy file that contains the same content as nodes.cc but compiled
// on CUDA
#include "nodes-normalization.cc"
2 changes: 1 addition & 1 deletion dynet/gpu-nodes-norms.cu
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// This is a dummy file that contains the same content as nodes-norms.cc but compiled
// This is a dummy file that contains the same content as nodes.cc but compiled
// on CUDA
#include "nodes-norms.cc"
3 changes: 3 additions & 0 deletions dynet/gpu-nodes-random.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This is a dummy file that contains the same content as nodes.cc but compiled
// on CUDA
#include "nodes-random.cc"
3 changes: 3 additions & 0 deletions dynet/gpu-nodes-select.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This is a dummy file that contains the same content as nodes.cc but compiled
// on CUDA
#include "nodes-select.cc"
2 changes: 1 addition & 1 deletion dynet/gpu-nodes-similarities.cu
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// This is a dummy file that contains the same content as nodes-similarities.cc but compiled
// This is a dummy file that contains the same content as nodes.cc but compiled
// on CUDA
#include "nodes-similarities.cc"
3 changes: 3 additions & 0 deletions dynet/gpu-nodes-softmaxes.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This is a dummy file that contains the same content as nodes.cc but compiled
// on CUDA
#include "nodes-softmaxes.cc"
3 changes: 3 additions & 0 deletions dynet/gpu-nodes-trig.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This is a dummy file that contains the same content as nodes.cc but compiled
// on CUDA
#include "nodes-trig.cc"
1 change: 1 addition & 0 deletions dynet/nodes-conv2d.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#if HAVE_CUDA
#include "dynet/cuda.h"
#include "dynet/gpu-ops.h"
#include "dynet/cudnn-ops.h"
#endif

using namespace std;
Expand Down
4 changes: 4 additions & 0 deletions dynet/nodes-conv2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#include "dynet/dynet.h"
#include "dynet/nodes-macros.h"

#if HAVE_CUDNN
#include "dynet/cudnn-ops.h"
#endif

namespace dynet {

// conv2d
Expand Down
4 changes: 2 additions & 2 deletions dynet/nodes-losses.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Dim PairwiseRankLoss::dim_forward(const vector<Dim>& xs) const {
return xs[0].bd >= xs[1].bd ? xs[0] : xs[1];
}

#endif

template<class MyDevice>
void PairwiseRankLoss::forward_dev_impl(const MyDevice & dev, const vector<const Tensor*>& xs, Tensor& fx) const {
fx.tvec().device(*dev.edevice) = xs[0]->tvec().binaryExpr(xs[1]->tvec(), FPairwiseRankLoss(margin));
Expand All @@ -46,8 +48,6 @@ void PairwiseRankLoss::backward_dev_impl(const MyDevice & dev,
}
DYNET_NODE_INST_DEV_IMPL(PairwiseRankLoss)

#endif

// ************* BinaryLogLoss *************

#ifndef __CUDACC__
Expand Down
4 changes: 4 additions & 0 deletions dynet/nodes-maxpooling2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#include "dynet/dynet.h"
#include "dynet/nodes-macros.h"

#if HAVE_CUDNN
#include "dynet/cudnn-ops.h"
#endif

namespace dynet {

// maxpooling2d
Expand Down

0 comments on commit 786d3a2

Please sign in to comment.