From 46fff4dd1a18f0af63c9680e5793d727ab112239 Mon Sep 17 00:00:00 2001 From: "baolei.an" Date: Wed, 6 May 2020 14:54:32 +0800 Subject: [PATCH] [LITE][BM] modify device info location,test=develop --- lite/backends/bm/CMakeLists.txt | 1 + lite/backends/bm/device_info.cc | 55 ++++++++++++++++++++++++++ lite/backends/bm/device_info.h | 70 +++++++++++++++++++++++++++++++++ lite/core/device_info.cc | 13 ------ lite/core/device_info.h | 43 -------------------- lite/kernels/bm/CMakeLists.txt | 2 +- 6 files changed, 127 insertions(+), 57 deletions(-) create mode 100644 lite/backends/bm/device_info.cc create mode 100644 lite/backends/bm/device_info.h diff --git a/lite/backends/bm/CMakeLists.txt b/lite/backends/bm/CMakeLists.txt index 9e15b9836b..d559a84fde 100644 --- a/lite/backends/bm/CMakeLists.txt +++ b/lite/backends/bm/CMakeLists.txt @@ -3,3 +3,4 @@ if (NOT LITE_WITH_BM) endif() lite_cc_library(target_wrapper_bm SRCS target_wrapper.cc DEPS ${bm_runtime_libs}) +lite_cc_library(device_info_bm SRCS device_info.cc) diff --git a/lite/backends/bm/device_info.cc b/lite/backends/bm/device_info.cc new file mode 100644 index 0000000000..910ed96aae --- /dev/null +++ b/lite/backends/bm/device_info.cc @@ -0,0 +1,55 @@ +// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// 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. + +// Parts of the following code in this file refs to +// https://github.com/Tencent/ncnn/blob/master/src/cpu.cpp +// Tencent is pleased to support the open source community by making ncnn +// available. +// +// Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. +// +// Licensed under the BSD 3-Clause License (the "License"); you may not use this +// file except in compliance with the License. You may obtain a copy of the +// License at +// +// https://opensource.org/licenses/BSD-3-Clause +// +// Unless required by applicable law or agreed to in writing, software +// 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 "lite/backends/bm/device_info.h" +#include +#include + +namespace paddle { +namespace lite { + +#ifdef LITE_WITH_BM +void Device::SetId(int device_id) { + LOG(INFO) << "Set bm device " << device_id; + TargetWrapper::SetDevice(device_id); + idx_ = device_id; +} + +void Device::Init() { SetId(idx_); } +int Device::core_num() { + return TargetWrapper::num_devices(); +} +#endif // LITE_WITH_BM + +} // namespace lite +} // namespace paddle diff --git a/lite/backends/bm/device_info.h b/lite/backends/bm/device_info.h new file mode 100644 index 0000000000..89668b368e --- /dev/null +++ b/lite/backends/bm/device_info.h @@ -0,0 +1,70 @@ +// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// 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. + +#pragma once + +#include +#include +#include +#include "lite/core/device_info.h" +#include "lite/core/tensor.h" +#include "lite/utils/cp_logging.h" + +namespace paddle { +namespace lite { + +#ifdef LITE_WITH_BM +template <> +class Device { + public: + Device(int dev_id, int max_stream = 1) + : idx_(dev_id), max_stream_(max_stream) {} + void Init(); + + int id() { return idx_; } + int max_stream() { return 1; } + std::string name() { return "BM"; } + float max_memory() { return 16; } + int core_num(); + void SetId(int idx); + + int sm_version() { return 0; } + bool has_fp16() { return false; } + bool has_int8() { return false; } + bool has_hmma() { return false; } + bool has_imma() { return false; } + int runtime_version() { return 0; } + + private: + void CreateQueue() {} + void GetInfo() {} + + private: + int idx_{0}; + int max_stream_{1}; + std::string device_name_; + float max_memory_; + + int sm_version_; + bool has_fp16_; + bool has_int8_; + bool has_hmma_; + bool has_imma_; + int runtime_version_; +}; + +template class Env; +#endif +} // namespace lite +} // namespace paddle diff --git a/lite/core/device_info.cc b/lite/core/device_info.cc index ac79ede374..09da06a416 100644 --- a/lite/core/device_info.cc +++ b/lite/core/device_info.cc @@ -1240,19 +1240,6 @@ void Device::CreateQueue() { } #endif // LITE_WITH_MLU -#ifdef LITE_WITH_BM -void Device::SetId(int device_id) { - LOG(INFO) << "Set bm device " << device_id; - TargetWrapper::SetDevice(device_id); - idx_ = device_id; -} - -void Device::Init() { SetId(idx_); } -int Device::core_num() { - return TargetWrapper::num_devices(); -} -#endif // LITE_WITH_BM - #ifdef LITE_WITH_CUDA void Device::Init() { diff --git a/lite/core/device_info.h b/lite/core/device_info.h index f5b75039ea..b06eb8d944 100644 --- a/lite/core/device_info.h +++ b/lite/core/device_info.h @@ -221,49 +221,6 @@ class Device { template class Env; #endif // LITE_WITH_MLU -#ifdef LITE_WITH_BM -template <> -class Device { - public: - Device(int dev_id, int max_stream = 1) - : idx_(dev_id), max_stream_(max_stream) {} - void Init(); - - int id() { return idx_; } - int max_stream() { return 1; } - std::string name() { return "BM"; } - float max_memory() { return 16; } - int core_num(); - void SetId(int idx); - - int sm_version() { return 0; } - bool has_fp16() { return false; } - bool has_int8() { return false; } - bool has_hmma() { return false; } - bool has_imma() { return false; } - int runtime_version() { return 0; } - - private: - void CreateQueue() {} - void GetInfo() {} - - private: - int idx_{0}; - int max_stream_{1}; - std::string device_name_; - float max_memory_; - - int sm_version_; - bool has_fp16_; - bool has_int8_; - bool has_hmma_; - bool has_imma_; - int runtime_version_; -}; - -template class Env; -#endif - #ifdef LITE_WITH_CUDA template <> class Device { diff --git a/lite/kernels/bm/CMakeLists.txt b/lite/kernels/bm/CMakeLists.txt index 691fe55978..d7b21bf097 100644 --- a/lite/kernels/bm/CMakeLists.txt +++ b/lite/kernels/bm/CMakeLists.txt @@ -3,4 +3,4 @@ if(NOT LITE_WITH_BM) endif() add_subdirectory(bridges) -add_kernel(subgraph_compute_bm BM basic SRCS subgraph_compute.cc DEPS ${lite_kernel_deps} ${bm_subgraph_bridges}) +add_kernel(subgraph_compute_bm BM basic SRCS subgraph_compute.cc DEPS ${lite_kernel_deps} ${bm_subgraph_bridges} device_info_bm) -- GitLab