From 4922eb6da5b651f4457f9ebf526a065e68de0e65 Mon Sep 17 00:00:00 2001 From: Zeng Jinle <32832641+sneaxiy@users.noreply.github.com> Date: Wed, 16 Oct 2019 22:37:13 +0800 Subject: [PATCH] make_conv_workspace_size_configurable, test=develop (#20662) --- paddle/fluid/operators/conv_op.cc | 4 +-- paddle/fluid/operators/conv_transpose_op.cc | 4 +-- .../fused/fusion_conv_inception_op.cc | 2 +- paddle/fluid/platform/CMakeLists.txt | 4 ++- .../fluid/platform/cudnn_workspace_helper.cc | 35 +++++++++++++++++++ .../fluid/platform/cudnn_workspace_helper.h | 2 ++ 6 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 paddle/fluid/platform/cudnn_workspace_helper.cc diff --git a/paddle/fluid/operators/conv_op.cc b/paddle/fluid/operators/conv_op.cc index 7e8a94c9e5..514fde453b 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 f0962a74b0..6dddd4848e 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 80cc0eb8cb..964335ed2b 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 001fcfea42..744b496487 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 0000000000..c65f3708de --- /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 29abdc72e2..766dbe113c 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 -- GitLab