update nncase v1 to 8c384a (#125)

develop
郑启航 2021-07-18 18:25:51 +08:00 committed by GitHub
parent 0ce2526418
commit 9b61893150
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
55 changed files with 520 additions and 209 deletions

View File

@ -1,4 +1,4 @@
/* Copyright 2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,4 +1,4 @@
/* Copyright 2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,4 +1,4 @@
/* Copyright 2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -35,17 +35,6 @@
} \
}
#define TYPE_IMPL_SELECT(type, IMPL) \
switch (runtime::get_bytes(type)) \
{ \
IMPL(1, uint8_t); \
IMPL(2, uint16_t); \
IMPL(4, uint32_t); \
IMPL(8, uint64_t); \
default: \
return err(std::errc::not_supported); \
}
enum copy_impl_select
{
all_contiguous,

View File

@ -1,4 +1,4 @@
/* Copyright 2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -20,14 +20,33 @@ BEGIN_NS_NNCASE_KERNELS_CPU_OPT
NNCASE_API result<void> concat(datatype_t type, gsl::span<const gsl::byte *const> inputs, gsl::byte *output, const runtime_shape_t &out_shape,
gsl::span<const runtime_shape_t> in_strides, const runtime_shape_t &out_strides, size_t axis, const runtime_shape_t &concat_dims,
kernel_context &context) noexcept;
kernel_context &context = default_kernel_context()) noexcept;
NNCASE_API result<void> resize_bilinear(datatype_t type, const gsl::byte *input, gsl::byte *output, const runtime_shape_t &in_shape,
const runtime_shape_t &in_strides, const runtime_shape_t &out_strides, int32_t out_h, int32_t out_w, bool align_corners, bool half_pixel_centers,
kernel_context &context = default_kernel_context()) noexcept;
NNCASE_API result<void> resize_nearest_neighbor(datatype_t type, const gsl::byte *input, gsl::byte *output, const runtime_shape_t &in_shape,
const runtime_shape_t &in_strides, const runtime_shape_t &out_strides, int32_t out_h, int32_t out_w, bool align_corners, bool half_pixel_centers,
kernel_context &context = default_kernel_context()) noexcept;
NNCASE_API result<void> copy(datatype_t type, const gsl::byte *src, gsl::byte *dest,
const runtime_shape_t &shape, const runtime_shape_t &src_strides, const runtime_shape_t &dest_strides,
int dims_offset, copy_impl_select impl_select, kernel_context &context) noexcept;
NNCASE_API result<void> gather(datatype_t type, const gsl::byte *input, gsl::byte *output, const runtime_shape_t &in_shape, const runtime_shape_t &out_shape,
const runtime_shape_t &in_strides, const runtime_shape_t &out_strides, const int32_t *indices, const runtime_shape_t &indices_shape, size_t axis,
kernel_context &context = default_kernel_context()) noexcept;
NNCASE_API result<void> gather_nd(datatype_t type, const gsl::byte *input, gsl::byte *output, const runtime_shape_t &in_shape, const runtime_shape_t &out_shape,
const runtime_shape_t &in_strides, const runtime_shape_t &out_strides, const int32_t *indices, const runtime_shape_t &indices_shape, size_t batch_dims,
kernel_context &context = default_kernel_context()) noexcept;
NNCASE_API result<void> onehot(datatype_t type, const int32_t *indices, gsl::byte *output, const runtime_shape_t &indices_shape, const runtime_shape_t &out_shape,
const runtime_shape_t &out_strides, gsl::byte *depth, gsl::byte *off_value, gsl::byte *on_value, size_t axis, onehot_mode_t mode, kernel_context &context) noexcept;
NNCASE_API result<void> slice(datatype_t type, const gsl::byte *input, gsl::byte *output, const runtime_shape_t &in_shape,
const runtime_shape_t &in_strides, const runtime_shape_t &out_strides, const runtime_shape_t &begins, const runtime_shape_t &ends, const runtime_axis_t &strides,
kernel_context &context) noexcept;
NNCASE_API result<void> copy(datatype_t type, const gsl::byte *src, gsl::byte *dest,
const runtime_shape_t &shape, const runtime_shape_t &src_strides, const runtime_shape_t &dest_strides,
int dims_offset, copy_impl_select impl_select, kernel_context &context) noexcept;
kernel_context &context = default_kernel_context()) noexcept;
END_NS_NNCASE_KERNELS_CPU_OPT

View File

@ -1,4 +1,4 @@
/* Copyright 2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,4 +1,4 @@
/* Copyright 2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,4 +1,4 @@
/* Copyright 2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,4 +1,4 @@
/* Copyright 2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,4 +1,4 @@
/* Copyright 2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -49,6 +49,9 @@ NNCASE_API result<void> dequantize(datatype_t in_type, datatype_t out_type, cons
NNCASE_API result<void> lut1d(datatype_t type, const gsl::byte *input, const gsl::byte *table, gsl::byte *output, const runtime_shape_t &shape,
const runtime_shape_t &in_strides, const runtime_shape_t &out_strides, const scalar &min, const scalar &max) noexcept;
NNCASE_API result<void> onehot(datatype_t type, const int32_t *indices, gsl::byte *output, const runtime_shape_t &indices_shape, const runtime_shape_t &out_shape,
const runtime_shape_t &out_strides, gsl::byte *depth, gsl::byte *off_value, gsl::byte *on_value, size_t axis, onehot_mode_t mode, kernel_context &context) noexcept;
NNCASE_API result<void> pad(datatype_t type, const gsl::byte *input, gsl::byte *output, const runtime_shape_t &in_shape,
const runtime_shape_t &in_strides, const runtime_shape_t &out_strides, const runtime_paddings_t &paddings, pad_mode_t mode, const scalar &pad_value,
kernel_context &context) noexcept;
@ -63,8 +66,22 @@ NNCASE_API result<void> unary(unary_op_t op, const float *input, float *output,
NNCASE_API result<void> reduce(reduce_op_t op, float init_value, const float *input, float *output, const runtime_shape_t &in_shape, const runtime_shape_t &axis,
const runtime_shape_t &in_strides, const runtime_shape_t &out_strides, bool keep_dims, kernel_context &context) noexcept;
NNCASE_API result<void> resize_bilinear(datatype_t type, const gsl::byte *input, gsl::byte *output, const runtime_shape_t &in_shape,
const runtime_shape_t &in_strides, const runtime_shape_t &out_strides, int32_t out_h, int32_t out_w, bool align_corners, bool half_pixel_centers,
kernel_context &context) noexcept;
NNCASE_API result<void> resize_nearest_neighbor(datatype_t type, const gsl::byte *input, gsl::byte *output, const runtime_shape_t &in_shape,
const runtime_shape_t &in_strides, const runtime_shape_t &out_strides, int32_t out_h, int32_t out_w, bool align_corners, bool half_pixel_centers,
kernel_context &context) noexcept;
NNCASE_API result<void> slice(datatype_t type, const gsl::byte *input, gsl::byte *output, const runtime_shape_t &in_shape,
const runtime_shape_t &in_strides, const runtime_shape_t &out_strides, const runtime_shape_t &begins, const runtime_shape_t &ends, const runtime_axis_t &strides,
kernel_context &context) noexcept;
NNCASE_API result<void> gather(datatype_t type, const gsl::byte *input, gsl::byte *output, const runtime_shape_t &in_shape, const runtime_shape_t &out_shape,
const runtime_shape_t &in_strides, const runtime_shape_t &out_strides, const int32_t *indices, const runtime_shape_t &indices_shape, size_t axis, kernel_context &context) noexcept;
NNCASE_API result<void> gather_nd(datatype_t type, const gsl::byte *input, gsl::byte *output, const runtime_shape_t &in_shape, const runtime_shape_t &out_shape,
const runtime_shape_t &in_strides, const runtime_shape_t &out_strides, const int32_t *indices, const runtime_shape_t &indices_shape, size_t batch_dims, kernel_context &context) noexcept;
END_NS_NNCASE_KERNELS_CPU_REF

View File

@ -1,4 +1,4 @@
/* Copyright 2019-2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,4 +1,4 @@
/* Copyright 2019-2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,4 +1,4 @@
/* Copyright 2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -15,6 +15,7 @@
#pragma once
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstddef>
#include <nncase/runtime/datatypes.h>
#include <numeric>
@ -27,6 +28,17 @@
#define CXX_RESTRICT
#endif
#define TYPE_IMPL_SELECT(type, IMPL) \
switch (runtime::get_bytes(type)) \
{ \
IMPL(1, uint8_t); \
IMPL(2, uint16_t); \
IMPL(4, uint32_t); \
IMPL(8, uint64_t); \
default: \
return err(std::errc::not_supported); \
}
BEGIN_NS_NNCASE_KERNELS
template <class offset_type, class S, class It>
@ -236,5 +248,46 @@ constexpr T quantize(float value, const quant_param_t &param) noexcept
{
return (T)clamp((int32_t)lrintf(value / param.scale + param.zero_point), (int32_t)std::numeric_limits<T>::lowest(), (int32_t)std::numeric_limits<T>::max());
}
inline std::pair<float, float> get_resize_scales(const runtime_shape_t &in_shape, int32_t out_h, int32_t out_w, bool align_corners)
{
auto height_scale = (float)in_shape[2] / out_h;
auto width_scale = (float)in_shape[3] / out_w;
if (align_corners && out_h > 1)
height_scale = (float)(in_shape[2] - 1) / (out_h - 1);
if (align_corners && out_w > 1)
width_scale = (float)(in_shape[3] - 1) / (out_w - 1);
return { height_scale, width_scale };
}
inline void set_resize_bilinear(size_t value, float scale, bool half_pixel_centers, size_t shape_size, float &scaled_value, int32_t &v0, int32_t &v1)
{
if (half_pixel_centers)
{
scaled_value = (value + 0.5f) * scale - 0.5f;
}
else
{
scaled_value = value * scale;
}
float scaled_value_floor = std::floor(scaled_value);
v0 = std::max(static_cast<int32_t>(scaled_value_floor), 0);
v1 = std::min(static_cast<int32_t>(std::ceil(scaled_value)), static_cast<int32_t>(shape_size - 1));
}
template <class T>
inline size_t get_nearest_neighbor(T input_value, size_t shape_size, float scale, bool align_corners, bool half_pixel_centers)
{
const auto offset = half_pixel_centers ? 0.5f : 0.0f;
const auto after_scale = (static_cast<float>(input_value) + offset) * scale;
const auto align_corners_val = align_corners ? roundf(after_scale) : std::floor(after_scale);
int32_t output_value = std::min(static_cast<int32_t>(align_corners_val), static_cast<int32_t>(shape_size - 1));
if (half_pixel_centers)
{
output_value = std::max(0, output_value);
}
return output_value;
}
}
END_NS_NNCASE_KERNELS

View File

@ -1,4 +1,4 @@
/* Copyright 2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,4 +1,4 @@
/* Copyright 2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -13,10 +13,10 @@
* limitations under the License.
*/
#pragma once
#include <nncase/kernels/kernel_context.h>
#include <nncase/runtime/datatypes.h>
#include <nncase/runtime/error.h>
#include <nncase/runtime/result.h>
#include <nncase/kernels/kernel_context.h>
BEGIN_NS_NNCASE_KERNELS

View File

@ -1,4 +1,4 @@
/* Copyright 2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,4 +1,4 @@
/* Copyright 2019-2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,4 +1,4 @@
/* Copyright 2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -13,15 +13,15 @@
* limitations under the License.
*/
#pragma once
#include <nncase/kernels/kernel_context.h>
#include <nncase/runtime/datatypes.h>
#include <nncase/runtime/error.h>
#include <nncase/runtime/result.h>
#include <nncase/kernels/kernel_context.h>
BEGIN_NS_NNCASE_KERNELS
NNCASE_API result<void> batch_to_space(datatype_t type, const gsl::byte *input, gsl::byte *output, const runtime_shape_t &in_shape,
const runtime_shape_t &block_shape, const runtime_paddings_t &crops, const runtime_shape_t &in_strides, const runtime_shape_t &out_strides,
const runtime_shape_t &block_shape, const runtime_paddings_t &crops, const runtime_shape_t &in_strides, const runtime_shape_t &out_strides,
kernel_context &context = default_kernel_context()) noexcept;
NNCASE_API result<void> broadcast(datatype_t type, const gsl::byte *input, gsl::byte *output, const runtime_shape_t &in_shape,
@ -51,6 +51,10 @@ NNCASE_API result<void> dequantize(datatype_t in_type, datatype_t out_type, cons
NNCASE_API result<void> lut1d(datatype_t type, const gsl::byte *input, const gsl::byte *table, gsl::byte *output, const runtime_shape_t &shape,
const runtime_shape_t &in_strides, const runtime_shape_t &out_strides, const scalar &min, const scalar &max) noexcept;
NNCASE_API result<void> onehot(datatype_t type, const int32_t *indices, gsl::byte *output, const runtime_shape_t &indices_shape, const runtime_shape_t &out_shape,
const runtime_shape_t &out_strides, gsl::byte *depth, gsl::byte *off_value, gsl::byte *on_value, size_t axis, onehot_mode_t mode,
kernel_context &context = default_kernel_context()) noexcept;
NNCASE_API result<void> pad(datatype_t type, const gsl::byte *input, gsl::byte *output, const runtime_shape_t &in_shape,
const runtime_shape_t &in_strides, const runtime_shape_t &out_strides, const runtime_paddings_t &paddings, pad_mode_t mode, const scalar &pad_value,
kernel_context &context = default_kernel_context()) noexcept;
@ -65,8 +69,21 @@ NNCASE_API result<void> unary(unary_op_t op, const float *input, float *output,
NNCASE_API result<void> reduce(reduce_op_t op, float init_value, const float *input, float *output, const runtime_shape_t &in_shape, const runtime_shape_t &axis,
const runtime_shape_t &in_strides, const runtime_shape_t &out_strides, bool keep_dims, kernel_context &context = default_kernel_context()) noexcept;
NNCASE_API result<void> resize_bilinear(datatype_t type, const gsl::byte *input, gsl::byte *output, const runtime_shape_t &in_shape,
const runtime_shape_t &in_strides, const runtime_shape_t &out_strides, int32_t out_h, int32_t out_w, bool align_corners, bool half_pixel_centers,
kernel_context &context = default_kernel_context()) noexcept;
NNCASE_API result<void> resize_nearest_neighbor(datatype_t type, const gsl::byte *input, gsl::byte *output, const runtime_shape_t &in_shape,
const runtime_shape_t &in_strides, const runtime_shape_t &out_strides, int32_t out_h, int32_t out_w, bool align_corners, bool half_pixel_centers,
kernel_context &context = default_kernel_context()) noexcept;
NNCASE_API result<void> slice(datatype_t type, const gsl::byte *input, gsl::byte *output, const runtime_shape_t &in_shape,
const runtime_shape_t &in_strides, const runtime_shape_t &out_strides, const runtime_shape_t &begins, const runtime_shape_t &ends, const runtime_axis_t &strides,
kernel_context &context = default_kernel_context()) noexcept;
NNCASE_API result<void> gather(datatype_t in_type, const gsl::byte *input, gsl::byte *output, const runtime_shape_t &in_shape, const runtime_shape_t &out_shape,
const runtime_shape_t &in_strides, const runtime_shape_t &out_strides, const int32_t *indices, const runtime_shape_t &indices_shape, int32_t axis, kernel_context &context = default_kernel_context()) noexcept;
NNCASE_API result<void> gather_nd(datatype_t type, const gsl::byte *input, gsl::byte *output, const runtime_shape_t &in_shape, const runtime_shape_t &out_shape,
const runtime_shape_t &in_strides, const runtime_shape_t &out_strides, const int32_t *indices, const runtime_shape_t &indices_shape, int32_t batch_dims, kernel_context &context = default_kernel_context()) noexcept;
END_NS_NNCASE_KERNELS

View File

@ -1,4 +1,4 @@
/* Copyright 2019-2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,4 +1,4 @@
/* Copyright 2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,4 +1,4 @@
/* Copyright 2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,4 +1,4 @@
/* Copyright 2019-2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,4 +1,4 @@
/* Copyright 2019-2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -136,6 +136,22 @@ typedef enum _reduce_op
reduce_sum
} reduce_op_t;
inline std::string reduce_op_to_string(reduce_op_t op)
{
switch (op)
{
case reduce_mean:
return "reduce_mean";
case reduce_min:
return "reduce_min";
case reduce_max:
return "reduce_max";
case reduce_sum:
return "reduce_sum";
}
return "unknown";
}
typedef enum _binary_op
{
binary_add,
@ -256,6 +272,12 @@ typedef enum _image_resize_mode
image_resize_nearest_neighbor
} image_resize_mode_t;
typedef enum _onehot_mode
{
onehot_normal,
onehot_process_neg
} onehot_mode_t;
typedef enum _pad_mode
{
pad_constant,

View File

@ -1,4 +1,4 @@
/* Copyright 2019-2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,4 +1,4 @@
/* Copyright 2019-2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -38,9 +38,9 @@ struct host_memory_block
host_memory_block() = default;
host_memory_block(const host_memory_block &) = delete;
host_memory_block(host_memory_block && other) noexcept;
host_memory_block(host_memory_block &&other) noexcept;
host_memory_block &operator=(const host_memory_block &) = delete;
host_memory_block &operator=(host_memory_block && other) noexcept;
host_memory_block &operator=(host_memory_block &&other) noexcept;
~host_memory_block()
{
@ -52,6 +52,7 @@ struct host_memory_block
if (auto d = std::move(deleter))
d(reinterpret_cast<gsl::byte *>(virtual_address));
deleter = {};
physical_block.free(*this);
}
gsl::span<gsl::byte> virtual_buffer() const noexcept

View File

@ -1,4 +1,4 @@
/* Copyright 2019-2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,4 +1,4 @@
/* Copyright 2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,4 +1,4 @@
/* Copyright 2019-2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,4 +1,4 @@
/* Copyright 2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,6 +1,4 @@
/* This file is generated by tools/stackvm_gen/IsaGen at 2021/2/23 16:24:09 +08:00.
*
* Copyright 2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -36,6 +34,7 @@ public:
virtual result<void> visit(NNCASE_UNUSED const kpu_download_options &op) noexcept { return ok(); }
virtual result<void> visit(NNCASE_UNUSED const kpu_conv2d_options &op) noexcept { return ok(); }
virtual result<void> visit(NNCASE_UNUSED const kpu_upload_options &op) noexcept { return ok(); }
virtual result<void> visit(NNCASE_UNUSED const copy_options &op) noexcept { return ok(); }
protected:
bool interrupted_;

View File

@ -1,4 +1,4 @@
/* Copyright 2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,4 +1,4 @@
/* Copyright 2019-2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,4 +1,4 @@
/* Copyright 2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -292,7 +292,8 @@ enum class opcode_t : uint8_t
{
kpu_upload,
kpu_download,
kpu_conv2d
kpu_conv2d,
copy
};
struct kpu_upload_options
@ -328,4 +329,16 @@ struct kpu_conv2d_options
kpu_layer_argument_t layer;
};
struct copy_options
{
opcode_t opcode = opcode_t::copy;
uint8_t reserved0[3];
memory_range input;
memory_range output;
kpu_shape_t in_shape;
kpu_shape_t in_strides;
kpu_shape_t out_strides;
};
END_NS_NNCASE_RT_K210

View File

@ -1,4 +1,4 @@
/* Copyright 2019-2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,4 +1,4 @@
/* Copyright 2019-2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,4 +1,4 @@
/* Copyright 2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -72,7 +72,7 @@ struct Ok
: value(value) { }
template <class... Args>
constexpr explicit Ok(mpark::in_place_t, Args &&...args)
constexpr explicit Ok(mpark::in_place_t, Args &&... args)
: value(std::forward<Args>(args)...) { }
T value;
@ -101,7 +101,7 @@ inline constexpr Ok<void> ok()
}
template <class T, class... Args>
constexpr Ok<T> ok(Args &&...args)
constexpr Ok<T> ok(Args &&... args)
{
return Ok<T>(mpark::in_place, std::forward<Args>(args)...);
}

View File

@ -1,4 +1,4 @@
/* Copyright 2019-2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,4 +1,4 @@
/* Copyright 2019-2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,4 +1,4 @@
/* Copyright 2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -252,8 +252,10 @@ inline int get_last_not_contiguous_index(const runtime_shape_t &strides, const r
return -1;
}
template<size_t A, size_t B>
template <size_t A, size_t B>
constexpr auto is_not_equal = std::integral_constant<bool, std::not_equal_to<size_t> {}(A, B)> {};
struct DefaultCallable {};
struct DefaultCallable
{
};
END_NS_NNCASE_RUNTIME

View File

@ -1,4 +1,4 @@
/* Copyright 2019-2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,4 +1,4 @@
/* Copyright 2019-2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,4 +1,4 @@
/* Copyright 2019-2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,4 +1,4 @@
/* Copyright 2019-2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -33,7 +33,7 @@ struct NNCASE_API physical_memory_block
physical_memory_block &operator=(const physical_memory_block &) = delete;
physical_memory_block &operator=(physical_memory_block &&other) noexcept;
result<void> free() noexcept;
void free(NNCASE_UNUSED host_memory_block &block) noexcept;
static result<void> acknowledge(host_memory_block &block) noexcept;
static result<void> allocate(host_memory_block &block) noexcept;

View File

@ -130,61 +130,69 @@
//
#pragma once
#include <type_traits>
#include <cstddef>
#include <memory>
#include <type_traits>
#define ITLIB_SMALL_VECTOR_ERROR_HANDLING_NONE 0
#define ITLIB_SMALL_VECTOR_ERROR_HANDLING_NONE 0
#define ITLIB_SMALL_VECTOR_ERROR_HANDLING_THROW 1
#define ITLIB_SMALL_VECTOR_ERROR_HANDLING_ASSERT 2
#define ITLIB_SMALL_VECTOR_ERROR_HANDLING_ASSERT_AND_THROW 3
#if !defined(ITLIB_SMALL_VECTOR_ERROR_HANDLING)
# define ITLIB_SMALL_VECTOR_ERROR_HANDLING ITLIB_SMALL_VECTOR_ERROR_HANDLING_THROW
#define ITLIB_SMALL_VECTOR_ERROR_HANDLING ITLIB_SMALL_VECTOR_ERROR_HANDLING_THROW
#endif
#if ITLIB_SMALL_VECTOR_ERROR_HANDLING == ITLIB_SMALL_VECTOR_ERROR_HANDLING_NONE
# define I_ITLIB_SMALL_VECTOR_OUT_OF_RANGE_IF(cond)
#define I_ITLIB_SMALL_VECTOR_OUT_OF_RANGE_IF(cond)
#elif ITLIB_SMALL_VECTOR_ERROR_HANDLING == ITLIB_SMALL_VECTOR_ERROR_HANDLING_THROW
# include <stdexcept>
# define I_ITLIB_SMALL_VECTOR_OUT_OF_RANGE_IF(cond) if (cond) throw std::out_of_range("itlib::small_vector out of range")
#include <stdexcept>
#define I_ITLIB_SMALL_VECTOR_OUT_OF_RANGE_IF(cond) \
if (cond) \
throw std::out_of_range("itlib::small_vector out of range")
#elif ITLIB_SMALL_VECTOR_ERROR_HANDLING == ITLIB_SMALL_VECTOR_ERROR_HANDLING_ASSERT
# include <cassert>
# define I_ITLIB_SMALL_VECTOR_OUT_OF_RANGE_IF(cond, rescue_return) assert(!(cond) && "itlib::small_vector out of range")
#include <cassert>
#define I_ITLIB_SMALL_VECTOR_OUT_OF_RANGE_IF(cond, rescue_return) assert(!(cond) && "itlib::small_vector out of range")
#elif ITLIB_SMALL_VECTOR_ERROR_HANDLING == ITLIB_SMALL_VECTOR_ERROR_HANDLING_ASSERT_AND_THROW
# include <stdexcept>
# include <cassert>
# define I_ITLIB_SMALL_VECTOR_OUT_OF_RANGE_IF(cond, rescue_return) \
do { if (cond) { assert(false && "itlib::small_vector out of range"); throw std::out_of_range("itlib::small_vector out of range"); } } while(false)
#include <cassert>
#include <stdexcept>
#define I_ITLIB_SMALL_VECTOR_OUT_OF_RANGE_IF(cond, rescue_return) \
do \
{ \
if (cond) \
{ \
assert(false && "itlib::small_vector out of range"); \
throw std::out_of_range("itlib::small_vector out of range"); \
} \
} while (false)
#else
#error "Unknown ITLIB_SMALL_VECTOR_ERRROR_HANDLING"
#endif
#if defined(ITLIB_SMALL_VECTOR_NO_DEBUG_BOUNDS_CHECK)
# define I_ITLIB_SMALL_VECTOR_BOUNDS_CHECK(i)
#define I_ITLIB_SMALL_VECTOR_BOUNDS_CHECK(i)
#else
# include <cassert>
# define I_ITLIB_SMALL_VECTOR_BOUNDS_CHECK(i) assert((i) < this->size())
#include <cassert>
#define I_ITLIB_SMALL_VECTOR_BOUNDS_CHECK(i) assert((i) < this->size())
#endif
namespace itlib
{
template<typename T, size_t StaticCapacity = 16, size_t RevertToStaticSize = 0, class Alloc = std::allocator<T>>
struct small_vector: Alloc
template <typename T, size_t StaticCapacity = 16, size_t RevertToStaticSize = 0, class Alloc = std::allocator<T>>
struct small_vector : Alloc
{
static_assert(RevertToStaticSize <= StaticCapacity + 1, "itlib::small_vector: the revert-to-static size shouldn't exceed the static capacity by more than one");
using atraits = std::allocator_traits<Alloc>;
public:
using allocator_type = Alloc;
using value_type = typename atraits::value_type;
using size_type = typename atraits::size_type;
using difference_type = typename atraits::difference_type;
using reference = T&;
using const_reference = const T&;
using reference = T &;
using const_reference = const T &;
using pointer = typename atraits::pointer;
using const_pointer = typename atraits::const_pointer;
using iterator = pointer;
@ -197,9 +205,10 @@ public:
small_vector()
: small_vector(Alloc())
{}
{
}
small_vector(const Alloc& alloc)
small_vector(const Alloc &alloc)
: Alloc(alloc)
, m_capacity(StaticCapacity)
, m_dynamic_capacity(0)
@ -208,36 +217,37 @@ public:
m_begin = m_end = static_begin_ptr();
}
explicit small_vector(size_t count, const Alloc& alloc = Alloc())
explicit small_vector(size_t count, const Alloc &alloc = Alloc())
: small_vector(alloc)
{
resize(count);
}
explicit small_vector(size_t count, const T& value, const Alloc& alloc = Alloc())
explicit small_vector(size_t count, const T &value, const Alloc &alloc = Alloc())
: small_vector(alloc)
{
assign_impl(count, value);
}
template <class InputIterator, typename = decltype(*std::declval<InputIterator>())>
small_vector(InputIterator first, InputIterator last, const Alloc& alloc = Alloc())
small_vector(InputIterator first, InputIterator last, const Alloc &alloc = Alloc())
: small_vector(alloc)
{
assign_impl(first, last);
}
small_vector(std::initializer_list<T> l, const Alloc& alloc = Alloc())
small_vector(std::initializer_list<T> l, const Alloc &alloc = Alloc())
: small_vector(alloc)
{
assign_impl(l);
}
small_vector(const small_vector& v)
small_vector(const small_vector &v)
: small_vector(v, atraits::select_on_container_copy_construction(v.get_allocator()))
{}
{
}
small_vector(const small_vector& v, const Alloc& alloc)
small_vector(const small_vector &v, const Alloc &alloc)
: Alloc(alloc)
, m_dynamic_capacity(0)
, m_dynamic_data(nullptr)
@ -261,7 +271,7 @@ public:
}
}
small_vector(small_vector&& v)
small_vector(small_vector &&v)
: Alloc(std::move(v.get_alloc()))
, m_capacity(v.m_capacity)
, m_dynamic_capacity(v.m_dynamic_capacity)
@ -300,7 +310,7 @@ public:
}
}
small_vector& operator=(const small_vector& v)
small_vector &operator=(const small_vector &v)
{
if (this == &v)
{
@ -323,7 +333,7 @@ public:
return *this;
}
small_vector& operator=(small_vector&& v)
small_vector &operator=(small_vector &&v)
{
clear();
@ -357,7 +367,7 @@ public:
return *this;
}
void assign(size_type count, const T& value)
void assign(size_type count, const T &value)
{
clear();
assign_impl(count, value);
@ -512,7 +522,8 @@ public:
void reserve(size_type new_cap)
{
if (new_cap <= m_capacity) return;
if (new_cap <= m_capacity)
return;
auto new_buf = choose_data(new_cap);
@ -520,7 +531,7 @@ public:
assert(new_buf != static_begin_ptr()); // we should never reserve into static memory
const auto s = size();
if(s < RevertToStaticSize)
if (s < RevertToStaticSize)
{
// we've allocated enough memory for the dynamic buffer but don't move there until we have to
return;
@ -558,8 +569,10 @@ public:
{
const auto s = size();
if (s == m_capacity) return;
if (m_begin == static_begin_ptr()) return;
if (s == m_capacity)
return;
if (m_begin == static_begin_ptr())
return;
auto old_end = m_end;
@ -591,8 +604,10 @@ public:
void revert_to_static()
{
const auto s = size();
if (m_begin == static_begin_ptr()) return; //we're already there
if (s > StaticCapacity) return; // nothing we can do
if (m_begin == static_begin_ptr())
return; //we're already there
if (s > StaticCapacity)
return; // nothing we can do
// revert to static capacity
auto old_end = m_end;
@ -625,21 +640,21 @@ public:
}
}
iterator insert(const_iterator position, const value_type& val)
iterator insert(const_iterator position, const value_type &val)
{
auto pos = grow_at(position, 1);
atraits::construct(get_alloc(), pos, val);
return pos;
}
iterator insert(const_iterator position, value_type&& val)
iterator insert(const_iterator position, value_type &&val)
{
auto pos = grow_at(position, 1);
atraits::construct(get_alloc(), pos, std::move(val));
return pos;
}
iterator insert(const_iterator position, size_type count, const value_type& val)
iterator insert(const_iterator position, size_type count, const value_type &val)
{
auto pos = grow_at(position, count);
for (size_type i = 0; i < count; ++i)
@ -666,7 +681,7 @@ public:
{
auto pos = grow_at(position, ilist.size());
size_type i = 0;
for (auto& elem : ilist)
for (auto &elem : ilist)
{
atraits::construct(get_alloc(), pos + i, elem);
++i;
@ -674,8 +689,8 @@ public:
return pos;
}
template<typename... Args>
iterator emplace(const_iterator position, Args&&... args)
template <typename... Args>
iterator emplace(const_iterator position, Args &&... args)
{
auto pos = grow_at(position, 1);
atraits::construct(get_alloc(), pos, std::forward<Args>(args)...);
@ -699,14 +714,14 @@ public:
atraits::construct(get_alloc(), pos, val);
}
void push_back(T&& val)
void push_back(T &&val)
{
auto pos = grow_at(m_end, 1);
atraits::construct(get_alloc(), pos, std::move(val));
}
template<typename... Args>
reference emplace_back(Args&&... args)
template <typename... Args>
reference emplace_back(Args &&... args)
{
auto pos = grow_at(m_end, 1);
atraits::construct(get_alloc(), pos, std::forward<Args>(args)...);
@ -718,7 +733,7 @@ public:
shrink_at(m_end - 1, 1);
}
void resize(size_type n, const value_type& v)
void resize(size_type n, const value_type &v)
{
auto new_buf = choose_data(n);
@ -847,7 +862,7 @@ public:
}
private:
T* static_begin_ptr()
T *static_begin_ptr()
{
return reinterpret_cast<pointer>(m_static_data + 0);
}
@ -855,9 +870,9 @@ private:
// increase the size by splicing the elements in such a way that
// a hole of uninitialized elements is left at position, with size num
// returns the (potentially new) address of the hole
T* grow_at(const T* cp, size_t num)
T *grow_at(const T *cp, size_t num)
{
auto position = const_cast<T*>(cp);
auto position = const_cast<T *>(cp);
I_ITLIB_SMALL_VECTOR_OUT_OF_RANGE_IF(position < m_begin || position > m_end);
@ -919,9 +934,9 @@ private:
}
}
T* shrink_at(const T* cp, size_t num)
T *shrink_at(const T *cp, size_t num)
{
auto position = const_cast<T*>(cp);
auto position = const_cast<T *>(cp);
I_ITLIB_SMALL_VECTOR_OUT_OF_RANGE_IF(position < m_begin || position > m_end || position + num > m_end);
@ -985,7 +1000,7 @@ private:
return ++position;
}
void assign_impl(size_type count, const T& value)
void assign_impl(size_type count, const T &value)
{
assert(m_begin);
assert(m_begin == m_end);
@ -1022,7 +1037,7 @@ private:
assert(m_begin == m_end);
m_begin = m_end = choose_data(ilist.size());
for (auto& elem : ilist)
for (auto &elem : ilist)
{
atraits::construct(get_alloc(), m_end, elem);
++m_end;
@ -1043,7 +1058,7 @@ private:
}
}
T* choose_data(size_t desired_capacity)
T *choose_data(size_t desired_capacity)
{
if (m_begin == m_dynamic_data)
{
@ -1105,8 +1120,8 @@ private:
}
}
allocator_type& get_alloc() { return static_cast<allocator_type&>(*this); }
const allocator_type& get_alloc() const { return static_cast<const allocator_type&>(*this); }
allocator_type &get_alloc() { return static_cast<allocator_type &>(*this); }
const allocator_type &get_alloc() const { return static_cast<const allocator_type &>(*this); }
pointer m_begin;
pointer m_end;
@ -1118,9 +1133,9 @@ private:
pointer m_dynamic_data;
};
template<typename T, size_t StaticCapacity, size_t RevertToStaticSize, class Alloc>
bool operator==(const small_vector<T, StaticCapacity, RevertToStaticSize, Alloc>& a,
const small_vector<T, StaticCapacity, RevertToStaticSize, Alloc>& b)
template <typename T, size_t StaticCapacity, size_t RevertToStaticSize, class Alloc>
bool operator==(const small_vector<T, StaticCapacity, RevertToStaticSize, Alloc> &a,
const small_vector<T, StaticCapacity, RevertToStaticSize, Alloc> &b)
{
if (a.size() != b.size())
{
@ -1136,9 +1151,9 @@ bool operator==(const small_vector<T, StaticCapacity, RevertToStaticSize, Alloc>
return true;
}
template<typename T, size_t StaticCapacity, size_t RevertToStaticSize, class Alloc>
bool operator!=(const small_vector<T, StaticCapacity, RevertToStaticSize, Alloc>& a,
const small_vector<T, StaticCapacity, RevertToStaticSize, Alloc>& b)
template <typename T, size_t StaticCapacity, size_t RevertToStaticSize, class Alloc>
bool operator!=(const small_vector<T, StaticCapacity, RevertToStaticSize, Alloc> &a,
const small_vector<T, StaticCapacity, RevertToStaticSize, Alloc> &b)
{
if (a.size() != b.size())
{

View File

@ -1,4 +1,4 @@
/* Copyright 2019-2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,6 +1,6 @@
/* This file is generated by tools/stackvm_gen/IsaGen at 2021/5/28 11:52:08 +08:00.
/* This file is generated by tools/stackvm_gen/IsaGen at 2021/7/14 19:17:48 +08:00.
*
* Copyright 2020 Canaan Inc.
* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -1148,24 +1148,6 @@ struct op_reader<tensor_call_op_t>
}
};
template <>
struct op_reader<tensor_concat_op_t>
{
tensor_concat_op_t operator()(span_reader &reader) const
{
tensor_concat_op_t op(default_init);
op.opcode = static_cast<opcode_t>(reader.read_unaligned<uint8_t>());
op.funct = static_cast<tensor_function_t>(reader.read_unaligned<uint16_t>());
op.datatype = static_cast<datatype_t>(reader.read_unaligned<uint8_t>());
op.num_src = reader.read_unaligned<uint8_t>();
op.axis = reader.read_unaligned<uint8_t>();
op.rshape_dims = reader.read_unaligned<uint8_t>();
op.rshape_dest = reader.read_unaligned<uint8_t>();
op.rstride_dest = reader.read_unaligned<uint8_t>();
return op;
}
};
template <>
struct op_reader<tensor_conv2d_op_t>
{
@ -1192,6 +1174,22 @@ struct op_reader<tensor_conv2d_op_t>
}
};
template <>
struct op_reader<tensor_copy_op_t>
{
tensor_copy_op_t operator()(span_reader &reader) const
{
tensor_copy_op_t op(default_init);
op.opcode = static_cast<opcode_t>(reader.read_unaligned<uint8_t>());
op.funct = static_cast<tensor_function_t>(reader.read_unaligned<uint16_t>());
op.datatype = static_cast<datatype_t>(reader.read_unaligned<uint8_t>());
op.rshape = reader.read_unaligned<uint8_t>();
op.rstride_src = reader.read_unaligned<uint8_t>();
op.rstride_dest = reader.read_unaligned<uint8_t>();
return op;
}
};
template <>
struct op_reader<tensor_convert_op_t>
{
@ -1226,6 +1224,44 @@ struct op_reader<tensor_dequantize_op_t>
}
};
template <>
struct op_reader<tensor_gather_op_t>
{
tensor_gather_op_t operator()(span_reader &reader) const
{
tensor_gather_op_t op(default_init);
op.opcode = static_cast<opcode_t>(reader.read_unaligned<uint8_t>());
op.funct = static_cast<tensor_function_t>(reader.read_unaligned<uint16_t>());
op.datatype = static_cast<datatype_t>(reader.read_unaligned<uint8_t>());
op.rshape_src = reader.read_unaligned<uint8_t>();
op.rshape_dest = reader.read_unaligned<uint8_t>();
op.rstride_src = reader.read_unaligned<uint8_t>();
op.rstride_dest = reader.read_unaligned<uint8_t>();
op.rshape_indices = reader.read_unaligned<uint8_t>();
op.axis = reader.read_unaligned<uint8_t>();
return op;
}
};
template <>
struct op_reader<tensor_gather_nd_op_t>
{
tensor_gather_nd_op_t operator()(span_reader &reader) const
{
tensor_gather_nd_op_t op(default_init);
op.opcode = static_cast<opcode_t>(reader.read_unaligned<uint8_t>());
op.funct = static_cast<tensor_function_t>(reader.read_unaligned<uint16_t>());
op.datatype = static_cast<datatype_t>(reader.read_unaligned<uint8_t>());
op.rshape_src = reader.read_unaligned<uint8_t>();
op.rshape_dest = reader.read_unaligned<uint8_t>();
op.rstride_src = reader.read_unaligned<uint8_t>();
op.rstride_dest = reader.read_unaligned<uint8_t>();
op.rshape_indices = reader.read_unaligned<uint8_t>();
op.batch_dims = reader.read_unaligned<uint8_t>();
return op;
}
};
template <>
struct op_reader<tensor_lut1d_op_t>
{
@ -1243,6 +1279,24 @@ struct op_reader<tensor_lut1d_op_t>
}
};
template <>
struct op_reader<tensor_onehot_op_t>
{
tensor_onehot_op_t operator()(span_reader &reader) const
{
tensor_onehot_op_t op(default_init);
op.opcode = static_cast<opcode_t>(reader.read_unaligned<uint8_t>());
op.funct = static_cast<tensor_function_t>(reader.read_unaligned<uint16_t>());
op.datatype = static_cast<datatype_t>(reader.read_unaligned<uint8_t>());
op.rshape_indices = reader.read_unaligned<uint8_t>();
op.rshape_dest = reader.read_unaligned<uint8_t>();
op.rstride_dest = reader.read_unaligned<uint8_t>();
op.axis = reader.read_unaligned<uint8_t>();
op.onehot_mode = static_cast<onehot_mode_t>(reader.read_unaligned<uint8_t>());
return op;
}
};
template <>
struct op_reader<tensor_pad_op_t>
{
@ -1322,6 +1376,25 @@ struct op_reader<tensor_reduce_window2d_op_t>
}
};
template <>
struct op_reader<tensor_resize_image_op_t>
{
tensor_resize_image_op_t operator()(span_reader &reader) const
{
tensor_resize_image_op_t op(default_init);
op.opcode = static_cast<opcode_t>(reader.read_unaligned<uint8_t>());
op.funct = static_cast<tensor_function_t>(reader.read_unaligned<uint16_t>());
op.datatype = static_cast<datatype_t>(reader.read_unaligned<uint8_t>());
op.rshape_src = reader.read_unaligned<uint8_t>();
op.rstride_src = reader.read_unaligned<uint8_t>();
op.rstride_dest = reader.read_unaligned<uint8_t>();
op.align_corners = reader.read_unaligned<bool>();
op.half_pixel_centers = reader.read_unaligned<bool>();
op.image_resize_mode = static_cast<image_resize_mode_t>(reader.read_unaligned<uint8_t>());
return op;
}
};
template <>
struct op_reader<tensor_slice_op_t>
{
@ -1485,15 +1558,19 @@ public:
virtual result<void> visit(NNCASE_UNUSED const tensor_broadcast_op_t &op) noexcept { return ok(); }
virtual result<void> visit(NNCASE_UNUSED const tensor_binary_op_t &op) noexcept { return ok(); }
virtual result<void> visit(NNCASE_UNUSED const tensor_call_op_t &op) noexcept { return ok(); }
virtual result<void> visit(NNCASE_UNUSED const tensor_concat_op_t &op) noexcept { return ok(); }
virtual result<void> visit(NNCASE_UNUSED const tensor_conv2d_op_t &op) noexcept { return ok(); }
virtual result<void> visit(NNCASE_UNUSED const tensor_copy_op_t &op) noexcept { return ok(); }
virtual result<void> visit(NNCASE_UNUSED const tensor_convert_op_t &op) noexcept { return ok(); }
virtual result<void> visit(NNCASE_UNUSED const tensor_dequantize_op_t &op) noexcept { return ok(); }
virtual result<void> visit(NNCASE_UNUSED const tensor_gather_op_t &op) noexcept { return ok(); }
virtual result<void> visit(NNCASE_UNUSED const tensor_gather_nd_op_t &op) noexcept { return ok(); }
virtual result<void> visit(NNCASE_UNUSED const tensor_lut1d_op_t &op) noexcept { return ok(); }
virtual result<void> visit(NNCASE_UNUSED const tensor_onehot_op_t &op) noexcept { return ok(); }
virtual result<void> visit(NNCASE_UNUSED const tensor_pad_op_t &op) noexcept { return ok(); }
virtual result<void> visit(NNCASE_UNUSED const tensor_quantize_op_t &op) noexcept { return ok(); }
virtual result<void> visit(NNCASE_UNUSED const tensor_reduce_op_t &op) noexcept { return ok(); }
virtual result<void> visit(NNCASE_UNUSED const tensor_reduce_window2d_op_t &op) noexcept { return ok(); }
virtual result<void> visit(NNCASE_UNUSED const tensor_resize_image_op_t &op) noexcept { return ok(); }
virtual result<void> visit(NNCASE_UNUSED const tensor_slice_op_t &op) noexcept { return ok(); }
virtual result<void> visit(NNCASE_UNUSED const tensor_unary_op_t &op) noexcept { return ok(); }
virtual result<void> visit(NNCASE_UNUSED const tensor_transpose_op_t &op) noexcept { return ok(); }

View File

@ -1,6 +1,6 @@
/* This file is generated by tools/stackvm_gen/IsaGen at 2021/5/28 11:52:08 +08:00.
/* This file is generated by tools/stackvm_gen/IsaGen at 2021/7/14 19:17:48 +08:00.
*
* Copyright 2020 Canaan Inc.
* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -127,25 +127,28 @@ enum class tensor_function_t
BROADCAST = 0x0002,
CALL = 0x0003,
CLAMP = 0x0004,
CONCAT = 0x0005,
CONV2D = 0x0006,
CONV2D_TRANSPOSE = 0x0007,
CONVERT = 0x0008,
CONV2D = 0x0005,
CONV2D_TRANSPOSE = 0x0006,
CONVERT = 0x0007,
COPY = 0x0008,
DEQUANTIZE = 0x0009,
LOGISTIC = 0x000A,
LUT1D = 0x000B,
MATMUL = 0x000C,
PAD = 0x000D,
QUANTIZE = 0x000E,
REDUCE = 0x000F,
REDUCE_WINDOW2D = 0x0010,
RESIZE_IMAGE = 0x0011,
SLICE = 0x0012,
SOFTMAX = 0x0013,
SPACE_TO_BATCH = 0x0014,
TAKE = 0x0015,
TRANSPOSE = 0x0016,
UNARY = 0x0017,
GATHER = 0x000A,
GATHER_ND = 0x000B,
LOGISTIC = 0x000C,
LUT1D = 0x000D,
MATMUL = 0x000E,
ONEHOT = 0x000F,
PAD = 0x0010,
QUANTIZE = 0x0011,
REDUCE = 0x0012,
REDUCE_WINDOW2D = 0x0013,
RESIZE_IMAGE = 0x0014,
SLICE = 0x0015,
SOFTMAX = 0x0016,
SPACE_TO_BATCH = 0x0017,
TAKE = 0x0018,
TRANSPOSE = 0x0019,
UNARY = 0x001A,
};
// Instructions
@ -1273,24 +1276,6 @@ struct tensor_call_op_t
}
};
struct tensor_concat_op_t
{
opcode_t opcode;
tensor_function_t funct;
datatype_t datatype;
uint8_t num_src;
uint8_t axis;
uint8_t rshape_dims;
uint8_t rshape_dest;
uint8_t rstride_dest;
tensor_concat_op_t(default_init_t) noexcept { }
explicit tensor_concat_op_t(datatype_t datatype, uint8_t num_src, uint8_t axis, uint8_t rshape_dims, uint8_t rshape_dest, uint8_t rstride_dest) noexcept
: opcode(opcode_t::TENSOR), funct(tensor_function_t::CONCAT), datatype(datatype), num_src(num_src), axis(axis), rshape_dims(rshape_dims), rshape_dest(rshape_dest), rstride_dest(rstride_dest)
{
}
};
struct tensor_conv2d_op_t
{
opcode_t opcode;
@ -1317,6 +1302,22 @@ struct tensor_conv2d_op_t
}
};
struct tensor_copy_op_t
{
opcode_t opcode;
tensor_function_t funct;
datatype_t datatype;
uint8_t rshape;
uint8_t rstride_src;
uint8_t rstride_dest;
tensor_copy_op_t(default_init_t) noexcept { }
explicit tensor_copy_op_t(datatype_t datatype, uint8_t rshape, uint8_t rstride_src, uint8_t rstride_dest) noexcept
: opcode(opcode_t::TENSOR), funct(tensor_function_t::COPY), datatype(datatype), rshape(rshape), rstride_src(rstride_src), rstride_dest(rstride_dest)
{
}
};
struct tensor_convert_op_t
{
opcode_t opcode;
@ -1351,6 +1352,44 @@ struct tensor_dequantize_op_t
}
};
struct tensor_gather_op_t
{
opcode_t opcode;
tensor_function_t funct;
datatype_t datatype;
uint8_t rshape_src;
uint8_t rshape_dest;
uint8_t rstride_src;
uint8_t rstride_dest;
uint8_t rshape_indices;
uint8_t axis;
tensor_gather_op_t(default_init_t) noexcept { }
explicit tensor_gather_op_t(datatype_t datatype, uint8_t rshape_src, uint8_t rshape_dest, uint8_t rstride_src, uint8_t rstride_dest, uint8_t rshape_indices, uint8_t axis) noexcept
: opcode(opcode_t::TENSOR), funct(tensor_function_t::GATHER), datatype(datatype), rshape_src(rshape_src), rshape_dest(rshape_dest), rstride_src(rstride_src), rstride_dest(rstride_dest), rshape_indices(rshape_indices), axis(axis)
{
}
};
struct tensor_gather_nd_op_t
{
opcode_t opcode;
tensor_function_t funct;
datatype_t datatype;
uint8_t rshape_src;
uint8_t rshape_dest;
uint8_t rstride_src;
uint8_t rstride_dest;
uint8_t rshape_indices;
uint8_t batch_dims;
tensor_gather_nd_op_t(default_init_t) noexcept { }
explicit tensor_gather_nd_op_t(datatype_t datatype, uint8_t rshape_src, uint8_t rshape_dest, uint8_t rstride_src, uint8_t rstride_dest, uint8_t rshape_indices, uint8_t batch_dims) noexcept
: opcode(opcode_t::TENSOR), funct(tensor_function_t::GATHER_ND), datatype(datatype), rshape_src(rshape_src), rshape_dest(rshape_dest), rstride_src(rstride_src), rstride_dest(rstride_dest), rshape_indices(rshape_indices), batch_dims(batch_dims)
{
}
};
struct tensor_lut1d_op_t
{
opcode_t opcode;
@ -1368,6 +1407,24 @@ struct tensor_lut1d_op_t
}
};
struct tensor_onehot_op_t
{
opcode_t opcode;
tensor_function_t funct;
datatype_t datatype;
uint8_t rshape_indices;
uint8_t rshape_dest;
uint8_t rstride_dest;
uint8_t axis;
onehot_mode_t onehot_mode;
tensor_onehot_op_t(default_init_t) noexcept { }
explicit tensor_onehot_op_t(datatype_t datatype, uint8_t rshape_indices, uint8_t rshape_dest, uint8_t rstride_dest, uint8_t axis, onehot_mode_t onehot_mode) noexcept
: opcode(opcode_t::TENSOR), funct(tensor_function_t::ONEHOT), datatype(datatype), rshape_indices(rshape_indices), rshape_dest(rshape_dest), rstride_dest(rstride_dest), axis(axis), onehot_mode(onehot_mode)
{
}
};
struct tensor_pad_op_t
{
opcode_t opcode;
@ -1447,6 +1504,25 @@ struct tensor_reduce_window2d_op_t
}
};
struct tensor_resize_image_op_t
{
opcode_t opcode;
tensor_function_t funct;
datatype_t datatype;
uint8_t rshape_src;
uint8_t rstride_src;
uint8_t rstride_dest;
bool align_corners;
bool half_pixel_centers;
image_resize_mode_t image_resize_mode;
tensor_resize_image_op_t(default_init_t) noexcept { }
explicit tensor_resize_image_op_t(datatype_t datatype, uint8_t rshape_src, uint8_t rstride_src, uint8_t rstride_dest, bool align_corners, bool half_pixel_centers, image_resize_mode_t image_resize_mode) noexcept
: opcode(opcode_t::TENSOR), funct(tensor_function_t::RESIZE_IMAGE), datatype(datatype), rshape_src(rshape_src), rstride_src(rstride_src), rstride_dest(rstride_dest), align_corners(align_corners), half_pixel_centers(half_pixel_centers), image_resize_mode(image_resize_mode)
{
}
};
struct tensor_slice_op_t
{
opcode_t opcode;

View File

@ -1,4 +1,4 @@
/* Copyright 2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,4 +1,4 @@
/* Copyright 2020 Canaan Inc.
/* Copyright 2019-2021 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -14,4 +14,4 @@
*/
#pragma once
#define NNCASE_VERSION "1.0.0"
#define NNCASE_GIT_DESC "0dc08ae"
#define NNCASE_VERSION_SUFFIX "-8c384a4"

View File

@ -1 +1,10 @@
include(${CMAKE_CURRENT_LIST_DIR}/nncaseruntimeTargets.cmake)
if(NOT TARGET mpark_variant)
find_package(mpark_variant REQUIRED)
endif()
if(NOT TARGET gsl-lite)
find_package(gsl-lite REQUIRED)
endif()

View File

@ -54,14 +54,14 @@ endif()
add_library(kernels INTERFACE IMPORTED)
set_target_properties(kernels PROPERTIES
INTERFACE_LINK_LIBRARIES "CONAN_PKG::gsl-lite;CONAN_PKG::mpark-variant"
INTERFACE_LINK_LIBRARIES "gsl::gsl-lite;mpark_variant::mpark_variant"
)
# Create imported target runtime
add_library(runtime INTERFACE IMPORTED)
set_target_properties(runtime PROPERTIES
INTERFACE_LINK_LIBRARIES "CONAN_PKG::gsl-lite;CONAN_PKG::mpark-variant;\$<LINK_ONLY:kernels>"
INTERFACE_LINK_LIBRARIES "gsl::gsl-lite;mpark_variant::mpark_variant;\$<LINK_ONLY:kernels>"
)
# Create imported target nncaseruntime
@ -69,7 +69,7 @@ add_library(nncaseruntime STATIC IMPORTED)
set_target_properties(nncaseruntime PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
INTERFACE_LINK_LIBRARIES "\$<LINK_ONLY:kernels>;\$<LINK_ONLY:runtime>;\$<LINK_ONLY:runtime_stackvm>;CONAN_PKG::gsl-lite;CONAN_PKG::mpark-variant"
INTERFACE_LINK_LIBRARIES "\$<LINK_ONLY:kernels>;\$<LINK_ONLY:runtime>;\$<LINK_ONLY:runtime_stackvm>;gsl::gsl-lite;mpark_variant::mpark_variant"
)
# Create imported target runtime_stackvm

View File

@ -49,7 +49,7 @@ public:
result<void> run_kmodel(const uint8_t *src, dmac_channel_number_t dma_ch)
{
#ifdef NNCASE_DEBUG
#if NNCASE_DEBUG
auto micro = sysctl_get_time_us();
#endif
try_(interp_.options().set("dma_ch", (uint32_t)dma_ch));
@ -59,7 +59,7 @@ public:
try_(hrt::sync(input_tensor, hrt::sync_write_back));
try_(interp_.input_tensor(0, input_tensor));
try_(interp_.run());
#ifdef NNCASE_DEBUG
#if NNCASE_DEBUG
auto duration = sysctl_get_time_us() - micro;
printf("run kmodel takes %f ms.\n", duration / 1e3f);
#endif

View File

@ -3,3 +3,4 @@
add_library(gsl-lite INTERFACE)
target_include_directories(gsl-lite INTERFACE include)
add_library(CONAN_PKG::gsl-lite ALIAS gsl-lite)
add_library(gsl::gsl-lite ALIAS gsl-lite)

View File

@ -1,5 +1,6 @@
cmake_minimum_required (VERSION 3.8)
add_library(mpark-variant INTERFACE)
target_include_directories(mpark-variant INTERFACE include)
add_library(CONAN_PKG::mpark-variant ALIAS mpark-variant)
add_library(mpark_variant INTERFACE)
target_include_directories(mpark_variant INTERFACE include)
add_library(mpark_variant::mpark_variant ALIAS mpark_variant)
add_library(CONAN_PKG::mpark-variant ALIAS mpark_variant)