-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfused_kernel_ops.hpp
More file actions
76 lines (66 loc) · 2.56 KB
/
Copy pathfused_kernel_ops.hpp
File metadata and controls
76 lines (66 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#pragma once
#include "active_kernel.hpp"
#include "kernel_activation.hpp"
#include "tensor.hpp"
#include "tensor_factory.hpp"
#include <array>
#include <cstdint>
namespace fused_ops
{
inline Tensor NhwcView(float* data, uint32_t h, uint32_t w, uint32_t c)
{
const std::array<uint32_t, 3> shape = {h, w, c};
return TensorFactory::ViewND(data, 3, shape);
}
inline void BatchNormInPlace(Tensor& tensor, int channels, const float* scale, const float* bias)
{
Kernels::BatchNorm2dForward(tensor, scale, bias, channels, tensor);
}
inline void ReluInPlace(Tensor& tensor)
{
Kernels::ReLU(tensor, tensor);
}
inline void MatAddInPlace(Tensor& accum, const Tensor& addend)
{
Kernels::MatAddND(accum, addend, accum);
}
// Residual epilogue used by ResNet BasicBlock: out = ReLU(branch + shortcut).
// Routes through Kernels::MatAddND (CMSIS-NN / XNNPACK / reference).
inline void MatAddThenRelu(const Tensor& branch, const Tensor& shortcut, Tensor& out)
{
Kernels::MatAddND(branch, shortcut, out);
ReluInPlace(out);
}
inline void GeluInPlace(Tensor& tensor)
{
Kernels::Gelu(tensor, tensor);
}
inline void Grn2dInPlace(Tensor& tensor,
int channels,
const float* gamma,
const float* beta,
float eps,
float* channel_norm_scratch)
{
Kernels::Grn2dForward(
tensor, gamma, beta, channels, eps, channel_norm_scratch, tensor);
}
inline void FullyConnected1x1(const float* input,
int in_features,
int out_features,
float* weights,
const float* bias,
float* output)
{
Tensor in_tensor =
TensorFactory::View2D(const_cast<float*>(input), 1, static_cast<uint32_t>(in_features));
Tensor weight_tensor = TensorFactory::View2D(
weights, static_cast<uint32_t>(out_features), static_cast<uint32_t>(in_features));
Tensor bias_tensor =
TensorFactory::View2D(const_cast<float*>(bias), 1, static_cast<uint32_t>(out_features));
Tensor out_tensor =
TensorFactory::View2D(output, 1, static_cast<uint32_t>(out_features));
Kernels::FullyConnectedWithBias(
in_tensor, weight_tensor, bias_tensor, NetkitKernelActivation::None, out_tensor);
}
}