Skip to content

Commit c054adf

Browse files
authored
make_conv_workspace_size_configurable, test=release/1.6 (#20664)
1 parent 06e35ae commit c054adf

File tree

6 files changed

+45
-6
lines changed

6 files changed

+45
-6
lines changed

paddle/fluid/operators/conv_op.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ void Conv2DOpMaker::Make() {
318318
"allocated/freed each time the operator runs, larger "
319319
"workspace size can increase performance but also requires "
320320
"better hardware. This size should be chosen carefully.")
321-
.SetDefault(platform::kDefaultConvWorkspaceSizeLimitMB);
321+
.SetDefault(platform::GetDefaultConvWorkspaceSizeLimitMB());
322322
AddAttr<bool>("exhaustive_search",
323323
"(bool, default false) cuDNN has many algorithm to calculation "
324324
"convolution, whether enable exhaustive search "
@@ -455,7 +455,7 @@ void Conv3DOpMaker::Make() {
455455
"allocated/freed each time the operator runs, larger "
456456
"workspace size can increase performance but also requires "
457457
"better hardware. This size should be chosen carefully.")
458-
.SetDefault(platform::kDefaultConvWorkspaceSizeLimitMB);
458+
.SetDefault(platform::GetDefaultConvWorkspaceSizeLimitMB());
459459
AddAttr<bool>("exhaustive_search",
460460
"(bool, default false) cuDNN has many algorithm to calculation "
461461
"convolution, whether enable exhaustive search "

paddle/fluid/operators/conv_transpose_op.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ void Conv2DTransposeOpMaker::Make() {
222222
"allocated/freed each time the operator runs, larger "
223223
"workspace size can increase performance but also requires "
224224
"better hardward. This size should be carefully setted.")
225-
.SetDefault(platform::kDefaultConvWorkspaceSizeLimitMB);
225+
.SetDefault(platform::GetDefaultConvWorkspaceSizeLimitMB());
226226
AddComment(R"DOC(
227227
Convolution2D Transpose Operator.
228228
@@ -323,7 +323,7 @@ void Conv3DTransposeOpMaker::Make() {
323323
"allocated/freed each time the operator runs, larger "
324324
"workspace size can increase performance but also requires "
325325
"better hardward. This size should be carefully setted.")
326-
.SetDefault(platform::kDefaultConvWorkspaceSizeLimitMB);
326+
.SetDefault(platform::GetDefaultConvWorkspaceSizeLimitMB());
327327
AddComment(R"DOC(
328328
Convolution3D Transpose Operator.
329329

paddle/fluid/operators/fused/fusion_conv_inception_op.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class ConvInceptionFusionOpMaker : public framework::OpProtoAndCheckerMaker {
9696
"allocated/freed each time the operator runs, larger "
9797
"workspace size can increase performance but also requires "
9898
"better hardware. This size should be chosen carefully.")
99-
.SetDefault(platform::kDefaultConvWorkspaceSizeLimitMB);
99+
.SetDefault(platform::GetDefaultConvWorkspaceSizeLimitMB());
100100
AddComment(R"DOC(
101101
)DOC");
102102
}

paddle/fluid/platform/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,13 @@ ELSE()
6868
set(STREAM_CALLBACK_DEPS)
6969
ENDIF()
7070

71+
cc_library(cudnn_workspace_helper SRCS cudnn_workspace_helper.cc DEPS boost)
72+
7173
# memcpy depends on device_context, here add deps individually for
7274
# avoiding cycle dependencies
7375
cc_library(device_context SRCS device_context.cc init.cc DEPS simple_threadpool malloc xxhash ${STREAM_CALLBACK_DEPS}
7476
place eigen3 stringpiece cpu_helper cpu_info framework_proto ${GPU_CTX_DEPS} ${MKLDNN_CTX_DEPS}
75-
${dgc_deps} dlpack)
77+
${dgc_deps} dlpack cudnn_workspace_helper)
7678

7779
if (WITH_DISTRIBUTE)
7880
cc_library(collective_helper SRCS collective_helper.cc DEPS framework_proto device_context enforce)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "paddle/fluid/platform/cudnn_workspace_helper.h"
16+
#include <cstdlib>
17+
#include <string>
18+
#include "boost/lexical_cast.hpp"
19+
20+
namespace paddle {
21+
namespace platform {
22+
23+
static int GetDefaultConvWorkspaceSizeLimitMBImpl() {
24+
const char *env_str = std::getenv("FLAGS_conv_workspace_size_limit");
25+
return env_str ? boost::lexical_cast<int>(std::string(env_str))
26+
: kDefaultConvWorkspaceSizeLimitMB;
27+
}
28+
29+
int GetDefaultConvWorkspaceSizeLimitMB() {
30+
static auto workspace_size = GetDefaultConvWorkspaceSizeLimitMBImpl();
31+
return workspace_size;
32+
}
33+
34+
} // namespace platform
35+
} // namespace paddle

paddle/fluid/platform/cudnn_workspace_helper.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,7 @@ namespace platform {
1919

2020
static constexpr int kDefaultConvWorkspaceSizeLimitMB = 512;
2121

22+
int GetDefaultConvWorkspaceSizeLimitMB();
23+
2224
} // namespace platform
2325
} // namespace paddle

0 commit comments

Comments
 (0)