Skip to content

Commit

Permalink
🐛 @341ccfc0
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanjiong committed Dec 16, 2021
1 parent 029b7b0 commit 925c72e
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 50 deletions.
2 changes: 0 additions & 2 deletions include/dl_define.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#pragma once

#include "dl_define_private.hpp"

#include <climits>
#include "sdkconfig.h"

Expand Down
5 changes: 2 additions & 3 deletions include/layer/dl_layer_expand_dims.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,18 @@ namespace dl
this->output_exponent = input.exponent;
if (!this->inplace)
{
if (this->output != NULL)
if (this->output == NULL)
{
this->output = new Tensor<feature_t>;
}
this->output->set_exponent(this->output_exponent);
this->output->set_shape(this->output_shape);
this->output->set_shape(input.shape);
this->output->expand_dims(this->axis);
this->output->free_element();
}
else
{
this->output = &input;
this->output->set_shape(this->output_shape);
this->output->expand_dims(this->axis);
}
this->output_shape = this->output->shape;
Expand Down
2 changes: 1 addition & 1 deletion include/layer/dl_layer_flatten.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace dl
this->output_shape = {input.get_size()};
if (!this->inplace)
{
if (this->output != NULL)
if (this->output == NULL)
{
this->output = new Tensor<feature_t>;
}
Expand Down
22 changes: 11 additions & 11 deletions include/layer/dl_layer_leakyrelu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ namespace dl
namespace layer
{
/**
* @brief LeakyReLU(input).
* @brief LeakyRelu(input).
*
* @tparam feature_t supports int16_t and int8_t,
* - int16_t: stands for operation in int16_t quantize
* - int8_t: stands for operation in int8_t quantize
*/
template <typename feature_t>
class LeakyReLU : public Layer
class LeakyRelu : public Layer
{
private:
feature_t activation_alpha; /*<! quantized alpha >*/
Expand All @@ -28,26 +28,26 @@ namespace dl
std::vector<int> output_shape; /*<! output shape of leakyrelu >*/
public:
/**
* @brief Construct a new LeakyReLU object
* @brief Construct a new LeakyRelu object
*
* @param activation_alpha quantized alpha
* @param activation_exponent exponent of quantized alpha
* @param name name of leakyrelu
* @param inplace true: the output will store to input0
* false: the output will store to a separate memory
*/
LeakyReLU(const int activation_alpha, const int activation_exponent, const char *name = "LeakyReLU", bool inplace = false) : Layer(name), output(NULL), output_shape({})
LeakyRelu(const int activation_alpha, const int activation_exponent, const char *name = "LeakyRelu", bool inplace = false) : Layer(name), output(NULL), output_shape({})
{
this->activation_alpha = activation_alpha;
this->activation_exponent = activation_exponent;
this->inplace = inplace;
}

/**
* @brief Destroy the LeakyReLU object
* @brief Destroy the LeakyRelu object
*
*/
~LeakyReLU()
~LeakyRelu()
{
if ((!this->inplace) && (this->output != NULL))
{
Expand All @@ -66,7 +66,7 @@ namespace dl
this->output_shape = input.shape;
if (!this->inplace)
{
if (this->output != NULL)
if (this->output == NULL)
{
this->output = new Tensor<feature_t>;
}
Expand All @@ -90,19 +90,19 @@ namespace dl
/**
* @brief Get the output
*
* @return Tensor<feature_t>& LeakyReLU result
* @return Tensor<feature_t>& LeakyRelu result
*/
Tensor<feature_t> &get_output()
{
return *this->output;
}

/**
* @brief Call LeakyReLU operation.
* @brief Call LeakyRelu operation.
*
* @param input as an input
* @param assign_core not effective yet
* @return LeakyReLU result
* @return LeakyRelu result
*/
Tensor<feature_t> &call(Tensor<feature_t> &input, const std::vector<int> &assign_core = CONFIG_DEFAULT_ASSIGN_CORE)
{
Expand Down Expand Up @@ -130,7 +130,7 @@ namespace dl
{
this->output->set_shape(this->output_shape);
}
nn::leakyrelu<true>(*this->output, input, this->activation_alpha, this->activation_exponent, assign_core);
nn::leakyrelu(*this->output, input, this->activation_alpha, this->activation_exponent, assign_core);
DL_LOG_LAYER_LATENCY_END(this->name, "leakyrelu");
}

Expand Down
4 changes: 2 additions & 2 deletions include/layer/dl_layer_max2d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ namespace dl

if (!this->inplace)
{
if (this->output != NULL)
if (this->output == NULL)
{
this->output = new Tensor<feature_t>;
}
Expand Down Expand Up @@ -132,7 +132,7 @@ namespace dl
{
this->output->set_shape(this->output_shape);
}
nn::max2d<true>(*this->output, input0, input1, assign_core);
nn::max2d(*this->output, input0, input1, assign_core);
DL_LOG_LAYER_LATENCY_END(this->name, "max2d");
}

Expand Down
4 changes: 2 additions & 2 deletions include/layer/dl_layer_min2d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ namespace dl

if (!this->inplace)
{
if (this->output != NULL)
if (this->output == NULL)
{
this->output = new Tensor<feature_t>;
}
Expand Down Expand Up @@ -132,7 +132,7 @@ namespace dl
{
this->output->set_shape(this->output_shape);
}
nn::min2d<true>(*this->output, input0, input1, assign_core);
nn::min2d(*this->output, input0, input1, assign_core);
DL_LOG_LAYER_LATENCY_END(this->name, "min2d");
}

Expand Down
4 changes: 2 additions & 2 deletions include/layer/dl_layer_mul2d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ namespace dl

if (!this->inplace)
{
if (this->output != NULL)
if (this->output == NULL)
{
this->output = new Tensor<feature_t>;
}
Expand Down Expand Up @@ -140,7 +140,7 @@ namespace dl
{
this->output->set_shape(this->output_shape);
}
nn::mul2d<true>(*this->output, input0, input1, this->activation, assign_core);
nn::mul2d(*this->output, input0, input1, this->activation, assign_core);
DL_LOG_LAYER_LATENCY_END(this->name, "mul2d");
}

Expand Down
30 changes: 15 additions & 15 deletions include/layer/dl_layer_prelu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,36 @@ namespace dl
namespace layer
{
/**
* @brief PReLU(input).
* @brief PRelu(input).
*
* @tparam feature_t supports int16_t and int8_t,
* - int16_t: stands for operation in int16_t quantize
* - int8_t: stands for operation in int8_t quantize
*/
template <typename feature_t>
class PReLU : public Layer
class PRelu : public Layer
{
private:
feature_t *activation_element; /*<! quantized alpha elements along channel axis >*/
const feature_t *activation_element; /*<! quantized alpha elements along channel axis >*/
int activation_exponent; /*<! exponent of quantized alpha elements >*/
Tensor<feature_t> *output; /*<! output ptr of prelu >*/
bool inplace; /*<! true: the output will store to input0
false: the output will store to a separate memory >*/
std::vector<int> output_shape; /*<! output shape of prelu >*/
public:
/**
* @brief Construct a new PReLU object
* @brief Construct a new PRelu object
*
* @param activation_element quantized alpha elements along channel axis
* @param activation_exponent exponent of quantized alpha elements
* @param name name of prelu
* @param inplace true: the output will store to input0
* false: the output will store to a separate memory
*/
PReLU(const feature_t *activation_element,
PRelu(const feature_t *activation_element,
const int activation_exponent = 0,
const char *name = NULL,
bool inplace = "PReLU") : Layer(name),
const char *name = "PRelu",
bool inplace = false) : Layer(name),
activation_element(activation_element),
activation_exponent(activation_exponent),
output(NULL),
Expand All @@ -49,10 +49,10 @@ namespace dl
}

/**
* @brief Destroy the PReLU object
* @brief Destroy the PRelu object
*
*/
~PReLU()
~PRelu()
{
if ((!this->inplace) && (this->output != NULL))
{
Expand All @@ -71,7 +71,7 @@ namespace dl
this->output_shape = input.shape;
if (!this->inplace)
{
if (this->output != NULL)
if (this->output == NULL)
{
this->output = new Tensor<feature_t>;
}
Expand All @@ -94,19 +94,19 @@ namespace dl
/**
* @brief Get the output
*
* @return Tensor<feature_t>& PReLU result
* @return Tensor<feature_t>& PRelu result
*/
Tensor<feature_t> &get_output()
{
return *this->output;
}

/**
* @brief Call PReLU operation.
* @brief Call PRelu operation.
*
* @param input as an input
* @param assign_core not effective yet
* @return PReLU result
* @return PRelu result
*/
Tensor<feature_t> &call(Tensor<feature_t> &input, const std::vector<int> &assign_core = CONFIG_DEFAULT_ASSIGN_CORE)
{
Expand All @@ -125,7 +125,7 @@ namespace dl

DL_LOG_LAYER_LATENCY_START();
nn::prelu(*this->output, input, this->activation_element, this->activation_exponent, assign_core);
DL_LOG_LAYER_LATENCY_END(this->name, "leakyrelu");
DL_LOG_LAYER_LATENCY_END(this->name, "prelu");
}
else
{
Expand All @@ -135,7 +135,7 @@ namespace dl
this->output->set_shape(this->output_shape);
}
nn::prelu(*this->output, input, this->activation_element, this->activation_exponent, assign_core);
DL_LOG_LAYER_LATENCY_END(this->name, "leakyrelu");
DL_LOG_LAYER_LATENCY_END(this->name, "prelu");
}

return *this->output;
Expand Down
2 changes: 1 addition & 1 deletion include/layer/dl_layer_relu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace dl
this->output_shape = input.shape;
if (!this->inplace)
{
if (this->output != NULL)
if (this->output == NULL)
{
this->output = new Tensor<feature_t>;
}
Expand Down
8 changes: 5 additions & 3 deletions include/layer/dl_layer_reshape.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,21 @@ namespace dl
this->output_exponent = input.exponent;
if (!this->inplace)
{
if (this->output != NULL)
if (this->output == NULL)
{
this->output = new Tensor<feature_t>;
}
this->output->set_exponent(this->output_exponent);
this->output->set_shape(this->output_shape);
this->output->set_shape(input.shape);
this->output->reshape(this->output_shape);
this->output->free_element();
}
else
{
this->output = &input;
this->output->set_shape(this->output_shape);
this->output->reshape(this->output_shape);
}
this->output_shape = this->output->shape;

if (print_shape)
{
Expand Down
3 changes: 1 addition & 2 deletions include/layer/dl_layer_squeeze.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace dl
this->output_exponent = input.exponent;
if (!this->inplace)
{
if (this->output != NULL)
if (this->output == NULL)
{
this->output = new Tensor<feature_t>;
}
Expand All @@ -78,7 +78,6 @@ namespace dl
else
{
this->output = &input;
this->output->set_shape(input.shape);
this->output->squeeze(this->axis);
}
this->output_shape = this->output->shape;
Expand Down
8 changes: 4 additions & 4 deletions include/layer/dl_layer_sub2d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ namespace dl
this->output_shape = input0.shape;
if (!this->inplace)
{
if (this->output != NULL)
if (this->output == NULL)
{
this->output = new Tensor<feature_t>;
}
Expand Down Expand Up @@ -120,12 +120,12 @@ namespace dl
{
this->output->set_shape(this->output_shape);
}
this->output.malloc_element();
this->output->malloc_element();
this->output->set_exponent(input0.exponent);
DL_LOG_LAYER_LATENCY_END(this->name, "apply");

DL_LOG_LAYER_LATENCY_START();
nn::sub2d(this->output, input0, input1, this->activation, assign_core);
nn::sub2d(*this->output, input0, input1, this->activation, assign_core);
DL_LOG_LAYER_LATENCY_END(this->name, "sub2d");
}
else
Expand All @@ -135,7 +135,7 @@ namespace dl
{
this->output->set_shape(this->output_shape);
}
nn::sub2d<true>(this->output, input0, input1, this->activation, assign_core, this->output_exponent);
nn::sub2d(*this->output, input0, input1, this->activation, assign_core, this->output_exponent);
DL_LOG_LAYER_LATENCY_END(this->name, "sub2d");
}
return *this->output;
Expand Down
15 changes: 13 additions & 2 deletions include/layer/dl_layer_transpose.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,24 @@ namespace dl
{
this->output_exponent = input.exponent;
this->output_shape = input.shape;
for (int i = 0; i < this->perm.size(); i++)
int dims = this->output_shape.size();
if (this->perm.size() == 0)
{
for (int i = dims - 1; i >= 0; i--)
{
this->perm.push_back(i);
}
}
for (int i = 0; i < dims; ++i)
{
if (this->perm[i] < 0)
this->perm[i] = dims + this->perm[i];
this->output_shape[i] = input.shape[this->perm[i]];
}

if (!this->inplace)
{
if (this->output != NULL)
if (this->output == NULL)
{
this->output = new Tensor<feature_t>;
}
Expand Down
Binary file modified lib/esp32s3/libdl.a
Binary file not shown.

0 comments on commit 925c72e

Please sign in to comment.