diff --git a/mace/core/runtime/hexagon/hexagon_device.cc b/mace/core/runtime/hexagon/hexagon_device.cc index e8a0aa4e49873a306dcfa795a2a96d351f534dc5..c465c1a920930b9ef582692e4c64efc6ef5923ae 100644 --- a/mace/core/runtime/hexagon/hexagon_device.cc +++ b/mace/core/runtime/hexagon/hexagon_device.cc @@ -32,16 +32,18 @@ HexagonDevice::HexagonDevice(DeviceType device_type, #ifdef MACE_ENABLE_OPENCL GPURuntime *HexagonDevice::gpu_runtime() { + MACE_CHECK_NOTNULL(gpu_device_); return gpu_device_->gpu_runtime(); } #endif // MACE_ENABLE_OPENCL Allocator *HexagonDevice::allocator() { #ifdef MACE_ENABLE_OPENCL - return gpu_device_->allocator(); -#else - return allocator_.get(); + if (gpu_device_ != nullptr) { + return gpu_device_->allocator(); + } #endif // MACE_ENABLE_OPENCL + return allocator_.get(); } DeviceType HexagonDevice::device_type() const { diff --git a/mace/core/runtime/hexagon/hexagon_device.h b/mace/core/runtime/hexagon/hexagon_device.h index 660965eb9f89c46a395b0087ea6f864304a2f668..9913c893bb09c13525bf9486e989a7837d610da0 100644 --- a/mace/core/runtime/hexagon/hexagon_device.h +++ b/mace/core/runtime/hexagon/hexagon_device.h @@ -39,7 +39,7 @@ class HexagonDevice : public CPUDevice { HexagonDevice(DeviceType device_type, #ifdef MACE_ENABLE_OPENCL utils::ThreadPool *thread_pool, - std::unique_ptr gpu_device); + std::unique_ptr gpu_device = nullptr); #else utils::ThreadPool *thread_pool); #endif // MACE_ENABLE_OPENCL diff --git a/mace/libmace/mace.cc b/mace/libmace/mace.cc index 44e025d09703600e315753bc0e71fd6940da066b..3085b6556de96c58eea100f8daa097420e366f9c 100644 --- a/mace/libmace/mace.cc +++ b/mace/libmace/mace.cc @@ -578,8 +578,9 @@ MaceEngine::Impl::Impl(const MaceEngineConfig &config) } #endif #if defined(MACE_ENABLE_HEXAGON) || defined(MACE_ENABLE_HTA) - if (device_type_ == DeviceType::HEXAGON - || device_type_ == DeviceType::HTA) { + if (device_type_ == DeviceType::HEXAGON) { + device_.reset(new HexagonDevice(device_type_, thread_pool_.get())); + } else if (device_type_ == DeviceType::HTA) { #ifdef MACE_ENABLE_OPENCL device_.reset(new HexagonDevice( device_type_, thread_pool_.get(), diff --git a/mace/ops/eltwise.cc b/mace/ops/eltwise.cc index 39f7e6487eb203fc0c0dfde869d2e661f77cd24c..94986d8481a04ea5db327dd777fdacf7383b5746 100644 --- a/mace/ops/eltwise.cc +++ b/mace/ops/eltwise.cc @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -1198,6 +1199,27 @@ void RegisterEltwise(OpRegistry *op_registry) { #endif // MACE_ENABLE_QUANTIZE MACE_REGISTER_GPU_OP(op_registry, "Eltwise", EltwiseOp); + MACE_REGISTER_OP_CONDITION( + op_registry, OpConditionBuilder("Eltwise").SetDevicePlacerFunc( + [](OpConditionContext *context) -> std::set { + auto op = context->operator_def(); + if (op->output_shape_size() != op->output_size()) { + return {DeviceType::CPU, DeviceType::GPU}; + } + + int input_size = op->input_size(); + auto ws = context->workspace(); + for (int i = 0; i < input_size; ++i) { + if (ws->HasTensor(op->input(i)) && + ws->GetTensor(op->input(i))->is_weight()) { + int dims = ws->GetTensor(op->input(i))->dim_size(); + if (dims != 1 && dims != 4) { + return {DeviceType::CPU}; + } + } + } + return {DeviceType::CPU, DeviceType::GPU}; + })); } } // namespace ops diff --git a/tools/device.py b/tools/device.py index d1d80afe53cf1949b88281d07f4c9ce07df80be1..6ab0135bc64ae6c23359b1c89c3a375ea60da7d1 100644 --- a/tools/device.py +++ b/tools/device.py @@ -279,8 +279,7 @@ class DeviceWrapper: if os.path.exists(opencl_parameter_file): self.push(opencl_parameter_file, self.data_dir) - if self.system == SystemType.android \ - and device_type == common.DeviceType.HEXAGON: + if self.system == SystemType.android: self.push( "third_party/nnlib/%s/libhexagon_controller.so" % abi, self.data_dir)