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};
206
210enum Framework { TORCHSCRIPT, ONNXRUNTIME };
211
215struct EXPORT_OR_IMPORT BlaceHash {
219 uint64_t hash[4];
220
227 bool operator==(const BlaceHash &rhs) const;
228
235 bool operator!=(const BlaceHash &rhs) const;
236
243 bool operator<(const BlaceHash &rhs) const;
244
250 long long to_long_long();
251
258 std::string to_hex(int len = 8);
259
263 friend std::ostream &operator<<(std::ostream &os, const BlaceHash &obj);
264
270
276 BlaceHash(int seed);
277
283 BlaceHash(std::string str);
284
293 BlaceHash(int64_t a, int64_t b, int64_t c, int64_t d);
294
300 std::string print() {
301 std::string returnstring = "";
302 for (int temp = 0; temp < 4; temp++)
303 returnstring += std::to_string(hash[temp]) + "\n";
304 return returnstring;
305 }
306
313 static void mix_string_into_hash(BlaceHash &hash, std::string str);
314
321 static void mix_float_into_hash(BlaceHash &hash, float data);
322
329 static void mix_hash_into_hash(BlaceHash &hash, BlaceHash data);
330};
331
340 std::vector<Backend> backends;
344 int deprecated = true;
348 int seed = 0;
353 int run_threaded = false;
357 int plot_inputs = false;
363 MODEL_OFFLOADING_STRATEGY::FULL_UNLOAD;
369
374
381
388 bool operator==(const ModelInferenceArgs &other) const;
389
396 bool operator!=(const ModelInferenceArgs &other) const {
397 return !(*this == other);
398 }
399};
400
408 int parallel = true;
412 int samples = 1;
416 int allow_mirroring = true;
424 int jitter_keep_size = false;
432 PADDING_MODE padding_mode = PADDING_MODE::REFLECTION;
441
448
455 bool operator==(const MultisampleInferenceArgs &other) const;
456
463 bool operator!=(const MultisampleInferenceArgs &other) const {
464 return !(*this == other);
465 }
466};
467
475 int parallel = true;
479 int slices = 1;
483 int overlap = 32;
492
499
506 bool operator==(const SlicedInferenceArgs &other) const;
507
514 bool operator!=(const SlicedInferenceArgs &other) const {
515 return !(*this == other);
516 }
517};
518
523public:
533 ml_core::FORWARD_MODE mode = FORWARD_MODE::SIMPLE;
537 std::optional<MultisampleInferenceArgs> multi_args = std::nullopt;
541 std::optional<SlicedInferenceArgs> sliced_args = std::nullopt;
542
549
556 bool operator==(const InferenceArgsCollection &other) const;
557
564 bool operator!=(const InferenceArgsCollection &other) const {
565 return !(*this == other);
566 }
567};
568
572class ModelIdent : public std::string {
573public:
574 using std::string::string;
575
581 ModelIdent(const std::string &str) : std::string(str) {
582 // Additional initialization or processing can be done here
583 }
584};
585
589enum class ReturnCode {
590 OK = 0,
591 Error = 1, // Returned on generic errors
592 UserCancelled = 2, // This will be returned if a callback passed to the
593 // evaluator signalled cancelation.
594 UserKilled = 3, // This will be returned if a callback passed to the evaluator
595 // signalled a killing wish.
596 MissingData =
597 4, // Returned if missing data was encountered during computation
598 Error_OOM = 5, // Returned if method run into an OOM situation. Will only
599 // happen if returned from RawMemoryFetcher.
600 ModelFileNotPresent = 6, // Model file was not found
601 Error_Inference_OOM = 7, // Returned if worker ran out of RAM / VRAM during
602 // inference.
603 Error_IPC_Timeout = 8 // Returned if IPC process timed out.
604
605};
606
607} // namespace ml_core
608} // namespace blace
ml_core::FORWARD_MODE mode
Definition types.h:533
bool operator!=(const InferenceArgsCollection &other) const
Definition types.h:564
ModelInferenceArgs inference_args
Definition types.h:527
bool operator==(const InferenceArgsCollection &other) const
std::optional< SlicedInferenceArgs > sliced_args
Definition types.h:541
std::optional< MultisampleInferenceArgs > multi_args
Definition types.h:537
Definition types.h:572
ModelIdent(const std::string &str)
Definition types.h:581
Definition types.h:215
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:300
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:353
bool operator==(const ModelInferenceArgs &other) const
int seed
Definition types.h:348
int experimental_torchscript_autocast
Definition types.h:373
int empty_cache_after_inference
Definition types.h:368
int deprecated
Definition types.h:344
MODEL_OFFLOADING_STRATEGY model_offloading_strategy
Definition types.h:362
std::vector< Backend > backends
Definition types.h:340
int plot_inputs
Definition types.h:357
bool operator!=(const ModelInferenceArgs &other) const
Definition types.h:396
bool operator==(const MultisampleInferenceArgs &other) const
int parallel
Definition types.h:408
int result_to_input_num
Definition types.h:436
int samples
Definition types.h:412
int allow_mirroring
Definition types.h:416
int max_extension
Definition types.h:428
Interpolation jitter_interpolation
Definition types.h:420
bool operator!=(const MultisampleInferenceArgs &other) const
Definition types.h:463
int jitter_keep_size
Definition types.h:424
int result_to_input_denum
Definition types.h:440
PADDING_MODE padding_mode
Definition types.h:432
int slices
Definition types.h:479
int result_to_input_num
Definition types.h:487
int parallel
Definition types.h:475
int result_to_input_denum
Definition types.h:491
bool operator!=(const SlicedInferenceArgs &other) const
Definition types.h:514
int overlap
Definition types.h:483
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:589
Backend
Definition types.h:194
Framework
Definition types.h:210
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