From bf8531f2b7e7c4e52f455d761700fac7e7f86844 Mon Sep 17 00:00:00 2001 From: Liangliang He Date: Mon, 18 Dec 2017 20:31:18 +0800 Subject: [PATCH] Fix opencl future nullptr issue --- mace/kernels/opencl/addn.cc | 14 ++++++++------ mace/kernels/opencl/batch_norm_opencl.cc | 14 ++++++++------ mace/kernels/opencl/bias_add_opencl.cc | 14 ++++++++------ mace/kernels/opencl/buffer_to_image.cc | 14 ++++++++------ mace/kernels/opencl/concat.cc | 14 ++++++++------ mace/kernels/opencl/conv_2d_opencl_1x1.cc | 14 ++++++++------ mace/kernels/opencl/conv_2d_opencl_3x3.cc | 14 ++++++++------ mace/kernels/opencl/conv_2d_opencl_general.cc | 14 ++++++++------ mace/kernels/opencl/depthwise_conv_opencl_3x3.cc | 14 ++++++++------ mace/kernels/opencl/pooling_opencl.cc | 14 ++++++++------ mace/kernels/opencl/relu_opencl.cc | 14 ++++++++------ mace/kernels/opencl/resize_bilinear_opencl.cc | 14 ++++++++------ mace/kernels/opencl/space_to_batch_opecl.cc | 14 ++++++++------ tools/bazel-adb-run.sh | 2 +- 14 files changed, 105 insertions(+), 79 deletions(-) diff --git a/mace/kernels/opencl/addn.cc b/mace/kernels/opencl/addn.cc index 837f6cd8..d138aca3 100644 --- a/mace/kernels/opencl/addn.cc +++ b/mace/kernels/opencl/addn.cc @@ -84,12 +84,14 @@ static void AddN(const std::vector &input_tensors, params_generator, func, &timer); - future->wait_fn = [runtime, event](CallStats *stats) { - event.wait(); - if (stats != nullptr) { - runtime->GetCallStats(event, stats); - } - }; + if (future != nullptr) { + future->wait_fn = [runtime, event](CallStats *stats) { + event.wait(); + if (stats != nullptr) { + runtime->GetCallStats(event, stats); + } + }; + } } template diff --git a/mace/kernels/opencl/batch_norm_opencl.cc b/mace/kernels/opencl/batch_norm_opencl.cc index b53ef848..6cd46e76 100644 --- a/mace/kernels/opencl/batch_norm_opencl.cc +++ b/mace/kernels/opencl/batch_norm_opencl.cc @@ -96,12 +96,14 @@ void BatchNormFunctor::operator()( params_generator, func, &timer); - future->wait_fn = [runtime, event](CallStats *stats) { - event.wait(); - if (stats != nullptr) { - runtime->GetCallStats(event, stats); - } - }; + if (future != nullptr) { + future->wait_fn = [runtime, event](CallStats *stats) { + event.wait(); + if (stats != nullptr) { + runtime->GetCallStats(event, stats); + } + }; + } } template diff --git a/mace/kernels/opencl/bias_add_opencl.cc b/mace/kernels/opencl/bias_add_opencl.cc index e843e5f3..6d9aa4a9 100644 --- a/mace/kernels/opencl/bias_add_opencl.cc +++ b/mace/kernels/opencl/bias_add_opencl.cc @@ -50,12 +50,14 @@ void BiasAddFunctor::operator()( cl::NDRange(lws[0], lws[1], lws[2]), nullptr, &event); MACE_CHECK(error == CL_SUCCESS); - future->wait_fn = [runtime, event](CallStats *stats) { - event.wait(); - if (stats != nullptr) { - runtime->GetCallStats(event, stats); - } - }; + if (future != nullptr) { + future->wait_fn = [runtime, event](CallStats *stats) { + event.wait(); + if (stats != nullptr) { + runtime->GetCallStats(event, stats); + } + }; + } } template diff --git a/mace/kernels/opencl/buffer_to_image.cc b/mace/kernels/opencl/buffer_to_image.cc index c0dea3a2..b28f113b 100644 --- a/mace/kernels/opencl/buffer_to_image.cc +++ b/mace/kernels/opencl/buffer_to_image.cc @@ -73,12 +73,14 @@ void BufferToImageFunctor::operator()(Tensor *buffer, nullptr, &event); MACE_CHECK(error == CL_SUCCESS) << "Error code: " << error; - future->wait_fn = [runtime, event](CallStats *stats) { - event.wait(); - if (stats != nullptr) { - runtime->GetCallStats(event, stats); - } - }; + if (future != nullptr) { + future->wait_fn = [runtime, event](CallStats *stats) { + event.wait(); + if (stats != nullptr) { + runtime->GetCallStats(event, stats); + } + }; + } } template struct BufferToImageFunctor; diff --git a/mace/kernels/opencl/concat.cc b/mace/kernels/opencl/concat.cc index 514d590d..bea536b6 100644 --- a/mace/kernels/opencl/concat.cc +++ b/mace/kernels/opencl/concat.cc @@ -97,12 +97,14 @@ static void Concat2(const Tensor *input0, params_generator, func, &timer); - future->wait_fn = [runtime, event](CallStats *stats) { - event.wait(); - if (stats != nullptr) { - runtime->GetCallStats(event, stats); - } - }; + if (future != nullptr) { + future->wait_fn = [runtime, event](CallStats *stats) { + event.wait(); + if (stats != nullptr) { + runtime->GetCallStats(event, stats); + } + }; + } } template diff --git a/mace/kernels/opencl/conv_2d_opencl_1x1.cc b/mace/kernels/opencl/conv_2d_opencl_1x1.cc index 59b93376..e2146a2e 100644 --- a/mace/kernels/opencl/conv_2d_opencl_1x1.cc +++ b/mace/kernels/opencl/conv_2d_opencl_1x1.cc @@ -114,12 +114,14 @@ void Conv1x1(const Tensor *input, params_generator, func, &timer); - future->wait_fn = [runtime, event](CallStats *stats) { - event.wait(); - if (stats != nullptr) { - runtime->GetCallStats(event, stats); - } - }; + if (future != nullptr) { + future->wait_fn = [runtime, event](CallStats *stats) { + event.wait(); + if (stats != nullptr) { + runtime->GetCallStats(event, stats); + } + }; + } } extern void Conv2dOpenclK1x1S1(const Tensor *input, diff --git a/mace/kernels/opencl/conv_2d_opencl_3x3.cc b/mace/kernels/opencl/conv_2d_opencl_3x3.cc index 59b66e48..6902448a 100644 --- a/mace/kernels/opencl/conv_2d_opencl_3x3.cc +++ b/mace/kernels/opencl/conv_2d_opencl_3x3.cc @@ -107,12 +107,14 @@ static void Conv2d3x3S12(const Tensor *input, const Tensor *filter, func, &timer); - future->wait_fn = [runtime, event](CallStats *stats) { - event.wait(); - if (stats != nullptr) { - runtime->GetCallStats(event, stats); - } - }; + if (future != nullptr) { + future->wait_fn = [runtime, event](CallStats *stats) { + event.wait(); + if (stats != nullptr) { + runtime->GetCallStats(event, stats); + } + }; + } } void Conv2dOpenclK3x3S1(const Tensor *input, const Tensor *filter, diff --git a/mace/kernels/opencl/conv_2d_opencl_general.cc b/mace/kernels/opencl/conv_2d_opencl_general.cc index d3cee600..1ad8b194 100644 --- a/mace/kernels/opencl/conv_2d_opencl_general.cc +++ b/mace/kernels/opencl/conv_2d_opencl_general.cc @@ -109,12 +109,14 @@ void Conv2dOpencl(const Tensor *input, const Tensor *filter, func, &timer); - future->wait_fn = [runtime, event](CallStats *stats) { - event.wait(); - if (stats != nullptr) { - runtime->GetCallStats(event, stats); - } - }; + if (future != nullptr) { + future->wait_fn = [runtime, event](CallStats *stats) { + event.wait(); + if (stats != nullptr) { + runtime->GetCallStats(event, stats); + } + }; + } } } // namespace kernels diff --git a/mace/kernels/opencl/depthwise_conv_opencl_3x3.cc b/mace/kernels/opencl/depthwise_conv_opencl_3x3.cc index c67382c4..2300e0f0 100644 --- a/mace/kernels/opencl/depthwise_conv_opencl_3x3.cc +++ b/mace/kernels/opencl/depthwise_conv_opencl_3x3.cc @@ -66,12 +66,14 @@ static void InnerDepthwiseConvOpenclK3x3S12(const Tensor *input, nullptr, &event); MACE_CHECK(error == CL_SUCCESS); - future->wait_fn = [runtime, event](CallStats *stats) { - event.wait(); - if (stats != nullptr) { - runtime->GetCallStats(event, stats); - } - }; + if (future != nullptr) { + future->wait_fn = [runtime, event](CallStats *stats) { + event.wait(); + if (stats != nullptr) { + runtime->GetCallStats(event, stats); + } + }; + } } extern void DepthwiseConvOpenclK3x3S1(const Tensor *input, diff --git a/mace/kernels/opencl/pooling_opencl.cc b/mace/kernels/opencl/pooling_opencl.cc index 81415966..991dcac3 100644 --- a/mace/kernels/opencl/pooling_opencl.cc +++ b/mace/kernels/opencl/pooling_opencl.cc @@ -110,12 +110,14 @@ static void Pooling(const Tensor *input, func, &timer); - future->wait_fn = [runtime, event](CallStats *stats) { - event.wait(); - if (stats != nullptr) { - runtime->GetCallStats(event, stats); - } - }; + if (future != nullptr) { + future->wait_fn = [runtime, event](CallStats *stats) { + event.wait(); + if (stats != nullptr) { + runtime->GetCallStats(event, stats); + } + }; + } } template diff --git a/mace/kernels/opencl/relu_opencl.cc b/mace/kernels/opencl/relu_opencl.cc index d74337ec..c9d5a7f1 100644 --- a/mace/kernels/opencl/relu_opencl.cc +++ b/mace/kernels/opencl/relu_opencl.cc @@ -97,12 +97,14 @@ void ReluFunctor::operator()(const Tensor *input, params_generator, func, &timer); - future->wait_fn = [runtime, event](CallStats *stats) { - event.wait(); - if (stats != nullptr) { - runtime->GetCallStats(event, stats); - } - }; + if (future != nullptr) { + future->wait_fn = [runtime, event](CallStats *stats) { + event.wait(); + if (stats != nullptr) { + runtime->GetCallStats(event, stats); + } + }; + } } template diff --git a/mace/kernels/opencl/resize_bilinear_opencl.cc b/mace/kernels/opencl/resize_bilinear_opencl.cc index f8c7aa71..588d83c6 100644 --- a/mace/kernels/opencl/resize_bilinear_opencl.cc +++ b/mace/kernels/opencl/resize_bilinear_opencl.cc @@ -102,12 +102,14 @@ void ResizeBilinearFunctor::operator()( params_generator, func, &timer); - future->wait_fn = [runtime, event](CallStats *stats) { - event.wait(); - if (stats != nullptr) { - runtime->GetCallStats(event, stats); - } - }; + if (future != nullptr) { + future->wait_fn = [runtime, event](CallStats *stats) { + event.wait(); + if (stats != nullptr) { + runtime->GetCallStats(event, stats); + } + }; + } } template struct ResizeBilinearFunctor; diff --git a/mace/kernels/opencl/space_to_batch_opecl.cc b/mace/kernels/opencl/space_to_batch_opecl.cc index 395b9235..32ada21a 100644 --- a/mace/kernels/opencl/space_to_batch_opecl.cc +++ b/mace/kernels/opencl/space_to_batch_opecl.cc @@ -50,12 +50,14 @@ void SpaceToBatchFunctor::operator()(Tensor *space_te cl::NDRange(lws[0], lws[1], lws[2]), nullptr, &event); MACE_CHECK(error == CL_SUCCESS); - future->wait_fn = [runtime, event](CallStats *stats) { - event.wait(); - if (stats != nullptr) { - runtime->GetCallStats(event, stats); - } - }; + if (future != nullptr) { + future->wait_fn = [runtime, event](CallStats *stats) { + event.wait(); + if (stats != nullptr) { + runtime->GetCallStats(event, stats); + } + }; + } } } // namespace kernels diff --git a/tools/bazel-adb-run.sh b/tools/bazel-adb-run.sh index 4926ad2b..e80ecd83 100755 --- a/tools/bazel-adb-run.sh +++ b/tools/bazel-adb-run.sh @@ -42,5 +42,5 @@ for device in `adb devices | grep "^[A-Za-z0-9]\+[[:space:]]\+device$"| cut -f1` adb -s ${device} shell "mkdir -p $DEVICE_PATH" adb -s ${device} push $CL_PATH $DEVICE_CL_PATH && \ adb -s ${device} push $BAZEL_BIN_PATH/$BIN_NAME $DEVICE_PATH && \ - adb -s ${device} shell "MACE_KERNEL_PATH=$DEVICE_CL_PATH MACE_CPP_MIN_VLOG_LEVEL=0$VLOG_LEVEL $DEVICE_PATH/$BIN_NAME $@" + adb -s ${device} shell "MACE_KERNEL_PATH=$DEVICE_CL_PATH MACE_CPP_MIN_VLOG_LEVEL=$VLOG_LEVEL $DEVICE_PATH/$BIN_NAME $@" done -- GitLab