提交 5f10ecbf 编写于 作者: W willzhang4a58

force found_cudnn=true


Former-commit-id: 30c0518e
上级 d58118df
...@@ -4,7 +4,6 @@ cmake_minimum_required(VERSION 3.5) ...@@ -4,7 +4,6 @@ cmake_minimum_required(VERSION 3.5)
option(BUILD_THIRD_PARTY "Build third party or oneflow" OFF) option(BUILD_THIRD_PARTY "Build third party or oneflow" OFF)
option(BUILD_RDMA "" ON) option(BUILD_RDMA "" ON)
option(BUILD_CUDA "" ON) option(BUILD_CUDA "" ON)
option(BUILD_CUDNN "" ON)
# Project # Project
if (BUILD_THIRD_PARTY) if (BUILD_THIRD_PARTY)
......
...@@ -130,8 +130,8 @@ endforeach() ...@@ -130,8 +130,8 @@ endforeach()
# build test # build test
if(BUILD_TESTING) if(BUILD_TESTING)
if(NOT BUILD_CUDA or NOT BUILD_CUDNN) if(NOT BUILD_CUDA)
message(FATAL_ERROR "BUILD_TESTING without BUILD_CUDA and BUILD_CUDNN") message(FATAL_ERROR "BUILD_TESTING without BUILD_CUDA")
endif() endif()
oneflow_add_executable(oneflow_testexe ${of_all_test_cc}) oneflow_add_executable(oneflow_testexe ${of_all_test_cc})
target_link_libraries(oneflow_testexe ${of_libs} ${oneflow_third_party_libs}) target_link_libraries(oneflow_testexe ${of_libs} ${oneflow_third_party_libs})
......
...@@ -27,14 +27,7 @@ if (BUILD_CUDA) ...@@ -27,14 +27,7 @@ if (BUILD_CUDA)
foreach(extra_cuda_lib ${extra_cuda_libs}) foreach(extra_cuda_lib ${extra_cuda_libs})
list(APPEND CUDA_LIBRARIES ${cuda_lib_dir}/${extra_cuda_lib}) list(APPEND CUDA_LIBRARIES ${cuda_lib_dir}/${extra_cuda_lib})
endforeach() endforeach()
endif()
if (BUILD_CUDNN)
if (NOT BUILD_CUDA)
message(FATAL_ERROR "BUILD_CUDNN without BUILD_CUDA")
endif()
find_package(CuDNN REQUIRED) find_package(CuDNN REQUIRED)
add_definitions(-DWITH_CUDNN)
endif() endif()
if (NOT WIN32) if (NOT WIN32)
......
...@@ -70,14 +70,9 @@ void Actor::InitDeviceCtx(const ThreadCtx&) { ...@@ -70,14 +70,9 @@ void Actor::InitDeviceCtx(const ThreadCtx&) {
} }
#ifdef WITH_CUDA #ifdef WITH_CUDA
case DeviceType::kGPU: { case DeviceType::kGPU: {
device_ctx_.reset(new CudaDeviceCtx(NewWorkStreamId(), device_ctx_.reset(new CudaDeviceCtx(
cuda_handle_.cuda_stream(), NewWorkStreamId(), cuda_handle_.cuda_stream(),
cuda_handle_.cublas_handle() cuda_handle_.cublas_handle(), cuda_handle_.cudnn_handle()));
#ifdef WITH_CUDNN
,
cuda_handle_.cudnn_handle()
#endif
));
break; break;
} }
#endif #endif
......
...@@ -163,12 +163,6 @@ inline double GetCurTime() { ...@@ -163,12 +163,6 @@ inline double GetCurTime() {
size_t GetAvailableCpuMemSize(); size_t GetAvailableCpuMemSize();
inline void CheckUseCudnn(bool val) {
#ifndef WITH_CUDNN
CHECK_EQ(val, false) << "Please compile ONEFLOW with CUDNN";
#endif
}
} // namespace oneflow } // namespace oneflow
#endif // ONEFLOW_CORE_COMMON_UTIL_H_ #endif // ONEFLOW_CORE_COMMON_UTIL_H_
...@@ -14,19 +14,14 @@ class CudaDeviceCtx final : public DeviceCtx { ...@@ -14,19 +14,14 @@ class CudaDeviceCtx final : public DeviceCtx {
~CudaDeviceCtx() = default; ~CudaDeviceCtx() = default;
CudaDeviceCtx(int64_t work_stream_id, const cudaStream_t* cuda_stream, CudaDeviceCtx(int64_t work_stream_id, const cudaStream_t* cuda_stream,
const cublasHandle_t* cublas_handle = nullptr const cublasHandle_t* cublas_handle = nullptr,
#ifdef WITH_CUDNN
,
const cudnnHandle_t* cudnn_handle = nullptr const cudnnHandle_t* cudnn_handle = nullptr
#endif
) { ) {
set_work_stream_id(work_stream_id); set_work_stream_id(work_stream_id);
set_cuda_stream(cuda_stream); set_cuda_stream(cuda_stream);
set_cublas_handle(cublas_handle); set_cublas_handle(cublas_handle);
#ifdef WITH_CUDNN
set_cudnn_handle(cudnn_handle); set_cudnn_handle(cudnn_handle);
#endif
} }
void AddCallBack(std::function<void()> callback) const override; void AddCallBack(std::function<void()> callback) const override;
......
...@@ -22,7 +22,6 @@ const cublasHandle_t* CudaStreamHandle::cublas_handle() { ...@@ -22,7 +22,6 @@ const cublasHandle_t* CudaStreamHandle::cublas_handle() {
return cublas_handle_.get(); return cublas_handle_.get();
} }
#ifdef WITH_CUDNN
const cudnnHandle_t* CudaStreamHandle::cudnn_handle() { const cudnnHandle_t* CudaStreamHandle::cudnn_handle() {
if (!cudnn_handle_) { if (!cudnn_handle_) {
cudnn_handle_.reset(new cudnnHandle_t); cudnn_handle_.reset(new cudnnHandle_t);
...@@ -31,12 +30,9 @@ const cudnnHandle_t* CudaStreamHandle::cudnn_handle() { ...@@ -31,12 +30,9 @@ const cudnnHandle_t* CudaStreamHandle::cudnn_handle() {
} }
return cudnn_handle_.get(); return cudnn_handle_.get();
} }
#endif // WITH_CUDNN
CudaStreamHandle::~CudaStreamHandle() { CudaStreamHandle::~CudaStreamHandle() {
#ifdef WITH_CUDNN
if (cudnn_handle_) { CudaCheck(cudnnDestroy(*cudnn_handle_)); } if (cudnn_handle_) { CudaCheck(cudnnDestroy(*cudnn_handle_)); }
#endif // WITH_CUDNN
if (cublas_handle_) { CudaCheck(cublasDestroy(*cublas_handle_)); } if (cublas_handle_) { CudaCheck(cublasDestroy(*cublas_handle_)); }
if (cuda_stream_) { CudaCheck(cudaStreamDestroy(*cuda_stream_)); } if (cuda_stream_) { CudaCheck(cudaStreamDestroy(*cuda_stream_)); }
} }
......
...@@ -14,19 +14,14 @@ class CudaStreamHandle final { ...@@ -14,19 +14,14 @@ class CudaStreamHandle final {
const cudaStream_t* cuda_stream(); const cudaStream_t* cuda_stream();
const cublasHandle_t* cublas_handle(); const cublasHandle_t* cublas_handle();
#ifdef WITH_CUDNN
const cudnnHandle_t* cudnn_handle(); const cudnnHandle_t* cudnn_handle();
#endif
~CudaStreamHandle(); ~CudaStreamHandle();
private: private:
std::unique_ptr<cudaStream_t> cuda_stream_; std::unique_ptr<cudaStream_t> cuda_stream_;
std::unique_ptr<cublasHandle_t> cublas_handle_; std::unique_ptr<cublasHandle_t> cublas_handle_;
#ifdef WITH_CUDNN
std::unique_ptr<cudnnHandle_t> cudnn_handle_; std::unique_ptr<cudnnHandle_t> cudnn_handle_;
#endif
}; };
#endif // WITH_CUDA #endif // WITH_CUDA
......
...@@ -59,12 +59,10 @@ void CudaCheck(cudaError_t error) { ...@@ -59,12 +59,10 @@ void CudaCheck(cudaError_t error) {
CHECK_EQ(error, cudaSuccess) << cudaGetErrorString(error); CHECK_EQ(error, cudaSuccess) << cudaGetErrorString(error);
} }
#ifdef WITH_CUDNN
template<> template<>
void CudaCheck(cudnnStatus_t error) { void CudaCheck(cudnnStatus_t error) {
CHECK_EQ(error, CUDNN_STATUS_SUCCESS) << cudnnGetErrorString(error); CHECK_EQ(error, CUDNN_STATUS_SUCCESS) << cudnnGetErrorString(error);
} }
#endif // WITH_CUDNN
template<> template<>
void CudaCheck(cublasStatus_t error) { void CudaCheck(cublasStatus_t error) {
......
#ifdef WITH_CUDNN
#include "oneflow/core/device/cuda_util.h" #include "oneflow/core/device/cuda_util.h"
#include "oneflow/core/device/cudnn_util.h" #include "oneflow/core/device/cudnn_util.h"
...@@ -45,5 +43,3 @@ CudnnFilterDesc::CudnnFilterDesc(DataType data_type, const Shape& shape) ...@@ -45,5 +43,3 @@ CudnnFilterDesc::CudnnFilterDesc(DataType data_type, const Shape& shape)
} }
} // namespace oneflow } // namespace oneflow
#endif // WITH_CUDNN
#ifndef ONEFLOW_CORE_DEVICE_CUDNN_UTIL_H_ #ifndef ONEFLOW_CORE_DEVICE_CUDNN_UTIL_H_
#define ONEFLOW_CORE_DEVICE_CUDNN_UTIL_H_ #define ONEFLOW_CORE_DEVICE_CUDNN_UTIL_H_
#ifdef WITH_CUDNN
#include "cudnn.h" #include "cudnn.h"
#include "oneflow/core/common/data_type.h" #include "oneflow/core/common/data_type.h"
#include "oneflow/core/common/shape.h" #include "oneflow/core/common/shape.h"
...@@ -63,6 +61,4 @@ class CudnnFilterDesc final { ...@@ -63,6 +61,4 @@ class CudnnFilterDesc final {
} // namespace oneflow } // namespace oneflow
#endif // WITH_CUDNN
#endif // ONEFLOW_CORE_DEVICE_CUDNN_UTIL_H_ #endif // ONEFLOW_CORE_DEVICE_CUDNN_UTIL_H_
...@@ -15,9 +15,7 @@ class DeviceCtx { ...@@ -15,9 +15,7 @@ class DeviceCtx {
#ifdef WITH_CUDA #ifdef WITH_CUDA
const cudaStream_t& cuda_stream() const { return *cuda_stream_; } const cudaStream_t& cuda_stream() const { return *cuda_stream_; }
const cublasHandle_t& cublas_handle() const { return *cublas_handle_; } const cublasHandle_t& cublas_handle() const { return *cublas_handle_; }
#ifdef WITH_CUDNN
const cudnnHandle_t& cudnn_handle() const { return *cudnn_handle_; } const cudnnHandle_t& cudnn_handle() const { return *cudnn_handle_; }
#endif
#endif #endif
virtual void AddCallBack(std::function<void()>) const = 0; virtual void AddCallBack(std::function<void()>) const = 0;
...@@ -28,11 +26,8 @@ class DeviceCtx { ...@@ -28,11 +26,8 @@ class DeviceCtx {
#ifdef WITH_CUDA #ifdef WITH_CUDA
, ,
cuda_stream_(nullptr), cuda_stream_(nullptr),
cublas_handle_(nullptr) cublas_handle_(nullptr),
#ifdef WITH_CUDNN
,
cudnn_handle_(nullptr) cudnn_handle_(nullptr)
#endif
#endif #endif
{ {
} }
...@@ -42,9 +37,7 @@ class DeviceCtx { ...@@ -42,9 +37,7 @@ class DeviceCtx {
#ifdef WITH_CUDA #ifdef WITH_CUDA
void set_cuda_stream(const cudaStream_t* val) { cuda_stream_ = val; } void set_cuda_stream(const cudaStream_t* val) { cuda_stream_ = val; }
void set_cublas_handle(const cublasHandle_t* val) { cublas_handle_ = val; } void set_cublas_handle(const cublasHandle_t* val) { cublas_handle_ = val; }
#ifdef WITH_CUDNN
void set_cudnn_handle(const cudnnHandle_t* val) { cudnn_handle_ = val; } void set_cudnn_handle(const cudnnHandle_t* val) { cudnn_handle_ = val; }
#endif
#endif #endif
private: private:
...@@ -52,10 +45,8 @@ class DeviceCtx { ...@@ -52,10 +45,8 @@ class DeviceCtx {
#ifdef WITH_CUDA #ifdef WITH_CUDA
const cudaStream_t* cuda_stream_; const cudaStream_t* cuda_stream_;
const cublasHandle_t* cublas_handle_; const cublasHandle_t* cublas_handle_;
#ifdef WITH_CUDNN
const cudnnHandle_t* cudnn_handle_; const cudnnHandle_t* cudnn_handle_;
#endif #endif
#endif
}; };
} // namespace oneflow } // namespace oneflow
......
...@@ -44,7 +44,7 @@ message JobConf { ...@@ -44,7 +44,7 @@ message JobConf {
optional string model_load_snapshot_path = 7 [default = ""]; optional string model_load_snapshot_path = 7 [default = ""];
optional int32 max_data_id_length = 8 [default = 0]; optional int32 max_data_id_length = 8 [default = 0];
optional bool use_rdma = 9 [default = false]; optional bool use_rdma = 9 [default = false];
optional bool use_cudnn_on_gpu = 10; optional bool use_cudnn_on_gpu = 10 [default = true];
optional DataType default_data_type = 100 [default = kFloat]; // kFloat or kDouble optional DataType default_data_type = 100 [default = kFloat]; // kFloat or kDouble
optional int64 piece_num_of_experiment_phase = 101 [default = 100]; optional int64 piece_num_of_experiment_phase = 101 [default = 100];
......
...@@ -75,14 +75,6 @@ JobDesc::JobDesc(const JobDescProto& job_desc) { ...@@ -75,14 +75,6 @@ JobDesc::JobDesc(const JobDescProto& job_desc) {
#ifndef WITH_RDMA #ifndef WITH_RDMA
CHECK_EQ(job_conf_.use_rdma(), false) << "Please compile ONEFLOW with RDMA"; CHECK_EQ(job_conf_.use_rdma(), false) << "Please compile ONEFLOW with RDMA";
#endif #endif
if (job_conf_.has_use_cudnn_on_gpu() == false) {
#ifdef WITH_CUDNN
job_conf_.set_use_cudnn_on_gpu(true);
#else
job_conf_.set_use_cudnn_on_gpu(false);
#endif
}
CheckUseCudnn(job_conf_.use_cudnn_on_gpu());
int64_t piece_experiment = job_conf_.piece_num_of_experiment_phase(); int64_t piece_experiment = job_conf_.piece_num_of_experiment_phase();
if (job_conf_.has_train_conf()) { if (job_conf_.has_train_conf()) {
const TrainConf& train_conf = job_conf_.train_conf(); const TrainConf& train_conf = job_conf_.train_conf();
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
namespace oneflow { namespace oneflow {
#if defined(WITH_CUDA) && defined(WITH_CUDNN) #if defined(WITH_CUDA)
namespace test { namespace test {
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
namespace oneflow { namespace oneflow {
#if defined(WITH_CUDA) && defined(WITH_CUDNN) #if defined(WITH_CUDA)
namespace test { namespace test {
......
...@@ -21,7 +21,6 @@ void Operator::InitFromOpConf(const OperatorConf& op_conf) { ...@@ -21,7 +21,6 @@ void Operator::InitFromOpConf(const OperatorConf& op_conf) {
if (op_conf_.has_use_cudnn_on_gpu() == false) { if (op_conf_.has_use_cudnn_on_gpu() == false) {
op_conf_.set_use_cudnn_on_gpu(JobDesc::Singleton()->UseCudnn()); op_conf_.set_use_cudnn_on_gpu(JobDesc::Singleton()->UseCudnn());
} }
CheckUseCudnn(op_conf_.use_cudnn_on_gpu());
InitFromOpConf(); InitFromOpConf();
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册