提交 8fb74366 编写于 作者: 刘托

Merge branch 'micro_bug' into 'master'

fix: fix error in micro static lib building and warning from `memset`

See merge request deep-computing/mace!1280
......@@ -52,17 +52,17 @@ Here we use the har-cnn model as an example.
.. code-block:: sh
# copy convert result to micro dir ``path/to/micro``
# copy convert result to micro dir ``path/to/micro``, which should not be the sub directory of the ``mace/``.
cp build/har-cnn/model/har_cnn_micro.tar.gz path/to/micro/
cd path/to/micro
tar zxvf har_cnn_micro.tar.gz
bazel build //micro/codegen:micro_engine
bazel build //micro/codegen:libmicro.so
.. note::
- This step can be skipped if you just want to run a model using ``tools/python/run_micro.py``, such as commands in step 5.
- The build result ``bazel-bin/micro/codegen/libmicro_engine.so``'s abi is host, if you want to run the model on micro controllers, you should build the code with the target abi.
- The build result ``bazel-bin/micro/codegen/libmicro.so``'s abi is host, if you want to run the model on micro controllers, you should build the code with the target abi.
5. Run the model on host.
......
......@@ -224,7 +224,7 @@ class Buffer : public BufferBase {
}
void Clear(index_t size) {
memset(reinterpret_cast<char*>(raw_mutable_data()), 0, size);
memset(reinterpret_cast<void *>(raw_mutable_data()), 0, size);
}
const std::vector<size_t> shape() const {
......
......@@ -244,7 +244,7 @@ bool HexagonHTAWrapper::SetupGraph(const NetDef &net_def,
auto quantized_tensor = make_unique<Tensor>(allocator_, DT_UINT8);
auto hta_tensor = make_unique<Tensor>(allocator_, DT_UINT8);
hexagon_hta_nn_hw_tensordef &input_tensordef = input_tensordef_[index];
memset(&input_tensordef, 0, sizeof(input_tensordef));
memset(static_cast<void *>(&input_tensordef), 0, sizeof(input_tensordef));
MACE_CHECK(hexagon_hta_nn_get_memory_layout(nn_id_, 0, index,
&input_tensordef) == 0);
input_tensordef.dataLen = input_tensordef.batchStride;
......@@ -290,7 +290,7 @@ bool HexagonHTAWrapper::SetupGraph(const NetDef &net_def,
quantized_tensor->SetZeroPoint(output_info.zero_point());
hexagon_hta_nn_hw_tensordef &output_tensordef = output_tensordef_[index];
memset(&output_tensordef, 0, sizeof(output_tensordef));
memset(static_cast<void *>(&output_tensordef), 0, sizeof(output_tensordef));
MACE_CHECK(hexagon_hta_nn_get_memory_layout(nn_id_, 1, index,
&output_tensordef) == 0);
output_tensordef.dataLen = output_tensordef.batchStride;
......
......@@ -47,7 +47,7 @@ class AddNOp<DeviceType::CPU, T> : public Operation {
Tensor::MappingGuard output_guard(output);
auto output_data = output->mutable_data<T>();
memset(output_data, 0, size * sizeof(T));
memset(static_cast<void *>(output_data), 0, size * sizeof(T));
for (auto &input : inputs_) {
Tensor::MappingGuard input_guard(input);
......
......@@ -134,7 +134,8 @@ class Gemm : public delegator::Gemm {
depth = rows;
}
const index_t depth_padded = RoundUp(depth, static_cast<index_t>(4));
memset(packed_matrix, 0, sizeof(T) * WidthBlockSize * depth_padded);
memset(static_cast<void *>(packed_matrix), 0,
sizeof(T) * WidthBlockSize * depth_padded);
if (dst_major == ColMajor) {
for (index_t c = 0; c < cols; ++c) {
for (index_t r = 0; r < rows; ++r) {
......
......@@ -84,7 +84,7 @@ class CumsumOp<DeviceType::CPU, T> : public Operation {
for (index_t cum_idx = 0; cum_idx < cum_size; ++cum_idx) {
if (cum_idx == 0) {
if (exclusive_) {
std::memset(output_ptr + start_idx,
std::memset(static_cast<void *>(output_ptr + start_idx),
0,
sizeof(T) * inner_size);
} else {
......@@ -111,7 +111,7 @@ class CumsumOp<DeviceType::CPU, T> : public Operation {
index_t cur_idx = start_idx + cum_idx * inner_size;
if (cum_idx == cum_size - 1) {
if (exclusive_) {
std::memset(output_ptr + cur_idx,
std::memset(static_cast<void *>(output_ptr + cur_idx),
0,
sizeof(T) * inner_size);
} else {
......
......@@ -590,7 +590,7 @@ class ReduceOp<DeviceType::CPU, T> : public ReduceOpBase {
const T *input_ptr = input->data<T>();
Tensor::MappingGuard output_map(output);
T *output_ptr = output->mutable_data<T>();
memset(output_ptr, 0, output->size() * sizeof(T));
memset(static_cast<void *>(output_ptr), 0, output->size() * sizeof(T));
switch (data_reshape_.size()) {
case 1:Reduce1Dims(context, input_ptr, reduce_type_, output_ptr);
break;
......
......@@ -163,13 +163,13 @@ class SpaceToBatchNDOp<DeviceType::CPU, T> : public SpaceToBatchOpBase {
T *output_base =
output_data + (b * channels + c) * out_height * out_width;
memset(output_base + block_h * out_width,
memset(static_cast<void *>(output_base + block_h * out_width),
0,
(valid_h_start - block_h) * out_width * sizeof(T));
index_t in_h = valid_h_start * block_shape_h + tile_h - pad_top;
for (index_t h = valid_h_start; h < valid_h_end; ++h) {
memset(output_base + h * out_width,
memset(static_cast<void *>(output_base + h * out_width),
0,
valid_w_start * sizeof(T));
......@@ -181,12 +181,12 @@ class SpaceToBatchNDOp<DeviceType::CPU, T> : public SpaceToBatchOpBase {
} // w
in_h += block_shape_h;
memset(output_base + h * out_width + valid_w_end,
0,
(out_width - valid_w_end) * sizeof(T));
memset(
static_cast<void *>(output_base + h * out_width + valid_w_end),
0, (out_width - valid_w_end) * sizeof(T));
} // h
memset(output_base + valid_h_end * out_width,
memset(static_cast<void *>(output_base + valid_h_end * out_width),
0,
(std::min(out_height, block_h + block_h_size) - valid_h_end)
* out_width * sizeof(T));
......
......@@ -62,7 +62,7 @@ class SqrDiffMeanOp : public Operation {
const T *input_ptr1 = input1->data<T>();
Tensor::MappingGuard output_map(output);
T *output_ptr = output->mutable_data<T>();
memset(output_ptr, 0, output->size() * sizeof(T));
memset(static_cast<void *>(output_ptr), 0, output->size() * sizeof(T));
const index_t img_size = input0->dim(2) * input0->dim(3);
const index_t bc = input0->dim(0) * input0->dim(1);
......
......@@ -81,18 +81,22 @@ genrule(
"//micro/include",
"//micro/model",
"//micro/ops",
"//micro/base",
"//micro/port",
],
outs = ["libmicro.a"],
cmd = "tmp_mri_file=$$(mktemp micro-static-lib-mri.XXXXXXXXXX);" +
"mri_stream=$$(python $(location //mace/python/tools:archive_static_lib) " +
"$(locations micro_engine) " +
"$(locations generated_models) " +
"$(locations //micro/base) " +
"$(locations //micro/framework) " +
"$(locations //micro/model) " +
"$(locations ////micro/ops) " +
"$(locations //micro/ops) " +
"$(locations //micro/port) " +
"$@ " +
"$$tmp_mri_file);" +
"$(AR) -M <$$tmp_mri_file;" +
"$(AR) -M <$$tmp_mri_file;" +
"rm -rf $$tmp_mri_file;",
tools = ["//mace/python/tools:archive_static_lib"],
visibility = ["//visibility:public"],
......
......@@ -32,6 +32,7 @@ MaceStatus GetMicroEngineSingleton(MaceMicroEngine **engine) {
if (!kHasInit) {
MaceMicroEngineConfig *engine_config = GetMicroEngineConfig();
status = kMaceMicroEngine.Init(engine_config);
kHasInit = (status == MACE_SUCCESS);
}
if (status == MACE_SUCCESS) {
*engine = &kMaceMicroEngine;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册