diff --git a/paddle/fluid/operators/conv_op.cc b/paddle/fluid/operators/conv_op.cc index 7e8a94c9e506dc72a4439868f6e9ec63f4a17bf0..514fde453bbfdbd93ed2a9daec002f2f2857ff1e 100644 --- a/paddle/fluid/operators/conv_op.cc +++ b/paddle/fluid/operators/conv_op.cc @@ -318,7 +318,7 @@ void Conv2DOpMaker::Make() { "allocated/freed each time the operator runs, larger " "workspace size can increase performance but also requires " "better hardware. This size should be chosen carefully.") - .SetDefault(platform::kDefaultConvWorkspaceSizeLimitMB); + .SetDefault(platform::GetDefaultConvWorkspaceSizeLimitMB()); AddAttr("exhaustive_search", "(bool, default false) cuDNN has many algorithm to calculation " "convolution, whether enable exhaustive search " @@ -455,7 +455,7 @@ void Conv3DOpMaker::Make() { "allocated/freed each time the operator runs, larger " "workspace size can increase performance but also requires " "better hardware. This size should be chosen carefully.") - .SetDefault(platform::kDefaultConvWorkspaceSizeLimitMB); + .SetDefault(platform::GetDefaultConvWorkspaceSizeLimitMB()); AddAttr("exhaustive_search", "(bool, default false) cuDNN has many algorithm to calculation " "convolution, whether enable exhaustive search " diff --git a/paddle/fluid/operators/conv_transpose_op.cc b/paddle/fluid/operators/conv_transpose_op.cc index f0962a74b005c9f11ff39c1e28b30eec4d6b007e..6dddd4848e3e4870bfcc3051fd7cd0b90feb3ae8 100644 --- a/paddle/fluid/operators/conv_transpose_op.cc +++ b/paddle/fluid/operators/conv_transpose_op.cc @@ -222,7 +222,7 @@ void Conv2DTransposeOpMaker::Make() { "allocated/freed each time the operator runs, larger " "workspace size can increase performance but also requires " "better hardward. This size should be carefully setted.") - .SetDefault(platform::kDefaultConvWorkspaceSizeLimitMB); + .SetDefault(platform::GetDefaultConvWorkspaceSizeLimitMB()); AddComment(R"DOC( Convolution2D Transpose Operator. @@ -323,7 +323,7 @@ void Conv3DTransposeOpMaker::Make() { "allocated/freed each time the operator runs, larger " "workspace size can increase performance but also requires " "better hardward. This size should be carefully setted.") - .SetDefault(platform::kDefaultConvWorkspaceSizeLimitMB); + .SetDefault(platform::GetDefaultConvWorkspaceSizeLimitMB()); AddComment(R"DOC( Convolution3D Transpose Operator. diff --git a/paddle/fluid/operators/fused/fusion_conv_inception_op.cc b/paddle/fluid/operators/fused/fusion_conv_inception_op.cc index 80cc0eb8cb6f6961e8e6a284ac50c9de35d6e36d..964335ed2bc8df5e26eee3d1e1ae2b88bcbf25d9 100644 --- a/paddle/fluid/operators/fused/fusion_conv_inception_op.cc +++ b/paddle/fluid/operators/fused/fusion_conv_inception_op.cc @@ -96,7 +96,7 @@ class ConvInceptionFusionOpMaker : public framework::OpProtoAndCheckerMaker { "allocated/freed each time the operator runs, larger " "workspace size can increase performance but also requires " "better hardware. This size should be chosen carefully.") - .SetDefault(platform::kDefaultConvWorkspaceSizeLimitMB); + .SetDefault(platform::GetDefaultConvWorkspaceSizeLimitMB()); AddComment(R"DOC( )DOC"); } diff --git a/paddle/fluid/platform/CMakeLists.txt b/paddle/fluid/platform/CMakeLists.txt index 001fcfea422686ca34a84c76c0685f6a8292e7a8..744b4964874347e299730a124b32f969108eef31 100644 --- a/paddle/fluid/platform/CMakeLists.txt +++ b/paddle/fluid/platform/CMakeLists.txt @@ -68,11 +68,13 @@ ELSE() set(STREAM_CALLBACK_DEPS) ENDIF() +cc_library(cudnn_workspace_helper SRCS cudnn_workspace_helper.cc DEPS boost) + # memcpy depends on device_context, here add deps individually for # avoiding cycle dependencies cc_library(device_context SRCS device_context.cc init.cc DEPS simple_threadpool malloc xxhash ${STREAM_CALLBACK_DEPS} place eigen3 stringpiece cpu_helper cpu_info framework_proto ${GPU_CTX_DEPS} ${MKLDNN_CTX_DEPS} - ${dgc_deps} dlpack) + ${dgc_deps} dlpack cudnn_workspace_helper) if (WITH_DISTRIBUTE) cc_library(collective_helper SRCS collective_helper.cc DEPS framework_proto device_context enforce) diff --git a/paddle/fluid/platform/cudnn_workspace_helper.cc b/paddle/fluid/platform/cudnn_workspace_helper.cc new file mode 100644 index 0000000000000000000000000000000000000000..c65f3708de5ff03f84ca743dc24795694ff71b29 --- /dev/null +++ b/paddle/fluid/platform/cudnn_workspace_helper.cc @@ -0,0 +1,35 @@ +// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "paddle/fluid/platform/cudnn_workspace_helper.h" +#include +#include +#include "boost/lexical_cast.hpp" + +namespace paddle { +namespace platform { + +static int GetDefaultConvWorkspaceSizeLimitMBImpl() { + const char *env_str = std::getenv("FLAGS_conv_workspace_size_limit"); + return env_str ? boost::lexical_cast(std::string(env_str)) + : kDefaultConvWorkspaceSizeLimitMB; +} + +int GetDefaultConvWorkspaceSizeLimitMB() { + static auto workspace_size = GetDefaultConvWorkspaceSizeLimitMBImpl(); + return workspace_size; +} + +} // namespace platform +} // namespace paddle diff --git a/paddle/fluid/platform/cudnn_workspace_helper.h b/paddle/fluid/platform/cudnn_workspace_helper.h index 29abdc72e264b3676dec29c6be3fd8c4e1510dfe..766dbe113c33705d54ce9e25aae5c20ecaf2a068 100644 --- a/paddle/fluid/platform/cudnn_workspace_helper.h +++ b/paddle/fluid/platform/cudnn_workspace_helper.h @@ -19,5 +19,7 @@ namespace platform { static constexpr int kDefaultConvWorkspaceSizeLimitMB = 512; +int GetDefaultConvWorkspaceSizeLimitMB(); + } // namespace platform } // namespace paddle