Skip to content

Commit

Permalink
condition min build
Browse files Browse the repository at this point in the history
Signed-off-by: Liqun Fu <[email protected]>
  • Loading branch information
liqunfu committed Oct 24, 2023
1 parent c2d30ac commit 1c9ccbd
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 25 deletions.
6 changes: 4 additions & 2 deletions docs/OperatorKernels.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,10 @@ Do not modify directly.*
|||[1, 10]|**B** = tensor(bool)<br/> **V** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)|
|ImageScaler|*in* input:**T**<br> *out* output:**T**|1+|**T** = tensor(float)|
|InstanceNormalization|*in* input:**T**<br> *in* scale:**T**<br> *in* B:**T**<br> *out* output:**T**|6+|**T** = tensor(float)|
|IsInf|*in* X:**T1**<br> *out* Y:**T2**|10+|**T1** = tensor(double), tensor(float)<br/> **T2** = tensor(bool)|
|IsNaN|*in* X:**T1**<br> *out* Y:**T2**|13+|**T1** = tensor(double), tensor(float), tensor(float16)<br/> **T2** = tensor(bool)|
|IsInf|*in* X:**T1**<br> *out* Y:**T2**|20+|**T1** = tensor(double), tensor(float), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)<br/> **T2** = tensor(bool)|
|||[10, 19]|**T1** = tensor(double), tensor(float)<br/> **T2** = tensor(bool)|
|IsNaN|*in* X:**T1**<br> *out* Y:**T2**|20+|**T1** = tensor(double), tensor(float), tensor(float16), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)<br/> **T2** = tensor(bool)|
|||[13, 19]|**T1** = tensor(double), tensor(float), tensor(float16)<br/> **T2** = tensor(bool)|
|||[9, 12]|**T1** = tensor(double), tensor(float), tensor(float16)<br/> **T2** = tensor(bool)|
|LRN|*in* X:**T**<br> *out* Y:**T**|13+|**T** = tensor(float)|
|||[1, 12]|**T** = tensor(float)|
Expand Down
6 changes: 3 additions & 3 deletions onnxruntime/core/providers/cpu/cpu_execution_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1990,11 +1990,11 @@ Status RegisterOnnxOperatorKernels(KernelRegistry& kernel_registry) {
BuildKernelCreateInfo<ONNX_OPERATOR_VERSIONED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 13, 15, ScatterND)>,
BuildKernelCreateInfo<ONNX_OPERATOR_VERSIONED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 13, 13, Identity)>,
BuildKernelCreateInfo<ONNX_OPERATOR_VERSIONED_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 13, 19, float,
IsNaN)>,
IsNaN)>,
BuildKernelCreateInfo<ONNX_OPERATOR_VERSIONED_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 13, 19, double,
IsNaN)>,
IsNaN)>,
BuildKernelCreateInfo<ONNX_OPERATOR_VERSIONED_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 13, 19, MLFloat16,
IsNaN)>,
IsNaN)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 13, bool,
NonZero)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 13, float,
Expand Down
24 changes: 12 additions & 12 deletions onnxruntime/core/providers/cpu/tensor/isinf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,25 @@ using IsInfTypesOpset20 =
float,
double
#if !defined(DISABLE_FLOAT8_TYPES)
,Float8E4M3FN, Float8E4M3FNUZ, Float8E5M2, Float8E5M2FNUZ
,
Float8E4M3FN, Float8E4M3FNUZ, Float8E5M2, Float8E5M2FNUZ
#endif
>;

ORT_SPECIFY_OP_KERNEL_ARG_DEFAULT_TYPE_LIST(
kCpuExecutionProvider,
kOnnxDomain,
IsInf,
20,
Input,
0,
IsInfTypesOpset20);
kCpuExecutionProvider,
kOnnxDomain,
IsInf,
20,
Input,
0,
IsInfTypesOpset20);
} // namespace op_kernel_type_control



class IsInf final : public OpKernel {
public:
using EnabledDataTypes10 = ORT_OP_KERNEL_ARG_ENABLED_TYPE_LIST(kCpuExecutionProvider, kOnnxDomain,
IsInf, 10, Input, 0);
IsInf, 10, Input, 0);
using EnabledDataTypes20 = ORT_OP_KERNEL_ARG_ENABLED_TYPE_LIST(kCpuExecutionProvider, kOnnxDomain,
IsInf, 20, Input, 0);

Expand Down Expand Up @@ -76,7 +75,6 @@ ONNX_CPU_OPERATOR_KERNEL(
.TypeConstraint("T2", DataTypeImpl::GetTensorType<bool>()),
IsInf);


IsInf::IsInf(const OpKernelInfo& info) : OpKernel(info) {
Status status = info.GetAttr("detect_positive", &detect_positive_);
ORT_ENFORCE(status.IsOK(), "Failed to obtain detect_positive");
Expand Down Expand Up @@ -116,6 +114,7 @@ struct ComputeDispatchTarget {
}
};

#if !defined(DISABLE_FLOAT8_TYPES)
template <>
struct ComputeDispatchTarget<Float8E4M3FN> {
void operator()(const Tensor&, Tensor& Y, bool, bool) const {
Expand Down Expand Up @@ -156,6 +155,7 @@ struct ComputeDispatchTarget<Float8E5M2FNUZ> {
EigenMap<bool>(Y).array() = false;
}
};
#endif
} // namespace isinf_internal

