mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-28 20:11:22 +00:00
Replace float_t with float (#16484)
A couple of places in onnxruntime used `float_t` data type alias as an
alternative to `float`. However, this is not entirely correct, since
`float_t` is an implementation-defined type alias, which may be `float`,
`double`, `long double` or some other implementation-defined data type,
depending on the state of the internal `FLT_EVAL_METHOD` macro:
https://en.cppreference.com/w/c/numeric/math/float_t
On most major platforms and compilers (clang, GCC, MSVC) this is only a
cosmetic change and will not lead to any changes. However, icpx compiler
(and legacy icc) tends to substitute `float_t` with `long double`,
resulting in a linker error (unresolved reference) to the base onnx
library, that only contains the `ParseData` function for `float` and
`double` as in
[here](9264e09367/onnx/defs/tensor_proto_util.cc (L133-L134)).
Overall, this PR cleans up the implementation-defined behaviour and
enables building onnxruntime with icpx.
This commit is contained in:
parent
4768ac5f30
commit
c3db1d3628
5 changed files with 14 additions and 14 deletions
|
|
@ -68,10 +68,10 @@ FakeRCTBlobManager *fakeBlobManager = nil;
|
|||
inputTensorMap[@"type"] = JsTensorTypeFloat;
|
||||
|
||||
// data
|
||||
std::array<float_t, 5> outValues{std::numeric_limits<float_t>::min(), 1.0f, -2.0f, 3.0f,
|
||||
std::numeric_limits<float_t>::max()};
|
||||
std::array<float, 5> outValues{std::numeric_limits<float>::min(), 1.0f, -2.0f, 3.0f,
|
||||
std::numeric_limits<float>::max()};
|
||||
|
||||
const NSInteger byteBufferSize = outValues.size() * sizeof(float_t);
|
||||
const NSInteger byteBufferSize = outValues.size() * sizeof(float);
|
||||
unsigned char *byteBuffer = static_cast<unsigned char *>(malloc(byteBufferSize));
|
||||
NSData *byteBufferRef = [NSData dataWithBytesNoCopy:byteBuffer length:byteBufferSize];
|
||||
float *floatPtr = (float *)[byteBufferRef bytes];
|
||||
|
|
|
|||
|
|
@ -66,9 +66,9 @@ static void testCreateInputTensorT(const std::array<T, 3> &outValues, std::funct
|
|||
}
|
||||
|
||||
- (void)testCreateInputTensorFloat {
|
||||
std::array<float_t, 3> outValues{std::numeric_limits<float_t>::min(), 2.0f, std::numeric_limits<float_t>::max()};
|
||||
std::function<NSNumber *(float_t value)> convert = [](float_t value) { return [NSNumber numberWithFloat:value]; };
|
||||
testCreateInputTensorT<float_t>(outValues, convert, ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT, JsTensorTypeFloat);
|
||||
std::array<float, 3> outValues{std::numeric_limits<float>::min(), 2.0f, std::numeric_limits<float>::max()};
|
||||
std::function<NSNumber *(float value)> convert = [](float value) { return [NSNumber numberWithFloat:value]; };
|
||||
testCreateInputTensorT<float>(outValues, convert, ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT, JsTensorTypeFloat);
|
||||
}
|
||||
|
||||
- (void)testCreateInputTensorDouble {
|
||||
|
|
@ -241,10 +241,10 @@ static void testCreateOutputTensorT(const std::array<T, 5> &outValues, std::func
|
|||
}
|
||||
|
||||
- (void)testCreateOutputTensorFloat {
|
||||
std::array<float_t, 5> outValues{std::numeric_limits<float_t>::min(), 1.0f, 2.0f, 3.0f,
|
||||
std::numeric_limits<float_t>::max()};
|
||||
std::function<NSNumber *(float_t value)> convert = [](float_t value) { return [NSNumber numberWithFloat:value]; };
|
||||
testCreateOutputTensorT<float_t>(outValues, convert, JsTensorTypeFloat, @"test_types_float", @"ort");
|
||||
std::array<float, 5> outValues{std::numeric_limits<float>::min(), 1.0f, 2.0f, 3.0f,
|
||||
std::numeric_limits<float>::max()};
|
||||
std::function<NSNumber *(float value)> convert = [](float value) { return [NSNumber numberWithFloat:value]; };
|
||||
testCreateOutputTensorT<float>(outValues, convert, JsTensorTypeFloat, @"test_types_float", @"ort");
|
||||
}
|
||||
|
||||
- (void)testCreateOutputTensorDouble {
|
||||
|
|
|
|||
|
|
@ -148,7 +148,7 @@ static Ort::Value createInputTensorT(OrtAllocator *ortAllocator, const std::vect
|
|||
allocations:(std::vector<Ort::MemoryAllocation> &)allocations {
|
||||
switch (tensorType) {
|
||||
case ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT:
|
||||
return createInputTensorT<float_t>(ortAllocator, dims, buffer, allocations);
|
||||
return createInputTensorT<float>(ortAllocator, dims, buffer, allocations);
|
||||
case ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT8:
|
||||
return createInputTensorT<uint8_t>(ortAllocator, dims, buffer, allocations);
|
||||
case ONNX_TENSOR_ELEMENT_DATA_TYPE_INT8:
|
||||
|
|
@ -193,7 +193,7 @@ template <typename T> static NSData *createOutputTensorT(const Ort::Value &tenso
|
|||
|
||||
switch (tensorType) {
|
||||
case ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT:
|
||||
return createOutputTensorT<float_t>(tensor);
|
||||
return createOutputTensorT<float>(tensor);
|
||||
case ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT8:
|
||||
return createOutputTensorT<uint8_t>(tensor);
|
||||
case ONNX_TENSOR_ELEMENT_DATA_TYPE_INT8:
|
||||
|
|
|
|||
|
|
@ -345,7 +345,7 @@ bool ValidateUnidirMask(const Graph& graph, const NodeArg& mask, bool& is_unidir
|
|||
return false;
|
||||
}
|
||||
} else if (tensor_proto->data_type() == ONNX_NAMESPACE::TensorProto_DataType_FLOAT) {
|
||||
std::vector<float_t> float_data = ONNX_NAMESPACE::ParseData<float_t>(tensor_proto);
|
||||
std::vector<float> float_data = ONNX_NAMESPACE::ParseData<float>(tensor_proto);
|
||||
if (!ValidateUnidirMask(float_data, shape->dim(2).dim_value(), is_unidirectional)) {
|
||||
DEBUG_LOG("Mask is neither unidirectional nor all ones");
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -670,7 +670,7 @@ static TrilinearParams SetupUpsampleTrilinear(int64_t input_depth,
|
|||
// pixel value in the output
|
||||
// (cache because we don't have to re-compute each time we come across the output width/output height value
|
||||
// while iterating the output image tensor
|
||||
SafeInt<size_t> scale_buffer_size = SafeInt<size_t>(2) * sizeof(float_t) *
|
||||
SafeInt<size_t> scale_buffer_size = SafeInt<size_t>(2) * sizeof(float) *
|
||||
(output_depth + output_height + output_width);
|
||||
|
||||
// Limit number of allocations to just 1
|
||||
|
|
|
|||
Loading…
Reference in a new issue