blace.ai
Loading...
Searching...
No Matches
types.h
Go to the documentation of this file.
1#pragma once
2
3#include "library_defines.h"
4#include <cstdint>
5#include <iosfwd> // for ostream
6#include <optional>
7#include <string>
8#include <vector>
9
15namespace blace {
16namespace ml_core {
17
21typedef std::vector<int64_t> TensorSizes;
22
26constexpr int BYTE_MAX = 255;
30constexpr float SHORT_MAX = 32768.;
34constexpr float BYTE_MAX_FLOAT = 255.;
35
41enum DeviceEnum : int { CPU = 0, CUDA = 1, MPS = 2, DML = 3 };
42
46enum ValueRangeEnum : int {
47 ZERO_TO_ONE = 0,
48 MINUS_ONE_TO_ONE = 1,
49 IMAGENET = 2,
50 UNKNOWN_VALUE_RANGE = 3,
51 ZERO_TO_255 = 4,
52 MINUS_0_5_TO_0_5 = 5,
53 ZERO_TO_32768 = 6
54};
55
59enum DataTypeEnum : int {
60 INT_32 = 0,
61 FLOAT_32 = 1,
62 BLACE_BYTE = 2,
63 BLACE_BOOL = 3,
64 FLOAT_32_16 = 4,
65 FLOAT_16 = 5,
66 SHORT = 6,
67 INT_64 = 7,
68 FLOAT_64 = 8
69};
70
74enum OrderEnum : int {
75 BTCHW = 0,
76 BCHW = 1,
77 CHW = 2,
78 HWC = 3,
79 BHWC = 4,
80 HW = 5,
81 W = 6,
82 WC = 7,
83 C = 8,
84 BC = 9,
85 BWCH = 10,
86 BHW = 11,
87 BCH = 12,
88 CH = 13,
89 TBCHW = 14,
90 BCWH = 15,
91 BWHC = 16,
92 NO_DIMS = 17,
93 UNKNOWN_ORDER = 18,
94 BOUNDING_BOX_WITH_DIMS = 19,
95 THWC = 20,
96 TCHW = 21,
97 H = 22,
98 BAUDIO_MONO_44100HZ = 23
99
100};
101
105enum ColorFormatEnum : int {
106 RGB = 0,
107 R = 1,
108 A = 2,
109 ARGB = 3,
110 ARBITRARY_CHANNELS = 4,
111 BGRA = 5,
112 BGR = 6,
113 LAB = 7,
114 AB = 8,
115 L = 9,
116 XYZ = 10,
117 YCBCR = 11,
118 Y = 12,
119 BRG = 13,
120 UV = 14
121};
122
126enum ModelDataType { tFloat = 0, tHalf };
127
131struct LAB_NORMS {
135 double l_norm;
139 double l_cent;
143 double ab_norm;
144
151 bool operator==(const LAB_NORMS &other) const;
152};
153
157enum FORWARD_MODE { SIMPLE = 0, MULTIPASS, SLICED };
158
163 NEAREST = 0,
164 LINEAR,
165 BILINEAR,
166 BICUBIC,
167 TRILINEAR,
168 AREA,
169 PIL_BICUBIC
170};
171
175enum PADDING_MODE { REPLICATION = 0, REFLECTION, CONSTANT };
176
183enum MODEL_OFFLOADING_STRATEGY { NO_OFFLOADING = 0, TO_RAM, FULL_UNLOAD };
184
188enum DIRECTION { LEFT, TOP, RIGHT, BOTTOM };
189
195 TORCHSCRIPT_CUDA_FP32,
196 TORCHSCRIPT_CUDA_FP16,
197 TORCHSCRIPT_MPS_FP32,
198 ONNX_CUDA_FP32,
199 ONNX_CUDA_FP16,
200 ONNX_CPU_FP32,
201 TORCHSCRIPT_MPS_FP16,
202 TORCHSCRIPT_CPU_FP32,
203 ONNX_DML_FP32,
204 ONNX_DML_FP16,
205 TORCHSCRIPT_CPU_FP16,
206 EMPTY_BACKEND,
207};
208
212enum Framework { TORCHSCRIPT, ONNXRUNTIME };
213
217struct EXPORT_OR_IMPORT BlaceHash {
221 uint64_t hash[4];
222
229 bool operator==(const BlaceHash &rhs) const;
230
237 bool operator!=(const BlaceHash &rhs) const;
238
245 bool operator<(const BlaceHash &rhs) const;
246
252 long long to_long_long();
253
260 std::string to_hex(int len = 8);
261
265 friend std::ostream &operator<<(std::ostream &os, const BlaceHash &obj);
266
272
278 BlaceHash(int seed);
279
285 BlaceHash(std::string str);
286
295 BlaceHash(int64_t a, int64_t b, int64_t c, int64_t d);
296
302 std::string print() {
303 std::string returnstring = "";
304 for (int temp = 0; temp < 4; temp++)
305 returnstring += std::to_string(hash[temp]) + "\n";
306 return returnstring;
307 }
308
315 static void mix_string_into_hash(BlaceHash &hash, std::string str);
316
323 static void mix_float_into_hash(BlaceHash &hash, float data);
324
331 static void mix_hash_into_hash(BlaceHash &hash, BlaceHash data);
332};
333
342 std::vector<Backend> backends;
346 int deprecated = true;
350 int seed = 0;
355 int run_threaded = false;
359 int plot_inputs = false;
365 MODEL_OFFLOADING_STRATEGY::FULL_UNLOAD;
371
376
383
390 bool operator==(const ModelInferenceArgs &other) const;
391
398 bool operator!=(const ModelInferenceArgs &other) const {
399 return !(*this == other);
400 }
401};
402
410 int parallel = true;
414 int samples = 1;
418 int allow_mirroring = true;
426 int jitter_keep_size = false;
434 PADDING_MODE padding_mode = PADDING_MODE::REFLECTION;
443
450
457 bool operator==(const MultisampleInferenceArgs &other) const;
458
465 bool operator!=(const MultisampleInferenceArgs &other) const {
466 return !(*this == other);
467 }
468};
469
477 int parallel = true;
481 int slices = 1;
485 int overlap = 32;
494
501
508 bool operator==(const SlicedInferenceArgs &other) const;
509
516 bool operator!=(const SlicedInferenceArgs &other) const {
517 return !(*this == other);
518 }
519};
520
525public:
535 ml_core::FORWARD_MODE mode = FORWARD_MODE::SIMPLE;
539 std::optional<MultisampleInferenceArgs> multi_args = std::nullopt;
543 std::optional<SlicedInferenceArgs> sliced_args = std::nullopt;
544
551
558 bool operator==(const InferenceArgsCollection &other) const;
559
566 bool operator!=(const InferenceArgsCollection &other) const {
567 return !(*this == other);
568 }
569};
570
574class ModelIdent : public std::string {
575public:
576 using std::string::string;
577
583 ModelIdent(const std::string &str) : std::string(str) {
584 // Additional initialization or processing can be done here
585 }
586};
587
591enum class ReturnCode {
592 OK = 0,
593 Error = 1, // Returned on generic errors
594 UserCancelled = 2, // This will be returned if a callback passed to the
595 // evaluator signalled cancelation.
596 UserKilled = 3, // This will be returned if a callback passed to the evaluator
597 // signalled a killing wish.
598 MissingData =
599 4, // Returned if missing data was encountered during computation
600 Error_OOM = 5, // Returned if method run into an OOM situation. Will only
601 // happen if returned from RawMemoryFetcher.
602 ModelFileNotPresent = 6, // Model file was not found
603 Error_Inference_OOM = 7, // Returned if worker ran out of RAM / VRAM during
604 // inference.
605 Error_IPC_Timeout = 8, // Returned if IPC process timed out.
606 Error_NoSupportedBackend =
607 9, // Returned if model does not supported any of the requested backends
608
609};
610
611} // namespace ml_core
612} // namespace blace
ml_core::FORWARD_MODE mode
Definition types.h:535
bool operator!=(const InferenceArgsCollection &other) const
Definition types.h:566
ModelInferenceArgs inference_args
Definition types.h:529
bool operator==(const InferenceArgsCollection &other) const
std::optional< SlicedInferenceArgs > sliced_args
Definition types.h:543
std::optional< MultisampleInferenceArgs > multi_args
Definition types.h:539
Definition types.h:574
ModelIdent(const std::string &str)
Definition types.h:583
Definition types.h:217
BlaceHash(int64_t a, int64_t b, int64_t c, int64_t d)
static void mix_hash_into_hash(BlaceHash &hash, BlaceHash data)
friend std::ostream & operator<<(std::ostream &os, const BlaceHash &obj)
bool operator<(const BlaceHash &rhs) const
static void mix_string_into_hash(BlaceHash &hash, std::string str)
BlaceHash(std::string str)
std::string to_hex(int len=8)
static void mix_float_into_hash(BlaceHash &hash, float data)
bool operator==(const BlaceHash &rhs) const
std::string print()
Definition types.h:302
bool operator!=(const BlaceHash &rhs) const
Definition types.h:131
bool operator==(const LAB_NORMS &other) const
double l_cent
Definition types.h:139
double ab_norm
Definition types.h:143
double l_norm
Definition types.h:135
int run_threaded
Definition types.h:355
bool operator==(const ModelInferenceArgs &other) const
int seed
Definition types.h:350
int experimental_torchscript_autocast
Definition types.h:375
int empty_cache_after_inference
Definition types.h:370
int deprecated
Definition types.h:346
MODEL_OFFLOADING_STRATEGY model_offloading_strategy
Definition types.h:364
std::vector< Backend > backends
Definition types.h:342
int plot_inputs
Definition types.h:359
bool operator!=(const ModelInferenceArgs &other) const
Definition types.h:398
bool operator==(const MultisampleInferenceArgs &other) const
int parallel
Definition types.h:410
int result_to_input_num
Definition types.h:438
int samples
Definition types.h:414
int allow_mirroring
Definition types.h:418
int max_extension
Definition types.h:430
Interpolation jitter_interpolation
Definition types.h:422
bool operator!=(const MultisampleInferenceArgs &other) const
Definition types.h:465
int jitter_keep_size
Definition types.h:426
int result_to_input_denum
Definition types.h:442
PADDING_MODE padding_mode
Definition types.h:434
int slices
Definition types.h:481
int result_to_input_num
Definition types.h:489
int parallel
Definition types.h:477
int result_to_input_denum
Definition types.h:493
bool operator!=(const SlicedInferenceArgs &other) const
Definition types.h:516
int overlap
Definition types.h:485
bool operator==(const SlicedInferenceArgs &other) const
DIRECTION
Definition types.h:188
constexpr float BYTE_MAX_FLOAT
Definition types.h:34
FORWARD_MODE
Definition types.h:157
std::vector< int64_t > TensorSizes
Definition types.h:21
DataTypeEnum
Definition types.h:59
ReturnCode
Definition types.h:591
Backend
Definition types.h:194
Framework
Definition types.h:212
MODEL_OFFLOADING_STRATEGY
Definition types.h:183
PADDING_MODE
Definition types.h:175
constexpr float SHORT_MAX
Definition types.h:30
Interpolation
Definition types.h:162
OrderEnum
Definition types.h:74
constexpr int BYTE_MAX
Definition types.h:26
ColorFormatEnum
Definition types.h:105
DeviceEnum
Definition types.h:41
ModelDataType
Definition types.h:126
ValueRangeEnum
Definition types.h:46