Status IsInf::Compute(OpKernelContext* context) const {
Expand Down
14 changes: 9 additions & 5 deletions onnxruntime/core/providers/cpu/tensor/isnan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,13 @@ ADD_TYPED_ISNAN_OP_13(MLFloat16);
ADD_TYPED_ISNAN_OP(float);
ADD_TYPED_ISNAN_OP(double);
ADD_TYPED_ISNAN_OP(MLFloat16);

#if !defined(DISABLE_FLOAT8_TYPES)
ADD_TYPED_ISNAN_OP(Float8E4M3FN);
ADD_TYPED_ISNAN_OP(Float8E4M3FNUZ);
ADD_TYPED_ISNAN_OP(Float8E5M2);
ADD_TYPED_ISNAN_OP(Float8E5M2FNUZ);
#endif

template <typename T>
Status IsNaN<T>::Compute(OpKernelContext* context) const {
Expand Down Expand Up @@ -88,17 +91,18 @@ Status IsNaN<MLFloat16>::Compute(OpKernelContext* context) const {
return Status::OK();
}

#if !defined(DISABLE_FLOAT8_TYPES)
template <>
Status IsNaN<Float8E4M3FN>::Compute(OpKernelContext* context) const {
const auto* X = context->Input<Tensor>(0);
auto& dims = X->Shape();
auto& Y = *context->Output(0, dims);
auto& Y = *context->Output(0, dims);

auto input = ConstEigenVectorMap<uint8_t>(static_cast<const uint8_t*>(static_cast<const void*>(X->Data<Float8E4M3FN>())), onnxruntime::narrow<size_t>(dims.Size()));
auto output = EigenMap<bool>(Y);

// S.1111.111
std::transform(input.begin(), input.end(), output.begin(), [](uint8_t c) { return (c & 0x7f) == 0x7f;});
std::transform(input.begin(), input.end(), output.begin(), [](uint8_t c) { return (c & 0x7f) == 0x7f; });
return Status::OK();
}

Expand Down Expand Up @@ -126,9 +130,8 @@ Status IsNaN<Float8E5M2>::Compute(OpKernelContext* context) const {
auto input = ConstEigenVectorMap<uint8_t>(static_cast<const uint8_t*>(static_cast<const void*>(X->Data<Float8E5M2>())), onnxruntime::narrow<size_t>(dims.Size()));
auto output = EigenMap<bool>(Y);

// S.11111.{01, 10, 11}
std::transform(input.begin(), input.end(), output.begin(), [](uint8_t c) {
return ((c & 0x7c) == 0x7c) && ((c & 0x03) != 0x00); });
// S.11111.{01, 10, 11}
std::transform(input.begin(), input.end(), output.begin(), [](uint8_t c) { return ((c & 0x7c) == 0x7c) && ((c & 0x03) != 0x00); });
return Status::OK();
}

Expand All @@ -145,4 +148,5 @@ Status IsNaN<Float8E5M2FNUZ>::Compute(OpKernelContext* context) const {

return Status::OK();
}
#endif
} // namespace onnxruntime
7 changes: 4 additions & 3 deletions onnxruntime/test/providers/cpu/tensor/isinf_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ constexpr double DOUBLE_INF = std::numeric_limits<double>::infinity();
constexpr double DOUBLE_NINF = -std::numeric_limits<double>::infinity();
constexpr double DOUBLE_NAN = std::numeric_limits<double>::quiet_NaN();

template<typename T>
template <typename T>
void run_is_inf_test(int opset, int64_t detect_positive, int64_t detect_negative, const std::initializer_list<T>& input, const std::initializer_list<bool>& output) {
OpTester test("IsInf", opset);
test.AddAttribute<int64_t>("detect_positive", detect_positive);
Expand Down Expand Up @@ -99,10 +99,10 @@ TEST(IsInfTest, test_isinf_negative_double20) {
run_is_inf_test(20, 0, 1, input, output);
}

#if !defined(DISABLE_FLOAT8_TYPES)
TEST(IsInfTest, test_Float8E4M3FN) {
std::initializer_list<Float8E4M3FN> input = {
Float8E4M3FN(-1.0f), Float8E4M3FN(FLOAT_NAN, false), Float8E4M3FN(1.0f), Float8E4M3FN(FLOAT_NINF, false), Float8E4M3FN(FLOAT_NINF, false), Float8E4M3FN(FLOAT_INF, false)
};
Float8E4M3FN(-1.0f), Float8E4M3FN(FLOAT_NAN, false), Float8E4M3FN(1.0f), Float8E4M3FN(FLOAT_NINF, false), Float8E4M3FN(FLOAT_NINF, false), Float8E4M3FN(FLOAT_INF, false)};
std::initializer_list<bool> output = {false, false, false, false, false, false};
run_is_inf_test(20, 1, 1, input, output);
}
Expand Down Expand Up @@ -148,5 +148,6 @@ TEST(IsInfTest, test_Float8E5M2FNUZ) {
std::initializer_list<bool> output = {false, false, false, false, false, false};
run_is_inf_test(20, 1, 1, input, output);
}
#endif
} // namespace test
} // namespace onnxruntime
2 changes: 2 additions & 0 deletions onnxruntime/test/providers/cpu/tensor/isnan_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ TEST(IsNaNOpTest, IsNaNDouble20) {
run_is_nan_test(20, dims, input, output);
}

#if !defined(DISABLE_FLOAT8_TYPES)
TEST(IsNaNOpTest, IsNaNFloat8E4M3FN) {
std::vector<int64_t> dims{2, 2};
std::initializer_list<Float8E4M3FN> input = {Float8E4M3FN(1.0f), Float8E4M3FN(-NAN), Float8E4M3FN(2.0f), Float8E4M3FN(NAN)};
Expand Down Expand Up @@ -86,5 +87,6 @@ TEST(IsNaNOpTest, IsNaN_Float8E5M2FNUZ) {
std::initializer_list<bool> output = {false, true, false, true};
run_is_nan_test(20, dims, input, output);
}
#endif
} // namespace test
} // namespace onnxruntime

0 comments on commit 1c9ccbd

Please sign in to comment.