提交 3eeec43e 编写于 作者: R root 提交者: baolei.an

bm can build success

*test = develop
上级 cdec7b64
......@@ -30,12 +30,13 @@ if(NOT BM_SDK_INC)
message(FATAL_ERROR "Can not find bmruntime_interface.h in ${BM_SDK_ROOT}/include")
endif()
include_directories("${BM_SDK_ROOT}/include")
include_directories("${BM_SDK_ROOT}/include/bmruntime")
include_directories("${BM_SDK_ROOT}/include/bmlib")
include_directories("${BM_SDK_ROOT}/include/bmcompiler")
include_directories("${BM_SDK_ROOT}/include/bmcpu")
find_library(BM_SDK_RT_LIB NAMES bmrt
PATHS ${BM_SDK_ROOT}/lib/app)
PATHS ${BM_SDK_ROOT}/lib/bmnn/pcie)
if(NOT BM_SDK_RT_LIB)
message(FATAL_ERROR "Can not find bmrt Library in ${BM_SDK_ROOT}")
else()
......@@ -45,7 +46,7 @@ else()
endif()
find_library(BM_SDK_BM_LIB NAMES bmlib
PATHS ${BM_SDK_ROOT}/lib/app)
PATHS ${BM_SDK_ROOT}/lib/bmnn/pcie)
if(NOT BM_SDK_BM_LIB)
message(FATAL_ERROR "Can not find bmlib Library in ${BM_SDK_ROOT}")
else()
......@@ -65,7 +66,7 @@ else()
endif()
find_library(BM_SDK_CPU_LIB NAMES bmcpu
PATHS ${BM_SDK_ROOT}/lib/bmcpu)
PATHS ${BM_SDK_ROOT}/lib/bmnn/pcie)
if(NOT BM_SDK_CPU_LIB)
message(FATAL_ERROR "Can not find bmcpu Library in ${BM_SDK_ROOT}")
else()
......
......@@ -8,6 +8,7 @@ message(STATUS "LITE_WITH_ARM:\t${LITE_WITH_ARM}")
message(STATUS "LITE_WITH_NPU:\t${LITE_WITH_NPU}")
message(STATUS "LITE_WITH_XPU:\t${LITE_WITH_XPU}")
message(STATUS "LITE_WITH_FPGA:\t${LITE_WITH_FPGA}")
message(STATUS "LITE_WITH_BM:\t${LITE_WITH_BM}")
message(STATUS "LITE_WITH_PROFILE:\t${LITE_WITH_PROFILE}")
message(STATUS "LITE_WITH_CV:\t${LITE_WITH_CV}")
......@@ -65,6 +66,9 @@ if (LITE_WITH_LIGHT_WEIGHT_FRAMEWORK AND LITE_WITH_ARM)
if (LITE_WITH_FPGA)
set(INFER_LITE_PUBLISH_ROOT "${INFER_LITE_PUBLISH_ROOT}.fpga")
endif(LITE_WITH_FPGA)
if (LITE_WITH_BM)
set(INFER_LITE_PUBLISH_ROOT "${INFER_LITE_PUBLISH_ROOT}.bm")
endif(LITE_WITH_BM)
else()
set(INFER_LITE_PUBLISH_ROOT "${CMAKE_BINARY_DIR}/inference_lite_lib")
endif()
......
......@@ -64,6 +64,7 @@ message(STATUS "get ARM kernels ${arm_kernels}")
message(STATUS "get NPU kernels ${npu_kernels}")
message(STATUS "get XPU kernels ${xpu_kernels}")
message(STATUS "get FPGA kernels ${fpga_kernels}")
message(STATUS "get BM kernels ${bm_kernels}")
# for full api
if (NOT LITE_ON_TINY_PUBLISH)
......
......@@ -55,7 +55,8 @@ const std::string& TargetToStr(TargetType target) {
"any",
"fpga",
"npu",
"xpu"};
"xpu",
"bm"};
auto x = static_cast<int>(target);
CHECK_LT(x, static_cast<int>(TARGET(NUM)));
return target2string[x];
......@@ -93,7 +94,8 @@ const std::string& TargetRepr(TargetType target) {
"kAny",
"kFPGA",
"kNPU",
"kXPU"};
"kXPU",
"kBM"};
auto x = static_cast<int>(target);
CHECK_LT(x, static_cast<int>(TARGET(NUM)));
return target2string[x];
......@@ -129,7 +131,8 @@ std::set<TargetType> ExpandValidTargets(TargetType target) {
TARGET(kOpenCL),
TARGET(kNPU),
TARGET(kXPU),
TARGET(kFPGA)});
TARGET(kFPGA),
TARGET(kBM)});
if (target == TARGET(kAny)) {
return valid_set;
}
......
......@@ -52,8 +52,9 @@ enum class TargetType : int {
kFPGA = 7,
kNPU = 8,
kXPU = 9,
kBM = 10,
kAny = 6, // any target
NUM = 10, // number of fields.
NUM = 11, // number of fields.
};
enum class PrecisionType : int {
kUnk = 0,
......
......@@ -6,3 +6,4 @@ add_subdirectory(fpga)
add_subdirectory(host)
add_subdirectory(npu)
add_subdirectory(xpu)
add_subdirectory(bm)
if (NOT LITE_WITH_BM)
return()
endif()
lite_cc_library(target_wrapper_bm SRCS target_wrapper.cc)
// 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.
#include <map>
#include "lite/backends/bm/target_wrapper.h"
#include "bmlib_runtime.h"
namespace paddle {
namespace lite {
static int g_current_device_id = 0;
static std::map<int, bm_handle_t> g_bm_handles;
size_t TargetWrapperBM::num_devices() {
int count = 0;
bm_dev_getcount(&count);
return count;
}
void TargetWrapperBM::SetDevice(int id) {
g_current_device_id = id;
if (g_bm_handles.find(id) == g_bm_handles.end()) {
bm_handle_t bm_handle;
bm_dev_request(&bm_handle, id);
g_bm_handles.insert(std::pair<int, bm_handle_t>(id, bm_handle));
}
return;
}
void* TargetWrapperBM::Malloc(size_t size) {
void* ptr{};
bm_handle_t bm_handle = g_bm_handles.at(g_current_device_id);
bm_device_mem_t* p_mem = (bm_device_mem_t*)malloc(sizeof(bm_device_mem_t));
bm_malloc_device_byte(bm_handle, p_mem, size);
ptr = (void*)p_mem;
return ptr;
}
void TargetWrapperBM::Free(void* ptr) {
if (ptr != NULL) {
bm_handle_t bm_handle = g_bm_handles.at(g_current_device_id);
bm_device_mem_t* mem = static_cast<bm_device_mem_t*>(ptr);
bm_free_device(bm_handle, *mem);
free(ptr);
}
return;
}
void TargetWrapperBM::MemcpySync(void* dst,
const void* src,
size_t size,
IoDirection dir) {
if (g_bm_handles.find(g_current_device_id) == g_bm_handles.end()){
return;
}
bm_handle_t bm_handle = g_bm_handles.at(g_current_device_id);
bm_device_mem_t* pmem{};
const bm_device_mem_t* pcst_mem{};
switch (dir) {
case IoDirection::HtoD:
pmem = static_cast<bm_device_mem_t*>(dst);
bm_memcpy_s2d_partial_offset(bm_handle, *pmem, (void*)src, size, 0);
break;
case IoDirection::DtoH:
pcst_mem = static_cast<const bm_device_mem_t*>(src);
bm_memcpy_d2s_partial_offset(bm_handle, (void*)(dst), *pcst_mem, size, 0);
break;
default:
LOG(FATAL) << "Unsupported IoDirection " << static_cast<int>(dir);
break;
}
return;
}
} // namespace lite
} // namespace paddle
// 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 "lite/core/target_wrapper.h"
namespace paddle {
namespace lite {
using TargetWrapperBM = TargetWrapper<TARGET(kBM)>;
template <>
class TargetWrapper<TARGET(kBM)> {
public:
using stream_t = int;
using event_t = int;
static size_t num_devices();
static size_t maximum_stream() { return 0; }
static void SetDevice(int id);
static void CreateStream(stream_t* stream) {}
static void DestroyStream(const stream_t& stream) {}
static void CreateEvent(event_t* event) {}
static void DestroyEvent(const event_t& event) {}
static void RecordEvent(const event_t& event) {}
static void SyncEvent(const event_t& event) {}
static void StreamSync(const stream_t& stream) {}
static void* Malloc(size_t size);
static void Free(void* ptr);
static void MemcpySync(void* dst,
const void* src,
size_t size,
IoDirection dir);
static void MemcpyAsync(void* dst,
const void* src,
size_t size,
IoDirection dir,
const stream_t& stream) {}
static void MemsetSync(void* devPtr, int value, size_t count) {}
static void MemsetAsync(void* devPtr,
int value,
size_t count,
const stream_t& stream) {}
};
} // namespace lite
} // namespace paddle
......@@ -10,3 +10,4 @@ add_subdirectory(opencl)
add_subdirectory(fpga)
add_subdirectory(npu)
add_subdirectory(xpu)
add_subdirectory(bm)
if(NOT LITE_WITH_BM)
return ()
endif()
......@@ -78,7 +78,7 @@ function build_bm {
-DWITH_TESTING=${WITH_TESTING} \
-DBM_SDK_ROOT=${BM_SDK_ROOT}
make $TARGET_NAME -j$NUM_CORES_FOR_COMPILE
make -j$NUM_CORES_FOR_COMPILE
cd -
echo "Done"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册