3 #include "smaug/core/backend.h"
5 #include "smaug/operators/softmax_op.h"
32 dmaLoad(inputs, inputs,
33 input_num * (input_size + input_pad) *
sizeof(
float));
34 ARRAY_2D(
float, _inputs, inputs, input_size + input_pad);
35 ARRAY_2D(
float, _results, results, input_size + input_pad);
39 int max8_remainder = input_size - ((input_size >> 3) << 3);
42 for (
int i = 0; i < input_num; i++) {
44 float max_elem = -FLT_MAX;
46 for (
int j = 0; j < input_size - max8_remainder; j += 8) {
47 max_elem = max9(max_elem,
59 for (
int j = input_size - max8_remainder - 1; j < input_size; j++) {
60 max_elem = max2(max_elem, _inputs[i][j]);
65 for (
int j = 0; j < input_size; j++) {
66 _results[i][j] = _inputs[i][j] - max_elem;
71 for (
int j =0; j < input_size; j++) {
72 _results[i][j] = exp(_results[i][j]);
79 for (
int j = 0; j < input_size; j++) {
80 normaliz += _results[i][j];
84 normaliz = 1.0 / (normaliz + 1e-6);
87 for (
int j = 0; j < input_size; j++) {
88 _results[i][j] *= normaliz;
91 dmaLoad(results, results,
92 input_num * (input_size + input_pad) *
sizeof(
float));
102 void SoftmaxOp<ReferenceBackend>::run() {
103 auto inputs = getInput(Inputs);
104 auto outputs = getOutput(Outputs);
105 const TensorShape& inputShape = inputs->getShape();
106 assert(inputShape == outputs->getShape());
107 float* inputData = inputs->data<
float>();
108 float* outputData = outputs->data<
float>();
110 inputs->getShape().storageSize() *
sizeof(
float));
112 inputs->getShape().storageSize() *
sizeof(
float));
114 inputShape[0], inputShape[1], inputShape.getPadding(1));