提交 1ac3d9ff 编写于 作者: Y yejianwu

fix compile error and isolate opencl for deconv

上级 a6c8ff43
...@@ -23,12 +23,15 @@ ...@@ -23,12 +23,15 @@
#include <vector> #include <vector>
#include "mace/core/future.h" #include "mace/core/future.h"
#include "mace/core/runtime/opencl/cl2_header.h"
#include "mace/core/tensor.h" #include "mace/core/tensor.h"
#include "mace/kernels/activation.h" #include "mace/kernels/activation.h"
#include "mace/kernels/conv_pool_2d_util.h" #include "mace/kernels/conv_pool_2d_util.h"
#include "mace/utils/utils.h" #include "mace/utils/utils.h"
#ifdef MACE_ENABLE_OPENCL
#include "mace/core/runtime/opencl/cl2_header.h"
#endif // MACE_ENABLE_OPENCL
namespace mace { namespace mace {
namespace kernels { namespace kernels {
...@@ -126,7 +129,6 @@ struct Deconv2dFunctorBase { ...@@ -126,7 +129,6 @@ struct Deconv2dFunctorBase {
const index_t in_height = isNCHW ? input_shape[2] : input_shape[1]; const index_t in_height = isNCHW ? input_shape[2] : input_shape[1];
const index_t in_width = isNCHW ? input_shape[3] : input_shape[2]; const index_t in_width = isNCHW ? input_shape[3] : input_shape[2];
const index_t in_channels = isNCHW ? input_shape[1] : input_shape[3];
const index_t extended_input_height = const index_t extended_input_height =
(in_height - 1) * strides[0] + 1 + padding_size[0]; (in_height - 1) * strides[0] + 1 + padding_size[0];
...@@ -168,11 +170,9 @@ struct Deconv2dFunctorBase { ...@@ -168,11 +170,9 @@ struct Deconv2dFunctorBase {
const index_t in_height = isNCHW ? input_shape[2] : input_shape[1]; const index_t in_height = isNCHW ? input_shape[2] : input_shape[1];
const index_t in_width = isNCHW ? input_shape[3] : input_shape[2]; const index_t in_width = isNCHW ? input_shape[3] : input_shape[2];
const index_t in_channels = isNCHW ? input_shape[1] : input_shape[3];
const index_t out_height = isNCHW ? output_shape[2] : output_shape[1]; const index_t out_height = isNCHW ? output_shape[2] : output_shape[1];
const index_t out_width = isNCHW ? output_shape[3] : output_shape[2]; const index_t out_width = isNCHW ? output_shape[3] : output_shape[2];
const index_t out_channels = isNCHW ? output_shape[1] : output_shape[3];
const index_t extended_input_height = (in_height - 1) * strides[0] + 1; const index_t extended_input_height = (in_height - 1) * strides[0] + 1;
const index_t extended_input_width = (in_width - 1) * strides[1] + 1; const index_t extended_input_width = (in_width - 1) * strides[1] + 1;
...@@ -216,9 +216,9 @@ struct Deconv2dFunctorBase { ...@@ -216,9 +216,9 @@ struct Deconv2dFunctorBase {
const int *strides_; // [stride_h, stride_w] const int *strides_; // [stride_h, stride_w]
const Padding padding_type_; const Padding padding_type_;
std::vector<int> paddings_; std::vector<int> paddings_;
std::vector<index_t> output_shape_;
const ActivationType activation_; const ActivationType activation_;
const float relux_max_limit_; const float relux_max_limit_;
std::vector<index_t> output_shape_;
}; };
template <DeviceType D, typename T> template <DeviceType D, typename T>
...@@ -228,9 +228,7 @@ struct Deconv2dFunctor : Deconv2dFunctorBase { ...@@ -228,9 +228,7 @@ struct Deconv2dFunctor : Deconv2dFunctorBase {
const std::vector<int> &paddings, const std::vector<int> &paddings,
const std::vector<index_t> &output_shape, const std::vector<index_t> &output_shape,
const ActivationType activation, const ActivationType activation,
const float relux_max_limit, const float relux_max_limit)
const bool is_filter_transformed,
ScratchBuffer *scratch)
: Deconv2dFunctorBase(strides, : Deconv2dFunctorBase(strides,
padding_type, padding_type,
paddings, paddings,
...@@ -243,6 +241,7 @@ struct Deconv2dFunctor : Deconv2dFunctorBase { ...@@ -243,6 +241,7 @@ struct Deconv2dFunctor : Deconv2dFunctorBase {
const Tensor *bias, const Tensor *bias,
Tensor *output, Tensor *output,
StatsFuture *future) { StatsFuture *future) {
MACE_UNUSED(future);
MACE_CHECK_NOTNULL(input); MACE_CHECK_NOTNULL(input);
MACE_CHECK_NOTNULL(filter); MACE_CHECK_NOTNULL(filter);
MACE_CHECK_NOTNULL(output); MACE_CHECK_NOTNULL(output);
...@@ -315,6 +314,7 @@ struct Deconv2dFunctor : Deconv2dFunctorBase { ...@@ -315,6 +314,7 @@ struct Deconv2dFunctor : Deconv2dFunctorBase {
} }
}; };
#ifdef MACE_ENABLE_OPENCL
template <typename T> template <typename T>
struct Deconv2dFunctor<DeviceType::GPU, T> : Deconv2dFunctorBase { struct Deconv2dFunctor<DeviceType::GPU, T> : Deconv2dFunctorBase {
Deconv2dFunctor(const int *strides, Deconv2dFunctor(const int *strides,
...@@ -322,9 +322,7 @@ struct Deconv2dFunctor<DeviceType::GPU, T> : Deconv2dFunctorBase { ...@@ -322,9 +322,7 @@ struct Deconv2dFunctor<DeviceType::GPU, T> : Deconv2dFunctorBase {
const std::vector<int> &paddings, const std::vector<int> &paddings,
const std::vector<index_t> &output_shape, const std::vector<index_t> &output_shape,
const ActivationType activation, const ActivationType activation,
const float relux_max_limit, const float relux_max_limit)
const bool is_filter_transformed,
ScratchBuffer *scratch)
: Deconv2dFunctorBase(strides, : Deconv2dFunctorBase(strides,
padding_type, padding_type,
paddings, paddings,
...@@ -343,6 +341,7 @@ struct Deconv2dFunctor<DeviceType::GPU, T> : Deconv2dFunctorBase { ...@@ -343,6 +341,7 @@ struct Deconv2dFunctor<DeviceType::GPU, T> : Deconv2dFunctorBase {
std::unique_ptr<BufferBase> kernel_error_; std::unique_ptr<BufferBase> kernel_error_;
std::vector<index_t> input_shape_; std::vector<index_t> input_shape_;
}; };
#endif // MACE_ENABLE_OPENCL
} // namespace kernels } // namespace kernels
} // namespace mace } // namespace mace
......
...@@ -24,6 +24,7 @@ void Register_Deconv2D(OperatorRegistry *op_registry) { ...@@ -24,6 +24,7 @@ void Register_Deconv2D(OperatorRegistry *op_registry) {
.Build(), .Build(),
Deconv2dOp<DeviceType::CPU, float>); Deconv2dOp<DeviceType::CPU, float>);
#ifdef MACE_ENABLE_OPENCL
REGISTER_OPERATOR(op_registry, OpKeyBuilder("Deconv2D") REGISTER_OPERATOR(op_registry, OpKeyBuilder("Deconv2D")
.Device(DeviceType::GPU) .Device(DeviceType::GPU)
.TypeConstraint<float>("T") .TypeConstraint<float>("T")
...@@ -35,6 +36,7 @@ void Register_Deconv2D(OperatorRegistry *op_registry) { ...@@ -35,6 +36,7 @@ void Register_Deconv2D(OperatorRegistry *op_registry) {
.TypeConstraint<half>("T") .TypeConstraint<half>("T")
.Build(), .Build(),
Deconv2dOp<DeviceType::GPU, half>); Deconv2dOp<DeviceType::GPU, half>);
#endif // MACE_ENABLE_OPENCL
} }
} // namespace ops } // namespace ops
......
...@@ -34,10 +34,7 @@ class Deconv2dOp : public ConvPool2dOpBase<D, T> { ...@@ -34,10 +34,7 @@ class Deconv2dOp : public ConvPool2dOpBase<D, T> {
this->paddings_, this->paddings_,
OperatorBase::GetRepeatedArgument<index_t>("output_shape"), OperatorBase::GetRepeatedArgument<index_t>("output_shape"),
kernels::ActivationType::NOOP, kernels::ActivationType::NOOP,
0.0f, 0.0f) {}
static_cast<bool>(OperatorBase::GetSingleArgument<int>(
"is_filter_transformed", false)),
ws->GetScratchBuffer(D)) {}
bool Run(StatsFuture *future) override { bool Run(StatsFuture *future) override {
const Tensor *input = this->Input(INPUT); const Tensor *input = this->Input(INPUT);
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <vector> #include <vector>
#include <string> #include <string>
#include "mace/core/macros.h"
#include "mace/public/mace.h" #include "mace/public/mace.h"
#include "mace/utils/env_time.h" #include "mace/utils/env_time.h"
#include "mace/utils/logging.h" #include "mace/utils/logging.h"
...@@ -42,6 +43,7 @@ alignas(4) const unsigned char model_data[{{ model_data_size }}] = { ...@@ -42,6 +43,7 @@ alignas(4) const unsigned char model_data[{{ model_data_size }}] = {
const unsigned char *LoadModelData(const char *model_data_file) { const unsigned char *LoadModelData(const char *model_data_file) {
{% if embed_model_data %} {% if embed_model_data %}
MACE_UNUSED(model_data_file);
return model_data; return model_data;
{% else %} {% else %}
int fd = open(model_data_file, O_RDONLY); int fd = open(model_data_file, O_RDONLY);
...@@ -67,6 +69,8 @@ void UnloadModelData(const unsigned char *model_data) { ...@@ -67,6 +69,8 @@ void UnloadModelData(const unsigned char *model_data) {
int ret = munmap(const_cast<unsigned char *>(model_data), int ret = munmap(const_cast<unsigned char *>(model_data),
{{ model_data_size }}); {{ model_data_size }});
MACE_CHECK(ret == 0, "Failed to unmap model data file, error code: ", errno); MACE_CHECK(ret == 0, "Failed to unmap model data file, error code: ", errno);
{% else %}
MACE_UNUSED(model_data);
{% endif %} {% endif %}
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册