[cpp] elena cpu
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
- #include <iostream>
- #include <cstdio>
- #include <cstdlib>
- #include <cstring>
- #define EQUAL(a,b) (strcmp((a),(b))==0)
- #define ABORT(Msg) \
- { \
- std::cerr << ": \033[1;91m" \
- << "[Fatal]" \
- << "\033[m " << __FILE__ << ": " << __FUNCTION__ << ": Line" \
- << __LINE__ << ": " << Msg << std::endl; \
- std::abort(); \
- }
- #include "elena_int.h"
- #include "elena_registry.h"#define INCREASE(x, l) ((x + 1) >= (l) ? (x) : ((x) + 1))
- void bilinear_resize_preprocess(uint64_t src_h, uint64_t src_w, uint64_t dst_h, uint64_t dst_w,
- int16_t* __restrict__ cubfh, int16_t* __restrict__ cubfw,
- int32_t* __restrict__ inth, int32_t* __restrict__ intw) {
- float scale_h = double(src_h) / dst_h;
- float scale_w = double(src_w) / dst_w;
- for (int j = 0; j < dst_h; ++j) {
- float fh = (float)((j + 0.5) * scale_h - 0.5f);
- int sh = floor(fh);
- fh -= sh;
- if (sh < 0) {
- fh = 0;
- sh = 0;
- }
- if (sh >= src_h) {
- fh = 0;
- sh = src_h - 1;
- }
- int int_h1 = INCREASE(sh, src_h);
- fh = fh * 2048;
- cubfh[j] = rint(2048 - fh);
- cubfh[dst_h + j] = rint(fh);
- inth[j] = sh;
- inth[dst_h + j] = int_h1;
- }
- for (int i = 0; i < dst_w; ++i) {
- float fw = (float)((i + 0.5) * scale_w - 0.5f);
- int sw = floor(fw);
- fw -= sw;
- if (sw < 0) {
- fw = 0;
- sw = 0;
- }
- if (sw >= src_w) {
- fw = 0;
- sw = src_w - 1;
- }
- int int_w1 = INCREASE(sw, src_w);
- fw = fw * 2048;
- cubfw[i] = rint(2048 - rint(fw));
- cubfw[dst_w + i] = rint(fw);
- intw[i] = sw;
- intw[dst_w + i] = int_w1;
- }
- }
- void FuseKernel(uint64_t resize_h, uint64_t resize_w, uint64_t crop_h, uint64_t crop_w, int32_t crop_top, int32_t crop_left, float norm_mean_0, float norm_mean_1, float norm_mean_2, float norm_std_0, float norm_std_1, float norm_std_2, uint64_t pad_h, uint64_t pad_w, int32_t pad_top, int32_t pad_left, int32_t pad_bottom, int32_t pad_right, float pad_value, uint8_t* __restrict__ src_raw_data, float* __restrict__ dst_raw_data, uint64_t src_h, uint64_t src_w, const char *format, const char *interpolation = "nearest"){
- if (resize_h && resize_w && EQUAL(interpolation, "nearest")) {
- if(EQUAL(format, "BGR")){
- BGR_Nearest_Kernel(resize_h, resize_w, crop_h, crop_w, crop_top, crop_left, norm_mean_0, norm_mean_1, norm_mean_2, norm_std_0, norm_std_1, norm_std_2, pad_h, pad_w, pad_top, pad_left, pad_bottom, pad_right, pad_value, src_raw_data, dst_raw_data, src_h, src_w);
- } else if(EQUAL(format, "RGB")){
- RGB_Nearest_Kernel(resize_h, resize_w, crop_h, crop_w, crop_top, crop_left, norm_mean_0, norm_mean_1, norm_mean_2, norm_std_0, norm_std_1, norm_std_2, pad_h, pad_w, pad_top, pad_left, pad_bottom, pad_right, pad_value, src_raw_data, dst_raw_data, src_h, src_w);
- } else if(EQUAL(format, "GRAY")){
- GRAY_Nearest_Kernel(resize_h, resize_w, crop_h, crop_w, crop_top, crop_left, norm_mean_0, norm_mean_1, norm_mean_2, norm_std_0, norm_std_1, norm_std_2, pad_h, pad_w, pad_top, pad_left, pad_bottom, pad_right, pad_value, src_raw_data, dst_raw_data, src_h, src_w);
- } else if(EQUAL(format, "BGRA")){
- BGRA_Nearest_Kernel(resize_h, resize_w, crop_h, crop_w, crop_top, crop_left, norm_mean_0, norm_mean_1, norm_mean_2, norm_std_0, norm_std_1, norm_std_2, pad_h, pad_w, pad_top, pad_left, pad_bottom, pad_right, pad_value, src_raw_data, dst_raw_data, src_h, src_w);
- } else if(EQUAL(format, "NV12")){
- NV12_Nearest_Kernel(resize_h, resize_w, crop_h, crop_w, crop_top, crop_left, norm_mean_0, norm_mean_1, norm_mean_2, norm_std_0, norm_std_1, norm_std_2, pad_h, pad_w, pad_top, pad_left, pad_bottom, pad_right, pad_value, src_raw_data, dst_raw_data, src_h, src_w);
- } else if(EQUAL(format, "NV21")){
- NV21_Nearest_Kernel(resize_h, resize_w, crop_h, crop_w, crop_top, crop_left, norm_mean_0, norm_mean_1, norm_mean_2, norm_std_0, norm_std_1, norm_std_2, pad_h, pad_w, pad_top, pad_left, pad_bottom, pad_right, pad_value, src_raw_data, dst_raw_data, src_h, src_w);
- } else {
- ABORT("This format is not supported");
- }
- }
- else if(resize_h && resize_w && EQUAL(interpolation, "bilinear")){
- short* cubfh;
- short* cubfw;
- int* inth;
- int* intw;
- cubfh = new short[resize_h*2];
- cubfw = new short[resize_w*2];
- inth = new int[resize_h*2];
- intw = new int[resize_w*2];
- bilinear_resize_preprocess(src_h, src_w, resize_h, resize_w, cubfh, cubfw, inth, intw);
- if(EQUAL(format, "BGR")){
- BGR_Bilinear_Kernel(resize_h, resize_w, crop_h, crop_w, crop_top, crop_left, norm_mean_0, norm_mean_1, norm_mean_2, norm_std_0, norm_std_1, norm_std_2, pad_h, pad_w, pad_top, pad_left, pad_bottom, pad_right, pad_value, cubfh, cubfw, inth, intw, src_raw_data, dst_raw_data, src_h, src_w);
- } else if(EQUAL(format, "RGB")){
- RGB_Bilinear_Kernel(resize_h, resize_w, crop_h, crop_w, crop_top, crop_left, norm_mean_0, norm_mean_1, norm_mean_2, norm_std_0, norm_std_1, norm_std_2, pad_h, pad_w, pad_top, pad_left, pad_bottom, pad_right, pad_value, cubfh, cubfw, inth, intw, src_raw_data, dst_raw_data, src_h, src_w);
- } else if(EQUAL(format, "GRAY")){
- GRAY_Bilinear_Kernel(resize_h, resize_w, crop_h, crop_w, crop_top, crop_left, norm_mean_0, norm_mean_1, norm_mean_2, norm_std_0, norm_std_1, norm_std_2, pad_h, pad_w, pad_top, pad_left, pad_bottom, pad_right, pad_value, cubfh, cubfw, inth, intw, src_raw_data, dst_raw_data, src_h, src_w);
- } else if(EQUAL(format, "BGRA")){
- BGRA_Bilinear_Kernel(resize_h, resize_w, crop_h, crop_w, crop_top, crop_left, norm_mean_0, norm_mean_1, norm_mean_2, norm_std_0, norm_std_1, norm_std_2, pad_h, pad_w, pad_top, pad_left, pad_bottom, pad_right, pad_value, cubfh, cubfw, inth, intw, src_raw_data, dst_raw_data, src_h, src_w);
- } else if(EQUAL(format, "NV12")){
- NV12_Bilinear_Kernel(resize_h, resize_w, crop_h, crop_w, crop_top, crop_left, norm_mean_0, norm_mean_1, norm_mean_2, norm_std_0, norm_std_1, norm_std_2, pad_h, pad_w, pad_top, pad_left, pad_bottom, pad_right, pad_value, cubfh, cubfw, inth, intw, src_raw_data, dst_raw_data, src_h, src_w);
- } else if(EQUAL(format, "NV21")){
- NV21_Bilinear_Kernel(resize_h, resize_w, crop_h, crop_w, crop_top, crop_left, norm_mean_0, norm_mean_1, norm_mean_2, norm_std_0, norm_std_1, norm_std_2, pad_h, pad_w, pad_top, pad_left, pad_bottom, pad_right, pad_value, cubfh, cubfw, inth, intw, src_raw_data, dst_raw_data, src_h, src_w);
- } else {
- ABORT("This format is not supported");
- }
- delete[] cubfh;
- delete[] cubfw;
- delete[] inth;
- delete[] intw;
- }
- else {
- ABORT("This interpolation is not supported");
- }
- }
- using std::string;
- void FuseFunc(void* stream, uint8_t* data_in, int src_h, int src_w, const char* format,
- int resize_h, int resize_w, const char* interpolation, int crop_top, int crop_left,
- int crop_h, int crop_w, float mean0, float mean1, float mean2, float std0, float std1,
- float std2, int pad_top, int pad_left, int pad_bottom, int pad_right, int pad_h,
- int pad_w, float pad_value, float* data_out, int data_out_num) {
- const char* interpolation_ = "nearest";
- if (strcmp(interpolation, "bilinear") == 0) {
- interpolation_ = "bilinear";
- }
- FuseKernel(resize_h, resize_w, crop_h, crop_w, crop_top, crop_left, mean0, mean1, mean2, std0, std1, std2,
- pad_h, pad_w, pad_top, pad_left, pad_bottom, pad_right, pad_value, data_in, data_out,
- src_h, src_w, format, interpolation_);
- }
- REGISTER_FUSE_KERNEL(fa993066c1ec32a14d8d06ecfb8d5c54e7a04ec31ba833e1abf1f16c05e027c7_cpu, "fa993066c1ec32a14d8d06ecfb8d5c54e7a04ec31ba833e1abf1f16c05e027c7_cpu",
- FuseFunc);
- }
Editor
You can edit this paste and save as new: