From 42daf4c3020f358c6798cb90d87a320bc869737e Mon Sep 17 00:00:00 2001 From: dzhwinter Date: Tue, 9 Jan 2018 23:12:26 -0800 Subject: [PATCH 1/4] "add sync op" --- python/paddle/v2/fluid/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/paddle/v2/fluid/__init__.py b/python/paddle/v2/fluid/__init__.py index ccd5998e35..c163d9a92b 100644 --- a/python/paddle/v2/fluid/__init__.py +++ b/python/paddle/v2/fluid/__init__.py @@ -58,7 +58,7 @@ def __bootstrap__(): read_env_flags = ['use_pinned_memory', 'check_nan_inf'] if core.is_compile_gpu(): - read_env_flags.append('fraction_of_gpu_memory_to_use') + read_env_flags.append(['fraction_of_gpu_memory_to_use', 'op_sync']) core.init_gflags([sys.argv[0]] + ["--tryfromenv=" + ",".join(read_env_flags)]) core.init_glog(sys.argv[0]) From f0316bdbbd351cff24b49b9376fab9b56f962e3d Mon Sep 17 00:00:00 2001 From: dzhwinter Date: Tue, 9 Jan 2018 23:13:01 -0800 Subject: [PATCH 2/4] "add flags" --- paddle/framework/operator.cc | 10 ++++++++-- paddle/platform/gpu_info.cc | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/paddle/framework/operator.cc b/paddle/framework/operator.cc index 35ebe48ba6..c1a6d0221b 100644 --- a/paddle/framework/operator.cc +++ b/paddle/framework/operator.cc @@ -543,8 +543,14 @@ void OperatorWithKernel::Run(const Scope& scope, auto kernel_iter = kernels.find(expected_kernel_key); - kernel_iter->second->Compute(ExecutionContext( - *this, new_scope, *pool.Get(expected_kernel_key.place_))); + auto* new_dev_ctx = pool.Get(expected_kernel_key.place_); + kernel_iter->second->Compute( + ExecutionContext(*this, new_scope, *new_dev_ctx)); + + /*For profiling/benchmark only*/ + if (FLAGS_op_sync) { + new_dev_ctx->Wait(); + } } proto::DataType OperatorWithKernel::IndicateDataType( diff --git a/paddle/platform/gpu_info.cc b/paddle/platform/gpu_info.cc index 7037551d75..9d3147362a 100644 --- a/paddle/platform/gpu_info.cc +++ b/paddle/platform/gpu_info.cc @@ -22,6 +22,10 @@ DEFINE_double(fraction_of_gpu_memory_to_use, 0.92, "Default use 92% of GPU memory for PaddlePaddle," "reserve the rest for page tables, etc"); +DEFINE_bool(op_sync, false, + "Default cuda is asynchronous device, set to True will" + "force op run in synchronous mode."); + namespace paddle { namespace platform { From a6edc0389e11787c57aa1881ae01bebf025715f2 Mon Sep 17 00:00:00 2001 From: dzhwinter Date: Tue, 9 Jan 2018 23:19:22 -0800 Subject: [PATCH 3/4] "fix CI" --- paddle/framework/operator.cc | 5 +++++ paddle/platform/gpu_info.cc | 4 ---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/paddle/framework/operator.cc b/paddle/framework/operator.cc index c1a6d0221b..0f6071a69e 100644 --- a/paddle/framework/operator.cc +++ b/paddle/framework/operator.cc @@ -11,6 +11,7 @@ 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 #include #include @@ -22,6 +23,10 @@ limitations under the License. */ #include "paddle/framework/shape_inference.h" #include "paddle/framework/var_type.h" +DEFINE_bool(op_sync, false, + "Default cuda is asynchronous device, set to True will" + "force op run in synchronous mode."); + namespace paddle { namespace framework { diff --git a/paddle/platform/gpu_info.cc b/paddle/platform/gpu_info.cc index 9d3147362a..7037551d75 100644 --- a/paddle/platform/gpu_info.cc +++ b/paddle/platform/gpu_info.cc @@ -22,10 +22,6 @@ DEFINE_double(fraction_of_gpu_memory_to_use, 0.92, "Default use 92% of GPU memory for PaddlePaddle," "reserve the rest for page tables, etc"); -DEFINE_bool(op_sync, false, - "Default cuda is asynchronous device, set to True will" - "force op run in synchronous mode."); - namespace paddle { namespace platform { From 92eb247f07a47a6ed6af61d39d305935fb2fcd76 Mon Sep 17 00:00:00 2001 From: dzhwinter Date: Wed, 10 Jan 2018 19:13:29 -0800 Subject: [PATCH 4/4] "fix stupid error" --- python/paddle/v2/fluid/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/paddle/v2/fluid/__init__.py b/python/paddle/v2/fluid/__init__.py index c163d9a92b..422aa0a5ba 100644 --- a/python/paddle/v2/fluid/__init__.py +++ b/python/paddle/v2/fluid/__init__.py @@ -58,7 +58,7 @@ def __bootstrap__(): read_env_flags = ['use_pinned_memory', 'check_nan_inf'] if core.is_compile_gpu(): - read_env_flags.append(['fraction_of_gpu_memory_to_use', 'op_sync']) + read_env_flags += ['fraction_of_gpu_memory_to_use', 'op_sync'] core.init_gflags([sys.argv[0]] + ["--tryfromenv=" + ",".join(read_env_flags)]) core.init_glog(sys.argv[0])