Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
67005d42
M
mindspore
项目概览
magicwindyyd
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindspore
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
67005d42
编写于
8月 03, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
8月 03, 2020
浏览文件
操作
浏览文件
下载
差异文件
!3842 Add new hms ops of crop with type of int8
Merge pull request !3842 from liuwenhao/master
上级
aafa76be
b3cac13a
变更
14
展开全部
隐藏空白更改
内联
并排
Showing
14 changed file
with
1276 addition
and
41 deletion
+1276
-41
mindspore/lite/src/populate_parameter.cc
mindspore/lite/src/populate_parameter.cc
+1
-0
mindspore/lite/src/runtime/kernel/arm/base/crop_base.cc
mindspore/lite/src/runtime/kernel/arm/base/crop_base.cc
+108
-0
mindspore/lite/src/runtime/kernel/arm/base/crop_base.h
mindspore/lite/src/runtime/kernel/arm/base/crop_base.h
+46
-0
mindspore/lite/src/runtime/kernel/arm/fp32/crop.cc
mindspore/lite/src/runtime/kernel/arm/fp32/crop.cc
+1
-32
mindspore/lite/src/runtime/kernel/arm/fp32/crop.h
mindspore/lite/src/runtime/kernel/arm/fp32/crop.h
+4
-2
mindspore/lite/src/runtime/kernel/arm/int8/crop_int8.cc
mindspore/lite/src/runtime/kernel/arm/int8/crop_int8.cc
+96
-0
mindspore/lite/src/runtime/kernel/arm/int8/crop_int8.h
mindspore/lite/src/runtime/kernel/arm/int8/crop_int8.h
+52
-0
mindspore/lite/src/runtime/kernel/arm/opclib/crop_parameter.h
...spore/lite/src/runtime/kernel/arm/opclib/crop_parameter.h
+37
-0
mindspore/lite/src/runtime/kernel/arm/opclib/fp32/crop.cc
mindspore/lite/src/runtime/kernel/arm/opclib/fp32/crop.cc
+1
-0
mindspore/lite/src/runtime/kernel/arm/opclib/fp32/crop.h
mindspore/lite/src/runtime/kernel/arm/opclib/fp32/crop.h
+1
-7
mindspore/lite/src/runtime/kernel/arm/opclib/int8/crop_int8.cc
...pore/lite/src/runtime/kernel/arm/opclib/int8/crop_int8.cc
+222
-0
mindspore/lite/src/runtime/kernel/arm/opclib/int8/crop_int8.h
...spore/lite/src/runtime/kernel/arm/opclib/int8/crop_int8.h
+28
-0
mindspore/lite/src/runtime/kernel/arm/opclib/quantization/quantize.h
...ite/src/runtime/kernel/arm/opclib/quantization/quantize.h
+7
-0
mindspore/lite/test/ut/src/runtime/kernel/arm/int8/crop_int8_tests.cc
...te/test/ut/src/runtime/kernel/arm/int8/crop_int8_tests.cc
+672
-0
未找到文件。
mindspore/lite/src/populate_parameter.cc
浏览文件 @
67005d42
...
...
@@ -950,6 +950,7 @@ CropParameter *PopulateCropParameter(const lite::Primitive *primitive) {
return
nullptr
;
}
parameter
->
axis_
=
param
->
axis
();
parameter
->
offset_size_
=
param_offset
->
size
();
for
(
int
i
=
0
;
i
<
param_offset
->
size
();
++
i
)
{
parameter
->
offset_
[
i
]
=
param_offset
->
Get
(
i
);
}
...
...
mindspore/lite/src/runtime/kernel/arm/base/crop_base.cc
0 → 100644
浏览文件 @
67005d42
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* 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 "src/runtime/kernel/arm/base/crop_base.h"
#include <vector>
#include "src/runtime/kernel/arm/int8/crop_int8.h"
#include "src/runtime/kernel/arm/fp32/crop.h"
#include "schema/model_generated.h"
#include "src/kernel_factory.h"
#include "include/errorcode.h"
#include "include/context.h"
using
mindspore
::
lite
::
KernelRegistrar
;
using
mindspore
::
lite
::
RET_ERROR
;
using
mindspore
::
lite
::
RET_OK
;
using
mindspore
::
schema
::
PrimitiveType_Crop
;
namespace
mindspore
::
kernel
{
int
CropBaseCPUKernel
::
Init
()
{
return
RET_OK
;
}
kernel
::
LiteKernel
*
CpuCropInt8KernelCreator
(
const
std
::
vector
<
lite
::
tensor
::
Tensor
*>
&
inputs
,
const
std
::
vector
<
lite
::
tensor
::
Tensor
*>
&
outputs
,
OpParameter
*
opParameter
,
const
Context
*
ctx
,
const
kernel
::
KernelKey
&
desc
)
{
if
(
opParameter
==
nullptr
)
{
MS_LOG
(
ERROR
)
<<
"Input opParameter is nullptr!"
;
return
nullptr
;
}
MS_ASSERT
(
desc
.
type
==
schema
::
PrimitiveType_Crop
);
auto
*
kernel
=
new
(
std
::
nothrow
)
CropInt8CPUKernel
(
opParameter
,
inputs
,
outputs
,
ctx
);
if
(
kernel
==
nullptr
)
{
MS_LOG
(
ERROR
)
<<
"new CropCPUKernel fail!"
;
return
nullptr
;
}
auto
ret
=
kernel
->
Init
();
if
(
ret
!=
RET_OK
)
{
delete
kernel
;
MS_LOG
(
ERROR
)
<<
"Init kernel failed, name: "
<<
opParameter
->
name_
<<
", type: "
<<
schema
::
EnumNamePrimitiveType
(
static_cast
<
schema
::
PrimitiveType
>
(
opParameter
->
type_
));
return
nullptr
;
}
return
kernel
;
}
kernel
::
LiteKernel
*
CpuCropInt32KernelCreator
(
const
std
::
vector
<
lite
::
tensor
::
Tensor
*>
&
inputs
,
const
std
::
vector
<
lite
::
tensor
::
Tensor
*>
&
outputs
,
OpParameter
*
opParameter
,
const
Context
*
ctx
,
const
kernel
::
KernelKey
&
desc
)
{
if
(
opParameter
==
nullptr
)
{
MS_LOG
(
ERROR
)
<<
"Input opParameter is nullptr!"
;
return
nullptr
;
}
MS_ASSERT
(
desc
.
type
==
schema
::
PrimitiveType_Crop
);
auto
*
kernel
=
new
(
std
::
nothrow
)
CropCPUKernel
(
opParameter
,
inputs
,
outputs
,
ctx
);
if
(
kernel
==
nullptr
)
{
MS_LOG
(
ERROR
)
<<
"new CropCPUKernel fail!"
;
return
nullptr
;
}
auto
ret
=
kernel
->
Init
();
if
(
ret
!=
RET_OK
)
{
delete
kernel
;
MS_LOG
(
ERROR
)
<<
"Init kernel failed, name: "
<<
opParameter
->
name_
<<
", type: "
<<
schema
::
EnumNamePrimitiveType
(
static_cast
<
schema
::
PrimitiveType
>
(
opParameter
->
type_
));
return
nullptr
;
}
return
kernel
;
}
kernel
::
LiteKernel
*
CpuCropFp32KernelCreator
(
const
std
::
vector
<
lite
::
tensor
::
Tensor
*>
&
inputs
,
const
std
::
vector
<
lite
::
tensor
::
Tensor
*>
&
outputs
,
OpParameter
*
opParameter
,
const
Context
*
ctx
,
const
kernel
::
KernelKey
&
desc
)
{
if
(
opParameter
==
nullptr
)
{
MS_LOG
(
ERROR
)
<<
"Input opParameter is nullptr!"
;
return
nullptr
;
}
MS_ASSERT
(
desc
.
type
==
schema
::
PrimitiveType_Crop
);
auto
*
kernel
=
new
(
std
::
nothrow
)
CropCPUKernel
(
opParameter
,
inputs
,
outputs
,
ctx
);
if
(
kernel
==
nullptr
)
{
MS_LOG
(
ERROR
)
<<
"new CropCPUKernel fail!"
;
return
nullptr
;
}
auto
ret
=
kernel
->
Init
();
if
(
ret
!=
RET_OK
)
{
delete
kernel
;
MS_LOG
(
ERROR
)
<<
"Init kernel failed, name: "
<<
opParameter
->
name_
<<
", type: "
<<
schema
::
EnumNamePrimitiveType
(
static_cast
<
schema
::
PrimitiveType
>
(
opParameter
->
type_
));
return
nullptr
;
}
return
kernel
;
}
REG_KERNEL
(
kCPU
,
kNumberTypeInt8
,
PrimitiveType_Crop
,
CpuCropInt8KernelCreator
)
REG_KERNEL
(
kCPU
,
kNumberTypeInt32
,
PrimitiveType_Crop
,
CpuCropInt32KernelCreator
)
REG_KERNEL
(
kCPU
,
kNumberTypeFloat32
,
PrimitiveType_Crop
,
CpuCropFp32KernelCreator
)
}
// namespace mindspore::kernel
mindspore/lite/src/runtime/kernel/arm/base/crop_base.h
0 → 100644
浏览文件 @
67005d42
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* 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.
*/
#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_CROP_BASE_H_
#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_CROP_BASE_H_
#include <vector>
#include "src/lite_kernel.h"
#include "src/runtime/kernel/arm/opclib/crop_parameter.h"
using
mindspore
::
lite
::
Context
;
namespace
mindspore
::
kernel
{
class
CropBaseCPUKernel
:
public
LiteKernel
{
public:
CropBaseCPUKernel
(
OpParameter
*
parameter
,
const
std
::
vector
<
lite
::
tensor
::
Tensor
*>
&
inputs
,
const
std
::
vector
<
lite
::
tensor
::
Tensor
*>
&
outputs
,
const
Context
*
ctx
)
:
LiteKernel
(
parameter
,
inputs
,
outputs
),
ctx_
(
ctx
),
thread_count_
(
ctx
->
threadNum
)
{
opParameter
->
thread_num_
=
ctx
->
threadNum
;
}
~
CropBaseCPUKernel
()
=
default
;
int
Init
()
override
;
int
ReSize
()
override
{
return
0
;
}
int
Run
()
override
{
return
0
;
}
protected:
int
thread_count_
;
const
Context
*
ctx_
;
};
}
// namespace mindspore::kernel
#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_CROP_BASE_H_
mindspore/lite/src/runtime/kernel/arm/fp32/crop.cc
浏览文件 @
67005d42
...
...
@@ -17,6 +17,7 @@
#include "schema/model_generated.h"
#include "src/kernel_registry.h"
#include "src/runtime/kernel/arm/opclib/fp32/crop.h"
#include "src/runtime/kernel/arm/opclib/crop_parameter.h"
#include "include/errorcode.h"
#include "src/runtime/runtime_api.h"
...
...
@@ -77,36 +78,4 @@ int CropCPUKernel::Run() {
}
return
RET_OK
;
}
kernel
::
LiteKernel
*
CpuCropFp32KernelCreator
(
const
std
::
vector
<
lite
::
tensor
::
Tensor
*>
&
inputs
,
const
std
::
vector
<
lite
::
tensor
::
Tensor
*>
&
outputs
,
OpParameter
*
op_parameter
,
const
lite
::
Context
*
ctx
,
const
kernel
::
KernelKey
&
desc
)
{
if
(
op_parameter
==
nullptr
)
{
MS_LOG
(
ERROR
)
<<
"Input op_parameter is nullptr!"
;
return
nullptr
;
}
if
(
ctx
==
nullptr
)
{
MS_LOG
(
ERROR
)
<<
"Input context is nullptr!"
;
return
nullptr
;
}
MS_ASSERT
(
desc
.
type
==
schema
::
PrimitiveType_Crop
);
op_parameter
->
thread_num_
=
ctx
->
threadNum
;
auto
*
kernel
=
new
(
std
::
nothrow
)
CropCPUKernel
(
op_parameter
,
inputs
,
outputs
);
if
(
kernel
==
nullptr
)
{
MS_LOG
(
ERROR
)
<<
"new CropCPUKernel fail!"
;
return
nullptr
;
}
auto
ret
=
kernel
->
Init
();
if
(
ret
!=
RET_OK
)
{
delete
kernel
;
MS_LOG
(
ERROR
)
<<
"Init kernel failed, name: "
<<
op_parameter
->
name_
<<
", type: "
<<
schema
::
EnumNamePrimitiveType
(
static_cast
<
schema
::
PrimitiveType
>
(
op_parameter
->
type_
));
return
nullptr
;
}
return
kernel
;
}
REG_KERNEL
(
kCPU
,
kNumberTypeFloat32
,
PrimitiveType_Crop
,
CpuCropFp32KernelCreator
)
}
// namespace mindspore::kernel
mindspore/lite/src/runtime/kernel/arm/fp32/crop.h
浏览文件 @
67005d42
...
...
@@ -18,12 +18,14 @@
#include <vector>
#include "src/lite_kernel.h"
#include "src/runtime/kernel/arm/base/layout_transform.h"
#include "src/runtime/kernel/arm/base/crop_base.h"
namespace
mindspore
::
kernel
{
class
CropCPUKernel
:
public
Lite
Kernel
{
class
CropCPUKernel
:
public
CropBaseCPU
Kernel
{
public:
CropCPUKernel
(
OpParameter
*
parameter
,
const
std
::
vector
<
lite
::
tensor
::
Tensor
*>
&
inputs
,
const
std
::
vector
<
lite
::
tensor
::
Tensor
*>
&
outputs
)
:
LiteKernel
(
parameter
,
inputs
,
outputs
)
{}
const
std
::
vector
<
lite
::
tensor
::
Tensor
*>
&
outputs
,
const
Context
*
ctx
)
:
CropBaseCPUKernel
(
parameter
,
inputs
,
outputs
,
ctx
)
{}
~
CropCPUKernel
()
=
default
;
int
Init
()
override
;
int
ReSize
()
override
{
return
0
;
}
...
...
mindspore/lite/src/runtime/kernel/arm/int8/crop_int8.cc
0 → 100644
浏览文件 @
67005d42
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* 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 "src/runtime/kernel/arm/int8/crop_int8.h"
#include <limits>
#include "src/runtime/kernel/arm/opclib/int8/crop_int8.h"
#include "include/errorcode.h"
#include "src/runtime/runtime_api.h"
using
mindspore
::
kernel
::
KERNEL_ARCH
::
kCPU
;
using
mindspore
::
lite
::
RET_ERROR
;
using
mindspore
::
lite
::
RET_OK
;
namespace
mindspore
::
kernel
{
int
CropInt8CPUKernel
::
Init
()
{
CropBaseCPUKernel
::
Init
();
auto
*
input_tensor
=
inputs_
.
at
(
kInputIndex
);
auto
in_quant_args
=
input_tensor
->
GetQuantParams
();
crop_para_
->
quant_arg
.
in_args_
.
scale_
=
in_quant_args
.
front
().
scale
;
crop_para_
->
quant_arg
.
in_args_
.
zp_
=
in_quant_args
.
front
().
zeroPoint
;
auto
input_dim
=
input_tensor
->
shape
().
size
();
MS_ASSERT
(
input_dim
<=
CROP_OFFSET_MAX_SIZE
);
crop_para_
->
input_dim_
=
input_dim
;
auto
*
out_tensor
=
outputs_
.
at
(
kOutputIndex
);
auto
out_quant_args
=
out_tensor
->
GetQuantParams
();
crop_para_
->
quant_arg
.
out_args_
.
scale_
=
out_quant_args
.
front
().
scale
;
crop_para_
->
quant_arg
.
out_args_
.
zp_
=
out_quant_args
.
front
().
zeroPoint
;
crop_para_
->
in_shape_
=
input_tensor
->
shape
().
data
();
crop_para_
->
out_shape_
=
out_tensor
->
shape
().
data
();
crop_para_
->
quant_arg
.
output_activation_max_
=
std
::
numeric_limits
<
int8_t
>::
max
();
crop_para_
->
quant_arg
.
output_activation_min_
=
std
::
numeric_limits
<
int8_t
>::
min
();
PadOffset
(
input_dim
,
crop_para_
);
return
RET_OK
;
}
int
CropInt8CPUKernel
::
ReSize
()
{
return
0
;
}
int
CropInt8CPUKernel
::
Run
()
{
auto
ret
=
LiteBackendParallelLaunch
(
CropInt8Run
,
this
,
thread_count_
);
return
ret
;
}
void
PadOffset
(
int
input_dim
,
CropParameter
*
crop_para
)
{
auto
axis
=
crop_para
->
axis_
;
auto
offsets_size
=
crop_para
->
offset_size_
;
MS_ASSERT
(
axis
<=
input_dim
);
if
(
offsets_size
>
1
)
{
MS_ASSERT
(
axis
+
offsets_size
==
input_dim
);
}
for
(
int
i
=
0
;
i
<
input_dim
;
i
++
)
{
int
crop_offset
=
0
;
if
(
i
>=
axis
)
{
if
(
offsets_size
==
1
)
{
crop_offset
=
crop_para
->
offset_
[
0
];
}
else
if
(
offsets_size
>
1
)
{
crop_offset
=
crop_para
->
offset_
[
i
-
axis
];
}
}
crop_para
->
in_offset_
[
i
]
=
crop_offset
;
}
}
int
CropInt8Run
(
int
task_id
,
LiteParallelGroupEnv
*
penv
,
void
*
cdata
)
{
auto
crop
=
reinterpret_cast
<
CropInt8CPUKernel
*>
(
cdata
);
crop
->
DoExecute
(
task_id
);
return
RET_OK
;
}
int
CropInt8CPUKernel
::
DoExecute
(
int
task_id
)
{
auto
input_tensor
=
inputs_
.
at
(
kInputIndex
);
auto
out_tensor
=
outputs_
.
at
(
kOutputIndex
);
int8_t
*
input_data
=
reinterpret_cast
<
int8_t
*>
(
input_tensor
->
Data
());
int8_t
*
output_data
=
reinterpret_cast
<
int8_t
*>
(
out_tensor
->
Data
());
Crop
(
input_data
,
output_data
,
task_id
,
crop_para_
);
return
RET_OK
;
}
}
// namespace mindspore::kernel
mindspore/lite/src/runtime/kernel/arm/int8/crop_int8.h
0 → 100644
浏览文件 @
67005d42
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* 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.
*/
#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_INT8_CROP_INT8_H_
#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_INT8_CROP_INT8_H_
#include <vector>
#include "src/lite_kernel.h"
#include "include/context.h"
#include "src/runtime/kernel/arm/base/crop_base.h"
#include "src/runtime/runtime_api.h"
using
mindspore
::
lite
::
Context
;
namespace
mindspore
::
kernel
{
class
CropInt8CPUKernel
:
public
CropBaseCPUKernel
{
public:
CropInt8CPUKernel
(
OpParameter
*
parameter
,
const
std
::
vector
<
lite
::
tensor
::
Tensor
*>
&
inputs
,
const
std
::
vector
<
lite
::
tensor
::
Tensor
*>
&
outputs
,
const
Context
*
ctx
)
:
CropBaseCPUKernel
(
parameter
,
inputs
,
outputs
,
ctx
)
{
crop_para_
=
reinterpret_cast
<
CropParameter
*>
(
opParameter
);
crop_para_
->
thread_count_
=
opParameter
->
thread_num_
;
}
~
CropInt8CPUKernel
()
=
default
;
int
Init
()
override
;
int
ReSize
()
override
;
int
Run
()
override
;
int
DoExecute
(
int
tId
);
private:
CropParameter
*
crop_para_
;
};
int
CropInt8Run
(
int
task_id
,
LiteParallelGroupEnv
*
penv
,
void
*
cdata
);
void
PadOffset
(
int
input_dim
,
CropParameter
*
crop_para
);
}
// namespace mindspore::kernel
#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_INT8_CROP_INT8_H_
mindspore/lite/src/runtime/kernel/arm/opclib/crop_parameter.h
0 → 100644
浏览文件 @
67005d42
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* 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.
*/
#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_OPCLIB_CROP_PARAMETER_H_
#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_OPCLIB_CROP_PARAMETER_H_
#include "src/runtime/kernel/arm/opclib/op_base.h"
#define CROP_OFFSET_MAX_SIZE 4
struct
CropParameter
{
OpParameter
op_parameter_
;
CropQuantArg
quant_arg
;
int
thread_count_
;
int
thread_id_
;
int
offset_size_
;
int64_t
offset_
[
CROP_OFFSET_MAX_SIZE
];
int64_t
in_offset_
[
CROP_OFFSET_MAX_SIZE
];
int64_t
axis_
;
const
int
*
in_shape_
;
const
int
*
out_shape_
;
int
input_dim_
;
};
#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_OPCLIB_CROP_PARAMETER_H_
mindspore/lite/src/runtime/kernel/arm/opclib/fp32/crop.cc
浏览文件 @
67005d42
...
...
@@ -16,6 +16,7 @@
#include "src/runtime/kernel/arm/opclib/fp32/crop.h"
#include <string.h>
#include "src/runtime/kernel/arm/opclib/op_base.h"
#include "src/runtime/kernel/arm/opclib/crop_parameter.h"
void
Pad4DOffset
(
CropParameter
*
crop_param
,
int64_t
*
offset
)
{
int
axis
=
crop_param
->
axis_
;
...
...
mindspore/lite/src/runtime/kernel/arm/opclib/fp32/crop.h
浏览文件 @
67005d42
...
...
@@ -16,16 +16,10 @@
#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_OPCLIB_FP32_CROP_H_
#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_OPCLIB_FP32_CROP_H_
#include "src/runtime/kernel/arm/opclib/op_base.h"
#include "src/runtime/kernel/arm/opclib/crop_parameter.h"
#define CROP_OFFSET_MAX_SIZE 4
struct
CropParameter
{
OpParameter
op_parameter_
;
int64_t
offset_
[
CROP_OFFSET_MAX_SIZE
];
int64_t
axis_
;
int32_t
thread_id_
;
};
void
Crop4D
(
const
float
*
input
,
float
*
output
,
const
int
*
in_shape
,
const
int
*
out_shape
,
CropParameter
*
crop_param
);
void
Crop4DNoParallel
(
const
float
*
input
,
float
*
output
,
const
int
*
in_shape
,
const
int
*
out_shape
,
CropParameter
*
crop_param
);
...
...
mindspore/lite/src/runtime/kernel/arm/opclib/int8/crop_int8.cc
0 → 100644
浏览文件 @
67005d42
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* 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 "src/runtime/kernel/arm/opclib/crop_parameter.h"
#include "src/runtime/kernel/arm/opclib/int8/crop_int8.h"
#include <string.h>
void
Crop
(
const
int8_t
*
input
,
int8_t
*
output
,
int
task_id
,
CropParameter
*
para
)
{
auto
input_dim
=
para
->
input_dim_
;
switch
(
input_dim
)
{
case
1
:
Crop1D
(
input
,
output
,
task_id
,
para
);
break
;
case
2
:
Crop2D
(
input
,
output
,
task_id
,
para
);
break
;
case
3
:
Crop3D
(
input
,
output
,
task_id
,
para
);
break
;
case
4
:
Crop4D
(
input
,
output
,
task_id
,
para
);
break
;
}
}
void
Crop1D
(
const
int8_t
*
input
,
int8_t
*
output
,
int
task_id
,
CropParameter
*
para
)
{
const
int
out_batch
=
para
->
out_shape_
[
0
];
const
int
thread_count
=
para
->
thread_count_
;
int64_t
task_id_stride
=
thread_count
>
1
?
UP_DIV
(
out_batch
,
thread_count
)
:
out_batch
;
float
in_scale
=
para
->
quant_arg
.
in_args_
.
scale_
;
int32_t
in_zp
=
para
->
quant_arg
.
in_args_
.
zp_
;
float
out_scale
=
para
->
quant_arg
.
out_args_
.
scale_
;
int32_t
out_zp
=
para
->
quant_arg
.
out_args_
.
zp_
;
float
scale
=
in_scale
/
out_scale
;
float
bias
=
-
in_zp
*
scale
;
auto
n
=
task_id
*
task_id_stride
;
if
(
n
>=
out_batch
)
{
return
;
}
const
int8_t
*
in_ptr
=
input
+
n
+
para
->
in_offset_
[
0
];
int8_t
*
out_ptr
=
output
+
n
;
int64_t
out_dist_stride
=
MSMIN
(
out_batch
-
task_id
*
task_id_stride
,
task_id_stride
);
if
(
in_scale
==
out_scale
&&
in_zp
==
out_zp
)
{
memcpy
(
out_ptr
,
in_ptr
,
sizeof
(
int8_t
)
*
out_dist_stride
);
}
else
{
for
(
int
i
=
0
;
i
<
out_dist_stride
;
i
++
)
{
int32_t
output_tmp
=
round
(
in_ptr
[
i
]
*
scale
+
bias
)
+
out_zp
;
if
(
output_tmp
>
para
->
quant_arg
.
output_activation_max_
)
{
out_ptr
[
i
]
=
para
->
quant_arg
.
output_activation_max_
;
}
else
if
(
output_tmp
<
para
->
quant_arg
.
output_activation_min_
)
{
out_ptr
[
i
]
=
para
->
quant_arg
.
output_activation_min_
;
}
else
{
out_ptr
[
i
]
=
static_cast
<
int8_t
>
(
output_tmp
);
}
}
}
return
;
}
void
Crop2D
(
const
int8_t
*
input
,
int8_t
*
output
,
int
task_id
,
CropParameter
*
para
)
{
const
int
in_height
=
para
->
in_shape_
[
1
];
const
int
out_batch
=
para
->
out_shape_
[
0
];
const
int
out_height
=
para
->
out_shape_
[
1
];
const
int
thread_count
=
para
->
thread_count_
;
int64_t
task_id_stride
=
thread_count
>
1
?
UP_DIV
(
out_height
,
thread_count
)
:
out_height
;
float
in_scale
=
para
->
quant_arg
.
in_args_
.
scale_
;
int32_t
in_zp
=
para
->
quant_arg
.
in_args_
.
zp_
;
float
out_scale
=
para
->
quant_arg
.
out_args_
.
scale_
;
int32_t
out_zp
=
para
->
quant_arg
.
out_args_
.
zp_
;
float
scale
=
in_scale
/
out_scale
;
float
bias
=
-
in_zp
*
scale
;
for
(
int
n
=
0
;
n
<
out_batch
;
n
++
)
{
auto
h
=
task_id
*
task_id_stride
;
if
(
h
>=
out_height
)
{
return
;
}
const
int8_t
*
in_ptr
=
input
+
(
n
+
para
->
in_offset_
[
0
])
*
in_height
+
h
+
para
->
in_offset_
[
1
];
int8_t
*
out_ptr
=
output
+
n
*
out_height
+
h
;
int64_t
out_dist_stride
=
MSMIN
(
out_height
-
task_id
*
task_id_stride
,
task_id_stride
);
if
(
in_scale
==
out_scale
&&
in_zp
==
out_zp
)
{
memcpy
(
out_ptr
,
in_ptr
,
sizeof
(
int8_t
)
*
out_dist_stride
);
}
else
{
for
(
int
i
=
0
;
i
<
out_dist_stride
;
i
++
)
{
int32_t
output_tmp
=
round
(
in_ptr
[
i
]
*
scale
+
bias
)
+
out_zp
;
if
(
output_tmp
>
para
->
quant_arg
.
output_activation_max_
)
{
out_ptr
[
i
]
=
para
->
quant_arg
.
output_activation_max_
;
}
else
if
(
output_tmp
<
para
->
quant_arg
.
output_activation_min_
)
{
out_ptr
[
i
]
=
para
->
quant_arg
.
output_activation_min_
;
}
else
{
out_ptr
[
i
]
=
static_cast
<
int8_t
>
(
output_tmp
);
}
}
}
}
return
;
}
void
Crop3D
(
const
int8_t
*
input
,
int8_t
*
output
,
int
task_id
,
CropParameter
*
para
)
{
const
int
in_height
=
para
->
in_shape_
[
1
];
const
int
in_width
=
para
->
in_shape_
[
2
];
const
int
out_batch
=
para
->
out_shape_
[
0
];
const
int
out_height
=
para
->
out_shape_
[
1
];
const
int
out_width
=
para
->
out_shape_
[
2
];
const
int
in_stride_h
=
in_width
;
const
int
in_stride_n
=
in_stride_h
*
in_height
;
const
int
out_stride_h
=
out_width
;
const
int
out_stride_n
=
out_stride_h
*
out_height
;
float
in_scale
=
para
->
quant_arg
.
in_args_
.
scale_
;
int32_t
in_zp
=
para
->
quant_arg
.
in_args_
.
zp_
;
float
out_scale
=
para
->
quant_arg
.
out_args_
.
scale_
;
int32_t
out_zp
=
para
->
quant_arg
.
out_args_
.
zp_
;
float
scale
=
in_scale
/
out_scale
;
float
bias
=
-
in_zp
*
scale
;
const
int
thread_count
=
para
->
thread_count_
;
int64_t
task_id_stride
=
thread_count
>
1
?
UP_DIV
(
out_height
,
thread_count
)
:
out_height
;
for
(
int
n
=
0
;
n
<
out_batch
;
n
++
)
{
for
(
int
t
=
0
;
t
<
task_id_stride
;
t
++
)
{
auto
h
=
t
+
task_id
*
task_id_stride
;
if
(
h
>=
out_height
)
{
break
;
}
const
int8_t
*
in_ptr
=
input
+
(
n
+
para
->
in_offset_
[
0
])
*
in_stride_n
+
(
h
+
para
->
in_offset_
[
1
])
*
in_stride_h
+
para
->
in_offset_
[
2
];
int8_t
*
out_ptr
=
output
+
n
*
out_stride_n
+
h
*
out_stride_h
;
if
(
in_scale
==
out_scale
&&
in_zp
==
out_zp
)
{
memcpy
(
out_ptr
,
in_ptr
,
sizeof
(
int8_t
)
*
out_width
);
}
else
{
for
(
int
i
=
0
;
i
<
out_width
;
i
++
)
{
int32_t
output_tmp
=
round
(
in_ptr
[
i
]
*
scale
+
bias
)
+
out_zp
;
if
(
output_tmp
>
para
->
quant_arg
.
output_activation_max_
)
{
out_ptr
[
i
]
=
para
->
quant_arg
.
output_activation_max_
;
}
else
if
(
output_tmp
<
para
->
quant_arg
.
output_activation_min_
)
{
out_ptr
[
i
]
=
para
->
quant_arg
.
output_activation_min_
;
}
else
{
out_ptr
[
i
]
=
static_cast
<
int8_t
>
(
output_tmp
);
}
}
}
}
}
return
;
}
void
Crop4D
(
const
int8_t
*
input
,
int8_t
*
output
,
int
task_id
,
CropParameter
*
para
)
{
const
int
in_height
=
para
->
in_shape_
[
1
];
const
int
in_width
=
para
->
in_shape_
[
2
];
const
int
in_channel
=
para
->
in_shape_
[
3
];
const
int
out_batch
=
para
->
out_shape_
[
0
];
const
int
out_height
=
para
->
out_shape_
[
1
];
const
int
out_width
=
para
->
out_shape_
[
2
];
const
int
out_channel
=
para
->
out_shape_
[
3
];
const
int
in_stride_w
=
in_channel
;
const
int
in_stride_h
=
in_channel
*
in_width
;
const
int
in_stride_n
=
in_stride_h
*
in_height
;
const
int
out_stride_w
=
out_channel
;
const
int
out_stride_h
=
out_channel
*
out_width
;
const
int
out_stride_n
=
out_stride_h
*
out_height
;
float
in_scale
=
para
->
quant_arg
.
in_args_
.
scale_
;
int32_t
in_zp
=
para
->
quant_arg
.
in_args_
.
zp_
;
float
out_scale
=
para
->
quant_arg
.
out_args_
.
scale_
;
int32_t
out_zp
=
para
->
quant_arg
.
out_args_
.
zp_
;
float
scale
=
in_scale
/
out_scale
;
float
bias
=
-
in_zp
*
scale
;
const
int
thread_count
=
para
->
thread_count_
;
int64_t
task_id_stride
=
thread_count
>
1
?
UP_DIV
(
out_height
,
thread_count
)
:
out_height
;
for
(
int
n
=
0
;
n
<
out_batch
;
n
++
)
{
for
(
int
t
=
0
;
t
<
task_id_stride
;
t
++
)
{
auto
h
=
t
+
task_id
*
task_id_stride
;
if
(
h
>=
out_height
)
{
break
;
}
for
(
int
w
=
0
;
w
<
out_width
;
w
++
)
{
const
int8_t
*
in_ptr
=
input
+
(
n
+
para
->
in_offset_
[
0
])
*
in_stride_n
+
(
h
+
para
->
in_offset_
[
1
])
*
in_stride_h
+
(
w
+
para
->
in_offset_
[
2
])
*
in_stride_w
+
para
->
in_offset_
[
3
];
int8_t
*
out_ptr
=
output
+
n
*
out_stride_n
+
h
*
out_stride_h
+
w
*
out_stride_w
;
if
(
in_scale
==
out_scale
&&
in_zp
==
out_zp
)
{
memcpy
(
out_ptr
,
in_ptr
,
sizeof
(
int8_t
)
*
out_channel
);
}
else
{
for
(
int
i
=
0
;
i
<
out_channel
;
i
++
)
{
int32_t
output_tmp
=
round
(
in_ptr
[
i
]
*
scale
+
bias
)
+
out_zp
;
if
(
output_tmp
>
para
->
quant_arg
.
output_activation_max_
)
{
out_ptr
[
i
]
=
para
->
quant_arg
.
output_activation_max_
;
}
else
if
(
output_tmp
<
para
->
quant_arg
.
output_activation_min_
)
{
out_ptr
[
i
]
=
para
->
quant_arg
.
output_activation_min_
;
}
else
{
out_ptr
[
i
]
=
static_cast
<
int8_t
>
(
output_tmp
);
}
}
}
}
}
}
return
;
}
mindspore/lite/src/runtime/kernel/arm/opclib/int8/crop_int8.h
0 → 100644
浏览文件 @
67005d42
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* 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.
*/
#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_OPCLIB_INT8_CROP_INT8_H_
#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_OPCLIB_INT8_CROP_INT8_H_
#include "src/runtime/kernel/arm/opclib/op_base.h"
#include "src/runtime/kernel/arm/opclib/crop_parameter.h"
void
Crop
(
const
int8_t
*
input
,
int8_t
*
output
,
int
task_id
,
CropParameter
*
para
);
void
Crop1D
(
const
int8_t
*
input
,
int8_t
*
output
,
int
task_id
,
CropParameter
*
para
);
void
Crop2D
(
const
int8_t
*
input
,
int8_t
*
output
,
int
task_id
,
CropParameter
*
para
);
void
Crop3D
(
const
int8_t
*
input
,
int8_t
*
output
,
int
task_id
,
CropParameter
*
para
);
void
Crop4D
(
const
int8_t
*
input
,
int8_t
*
output
,
int
task_id
,
CropParameter
*
para
);
#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_OPCLIB_INT8_CROP_INT8_H_
mindspore/lite/src/runtime/kernel/arm/opclib/quantization/quantize.h
浏览文件 @
67005d42
...
...
@@ -75,6 +75,13 @@ struct MulQuantArg {
int
shift_right_
;
};
struct
CropQuantArg
{
QuantArg
in_args_
;
QuantArg
out_args_
;
int
output_activation_min_
;
int
output_activation_max_
;
};
void
QuantizeMultiplier
(
double
double_multiplier
,
int32_t
*
quantized_multiplier
,
int
*
shift
);
inline
void
QuantizeMultiplierSmallerThanOne
(
double
double_multiplier
,
int32_t
*
quantized_multiplier
,
...
...
mindspore/lite/test/ut/src/runtime/kernel/arm/int8/crop_int8_tests.cc
0 → 100644
浏览文件 @
67005d42
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录