Skip to content

Commit

Permalink
bot: fetch update components
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Dec 5, 2024
1 parent a249057 commit 6d0cf9d
Show file tree
Hide file tree
Showing 30 changed files with 771 additions and 191 deletions.
6 changes: 3 additions & 3 deletions src/components/sscma-micro/sscma/core/engine/ma_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ using EngineDefault = ma::engine::EngineTFLite;
using EngineDefault = ma::engine::EngineCVI;
#endif

#ifdef MA_USE_ENGINE_HALIO
#include "ma_engine_halio.h"
using EngineDefault = ma::engine::EngineHalio;
#ifdef MA_USE_ENGINE_HAILO
#include "ma_engine_hailo.h"
using EngineDefault = ma::engine::EngineHailo;
#endif

#endif // _MA_ENGINE_H_
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "ma_engine_halio.h"
#include "ma_engine_hailo.h"

#if MA_USE_ENGINE_HALIO
#if MA_USE_ENGINE_HAILO

#include <atomic>
#include <chrono>
#include <cstdint>
#include <cstring>
Expand All @@ -11,33 +12,57 @@ namespace ma::engine {

using namespace std;

EngineHalio::EngineHalio() : _vdevice(nullptr), _model(nullptr), _configured_model(nullptr), _bindings(nullptr) {}
EngineHailo::EngineHailo() : _vdevice(nullptr), _model(nullptr), _configured_model(nullptr), _bindings(nullptr) {}

EngineHalio::~EngineHalio() {}
EngineHailo::~EngineHailo() {}

ma_err_t EngineHalio::init() {
ma_err_t EngineHailo::init() {
if (_vdevice) {
return MA_OK;
}

auto vdevice = VDevice::create();
if (!vdevice) {
// TODO: optimize
static auto get_vdevice_f = []() -> shared_ptr<VDevice> {
static unique_ptr<VDevice> vdevice = nullptr;
if (!vdevice) {
auto dev = VDevice::create();
if (!dev) {
return nullptr;
}
vdevice = move(dev.release());
}
if (!vdevice) {
return nullptr;
}
auto shared = vdevice.get();
auto mgr = &vdevice;
static atomic<size_t> ref_count = 0;
ref_count.fetch_add(1);
return shared_ptr<VDevice>(shared, [mgr](VDevice*) {
if (mgr) {
if (ref_count.fetch_sub(1) == 1) {
mgr->reset();
}
}
});
};
_vdevice = get_vdevice_f();
if (!_vdevice) {
return MA_FAILED;
}
_vdevice = move(vdevice.value());

return MA_OK;
}

ma_err_t EngineHalio::init(size_t size) {
ma_err_t EngineHailo::init(size_t size) {
return init();
}

ma_err_t EngineHalio::init(void* pool, size_t size) {
ma_err_t EngineHailo::init(void* pool, size_t size) {
return init();
}

ma_err_t EngineHalio::run() {
ma_err_t EngineHailo::run() {
if (!_configured_model || !_bindings) {
return MA_FAILED;
}
Expand Down Expand Up @@ -65,7 +90,7 @@ ma_err_t EngineHalio::run() {
}

#if MA_USE_FILESYSTEM
ma_err_t EngineHalio::load(const string& model_path) {
ma_err_t EngineHailo::load(const string& model_path) {

{
_input_tensors.clear();
Expand Down Expand Up @@ -324,12 +349,12 @@ ma_err_t EngineHalio::load(const string& model_path) {
return MA_OK;
}

ma_err_t EngineHalio::load(const char* model_path) {
ma_err_t EngineHailo::load(const char* model_path) {
return load(string(model_path));
}
#endif

ma_err_t EngineHalio::load(const void* model_data, size_t model_size) {
ma_err_t EngineHailo::load(const void* model_data, size_t model_size) {
#if MA_USE_FILESYSTEM
string model_path(reinterpret_cast<const char*>(model_data), model_size);
return load(model_path);
Expand All @@ -338,55 +363,55 @@ ma_err_t EngineHalio::load(const void* model_data, size_t model_size) {
#endif
}

int32_t EngineHalio::getInputSize() {
int32_t EngineHailo::getInputSize() {
return _input_tensors.size();
}

int32_t EngineHalio::getOutputSize() {
int32_t EngineHailo::getOutputSize() {
return _output_tensors.size();
}

ma_tensor_t EngineHalio::getInput(int32_t index) {
ma_tensor_t EngineHailo::getInput(int32_t index) {
if (index < 0 || index >= static_cast<int32_t>(_input_tensors.size())) {
return {0};
}

return _input_tensors[index] ? *_input_tensors[index] : ma_tensor_t{0};
}

ma_tensor_t EngineHalio::getOutput(int32_t index) {
ma_tensor_t EngineHailo::getOutput(int32_t index) {
if (index < 0 || index >= static_cast<int32_t>(_output_tensors.size())) {
return {0};
}

return _output_tensors[index] ? *_output_tensors[index] : ma_tensor_t{0};
}

ma_shape_t EngineHalio::getInputShape(int32_t index) {
ma_shape_t EngineHailo::getInputShape(int32_t index) {
if (index < 0 || index >= static_cast<int32_t>(_input_tensors.size())) {
return {0};
}

return _input_tensors[index] ? _input_tensors[index]->shape : ma_shape_t{0};
}

ma_shape_t EngineHalio::getOutputShape(int32_t index) {
ma_shape_t EngineHailo::getOutputShape(int32_t index) {
if (index < 0 || index >= static_cast<int32_t>(_output_tensors.size())) {
return {0};
}

return _output_tensors[index] ? _output_tensors[index]->shape : ma_shape_t{0};
}

ma_quant_param_t EngineHalio::getInputQuantParam(int32_t index) {
ma_quant_param_t EngineHailo::getInputQuantParam(int32_t index) {
if (index < 0 || index >= static_cast<int32_t>(_input_tensors.size())) {
return {0};
}

return _input_tensors[index] ? _input_tensors[index]->quant_param : ma_quant_param_t{0};
}

ma_quant_param_t EngineHalio::getOutputQuantParam(int32_t index) {
ma_quant_param_t EngineHailo::getOutputQuantParam(int32_t index) {
if (index < 0 || index >= static_cast<int32_t>(_output_tensors.size())) {
return {0};
}
Expand All @@ -395,7 +420,17 @@ ma_quant_param_t EngineHalio::getOutputQuantParam(int32_t index) {
}


ma_err_t EngineHalio::setInput(int32_t index, const ma_tensor_t& tensor) {
ma_err_t EngineHailo::setInput(int32_t index, const ma_tensor_t& tensor) {
if (index < 0 || index >= static_cast<int32_t>(_input_tensors.size())) {
return MA_EINVAL;
}

if (tensor.size != _input_tensors[index]->size) {
return MA_EINVAL;
}

std::memcpy(_input_tensors[index]->data.data, tensor.data.data, tensor.size);

return MA_ENOTSUP;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#ifndef _MA_ENGINE_HALIO_H_
#define _MA_ENGINE_HALIO_H_
#ifndef _MA_ENGINE_HAILO_H_
#define _MA_ENGINE_HAILO_H_

#include "../ma_common.h"

#if MA_USE_ENGINE_HALIO
#if MA_USE_ENGINE_HAILO

#include "ma_engine.h"
#include "ma_engine_base.h"

#include <cstddef>
#include <cstdint>
Expand All @@ -21,12 +21,12 @@ namespace ma::engine {
using namespace std;
using namespace hailort;

class EngineHalio final : public Engine {
class EngineHailo final : public Engine {
public:
using ExternalHandler = function<ma_err_t(int, void*, size_t)>;

EngineHalio();
~EngineHalio() override;
EngineHailo();
~EngineHailo() override;

ma_err_t init() override;
ma_err_t init(size_t size) override;
Expand All @@ -52,7 +52,7 @@ class EngineHalio final : public Engine {
ma_err_t setInput(int32_t index, const ma_tensor_t& tensor) override;

private:
unique_ptr<VDevice> _vdevice;
shared_ptr<VDevice> _vdevice;
shared_ptr<InferModel> _model;
shared_ptr<ConfiguredInferModel> _configured_model;
shared_ptr<ConfiguredInferModel::Bindings> _bindings;
Expand Down
2 changes: 1 addition & 1 deletion src/components/sscma-micro/sscma/core/ma_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "ma_exception.h"
#include "ma_types.h"

#define MA_VERSION "2024.11.13"
#define MA_VERSION "2024.11.25"
#define MA_VERSION_LENTH_MAX 32

#endif // MA_COMMON_H
2 changes: 1 addition & 1 deletion src/components/sscma-micro/sscma/core/ma_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ typedef enum {
MA_OUTPUT_TYPE_POINT = 0x0200,
MA_OUTPUT_TYPE_BBOX = 0x0300,
MA_OUTPUT_TYPE_KEYPOINT = 0x0400,
MA_OUTPUT_TYPE_SEGMENTATION = 0x0500,
MA_OUTPUT_TYPE_SEGMENT = 0x0500,
} ma_output_type_t;


Expand Down
1 change: 1 addition & 0 deletions src/components/sscma-micro/sscma/core/math/ma_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@

#include "ma_math_scalars.h"
#include "ma_math_vectors.h"
#include "ma_math_matrix.h"

#endif // _MA_MATH_H
22 changes: 22 additions & 0 deletions src/components/sscma-micro/sscma/core/math/ma_math_matrix.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "ma_math_matrix.h"
#include "ma_math_vectors.h"

#include <cmath>

namespace ma::math {

void softmax2D(float* data, size_t rows, size_t cols) {
size_t size = rows * cols;
for (size_t i = 0; i < size; i += cols) {
softmax(&data[i], cols);
}
}

void fastSoftmax2D(float* data, size_t rows, size_t cols) {
size_t size = rows * cols;
for (size_t i = 0; i < size; i += cols) {
fastSoftmax(&data[i], cols);
}
}

}
32 changes: 32 additions & 0 deletions src/components/sscma-micro/sscma/core/math/ma_math_matrix.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#ifndef _MA_MATH_MARTRIX_H_
#define _MA_MATH_MARTRIX_H_

#include <cstddef>
#include <cstdint>

#if MA_USE_LIB_XTENSOR
#include <xtensor/xarray.hpp>
#include <xtensor/xmath.hpp>
#include <xtensor/xview.hpp>
#endif

namespace ma::math {

void softmax2D(float* data, size_t rows, size_t cols);

void fastSoftmax2D(float* data, size_t rows, size_t cols);

#if MA_USE_LIB_XTENSOR
template <typename QT>
static void dequantizeValues2D(xt::xarray<float>& dequantized_outputs, int index, const xt::xarray<QT>& quantized_outputs, size_t dim1, size_t dim2, float32_t qp_scale, float32_t qp_zp) {
for (size_t i = 0; i < dim1; i++) {
for (size_t j = 0; j < dim2; j++) {
dequantized_outputs(i, j) = (float(quantized_outputs(index, i, j)) - qp_zp) * qp_scale;
}
}
}
#endif

} // namespace ma::math

#endif
15 changes: 10 additions & 5 deletions src/components/sscma-micro/sscma/core/math/ma_math_scalars.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ constexpr inline float fastLn(float x) {
return -std::numeric_limits<float>::infinity();
}

auto bx{*reinterpret_cast<unsigned int*>(&x)};
auto ex{bx >> 23};
auto bx{*reinterpret_cast<unsigned int*>(&x)};
auto ex{bx >> 23};
const auto t{static_cast<signed int>(ex) - static_cast<signed int>(127)};

bx = 1065353216 | (bx & 8388607);
Expand All @@ -41,17 +41,22 @@ constexpr inline float fastExp(float x) {
const float c{8388608.f};
const float d{2139095040.f};

if ((x < c) | (x > d)) x = (x < c) ? 0.0f : d;
if ((x < c) | (x > d))
x = (x < c) ? 0.0f : d;

uint32_t n = static_cast<uint32_t>(x);
x = *reinterpret_cast<float*>(&n);

return x;
}

constexpr inline float sigmoid(float x) { return 1.0f / (1.0f + std::exp(-x)); }
constexpr inline float sigmoid(float x) {
return 1.0f / (1.0f + std::exp(-x));
}

constexpr inline float fastSigmoid(float x) { return 1.0f / (1.0f + fastExp(-x)); }
constexpr inline float fastSigmoid(float x) {
return 1.0f / (1.0f + fastExp(-x));
}

constexpr inline float inverseSigmoid(float x) {
float denominator = 1.0f - x;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ const void* Classifier::getInput() {
}

ma_err_t Classifier::run(const ma_img_t* img) {
// MA_ASSERT(img != nullptr);

input_img_ = img;

return underlyingRun();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ const void* Detector::getInput() {
}

ma_err_t Detector::run(const ma_img_t* img) {
// MA_ASSERT(img != nullptr);

input_img_ = img;

return underlyingRun();
}

Expand Down
Loading

0 comments on commit 6d0cf9d

Please sign in to comment.