|
| 1 | +/* |
| 2 | + * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | + * All rights reserved. |
| 4 | + * |
| 5 | + * This source code is licensed under the BSD-style license found in the |
| 6 | + * LICENSE file in the root directory of this source tree. |
| 7 | + */ |
| 8 | + |
| 9 | +#include <executorch/kernels/test/UnaryUfuncRealHBToFloatHTest.h> |
| 10 | + |
| 11 | +namespace torch::executor::testing { |
| 12 | +void UnaryUfuncRealHBToFloatHTest::test_bool_input() { |
| 13 | + TensorFactory<exec_aten::ScalarType::Bool> tf_bool; |
| 14 | + TensorFactory<exec_aten::ScalarType::Float> tf_float; |
| 15 | + |
| 16 | + const std::vector<int32_t> sizes = {1, 2}; |
| 17 | + |
| 18 | + exec_aten::Tensor a = tf_bool.make(sizes, /*data=*/{false, true}); |
| 19 | + exec_aten::Tensor out = tf_float.zeros(sizes); |
| 20 | + exec_aten::Tensor res = tf_float.make( |
| 21 | + sizes, |
| 22 | + /*data=*/{(float)op_reference(false), (float)op_reference(true)}); |
| 23 | + |
| 24 | + EXPECT_TENSOR_CLOSE(op_out(a, out), res); |
| 25 | +} |
| 26 | + |
| 27 | +void UnaryUfuncRealHBToFloatHTest::test_mismatched_input_shapes_dies() { |
| 28 | + if (get_supported_features()->is_aten) { |
| 29 | + GTEST_SKIP() << "ATen kernel can handle mismatched input shapes"; |
| 30 | + } |
| 31 | + TensorFactory<exec_aten::ScalarType::Float> tf; |
| 32 | + |
| 33 | + exec_aten::Tensor a = tf.ones(/*sizes=*/{4}); |
| 34 | + exec_aten::Tensor out = tf.ones(/*sizes=*/{2, 2}); |
| 35 | + |
| 36 | + ET_EXPECT_KERNEL_FAILURE(context_, op_out(a, out)); |
| 37 | +} |
| 38 | + |
| 39 | +void UnaryUfuncRealHBToFloatHTest:: |
| 40 | + test_all_real_input_half_output_static_dynamism_support() { |
| 41 | + if (get_supported_features()->is_aten) { |
| 42 | + GTEST_SKIP() << "Test Half support only for ExecuTorch mode"; |
| 43 | + } |
| 44 | +#define TEST_ENTRY(ctype, dtype) \ |
| 45 | + test_floating_point_op_out< \ |
| 46 | + exec_aten::ScalarType::dtype, \ |
| 47 | + exec_aten::ScalarType::Half>(); |
| 48 | + ET_FORALL_REALH_TYPES(TEST_ENTRY); |
| 49 | +#undef TEST_ENTRY |
| 50 | +} |
| 51 | + |
| 52 | +void UnaryUfuncRealHBToFloatHTest:: |
| 53 | + test_all_real_input_float_output_static_dynamism_support() { |
| 54 | +#define TEST_ENTRY(ctype, dtype) \ |
| 55 | + test_floating_point_op_out< \ |
| 56 | + exec_aten::ScalarType::dtype, \ |
| 57 | + exec_aten::ScalarType::Float>(); |
| 58 | + ET_FORALL_REAL_TYPES(TEST_ENTRY); |
| 59 | +#undef TEST_ENTRY |
| 60 | +} |
| 61 | + |
| 62 | +void UnaryUfuncRealHBToFloatHTest:: |
| 63 | + test_all_real_input_double_output_static_dynamism_support() { |
| 64 | +#define TEST_ENTRY(ctype, dtype) \ |
| 65 | + test_floating_point_op_out< \ |
| 66 | + exec_aten::ScalarType::dtype, \ |
| 67 | + exec_aten::ScalarType::Double>(); |
| 68 | + ET_FORALL_REAL_TYPES(TEST_ENTRY); |
| 69 | +#undef TEST_ENTRY |
| 70 | +} |
| 71 | + |
| 72 | +void UnaryUfuncRealHBToFloatHTest:: |
| 73 | + test_all_real_input_half_output_bound_dynamism_support() { |
| 74 | + if (get_supported_features()->is_aten) { |
| 75 | + GTEST_SKIP() << "Test Half support only for ExecuTorch mode"; |
| 76 | + } |
| 77 | +#define TEST_ENTRY(ctype, dtype) \ |
| 78 | + test_floating_point_op_out< \ |
| 79 | + exec_aten::ScalarType::dtype, \ |
| 80 | + exec_aten::ScalarType::Half>( \ |
| 81 | + {10, 10}, exec_aten::TensorShapeDynamism::DYNAMIC_BOUND); |
| 82 | + ET_FORALL_REALH_TYPES(TEST_ENTRY); |
| 83 | +#undef TEST_ENTRY |
| 84 | +} |
| 85 | + |
| 86 | +void UnaryUfuncRealHBToFloatHTest:: |
| 87 | + test_all_real_input_float_output_bound_dynamism_support() { |
| 88 | +#define TEST_ENTRY(ctype, dtype) \ |
| 89 | + test_floating_point_op_out< \ |
| 90 | + exec_aten::ScalarType::dtype, \ |
| 91 | + exec_aten::ScalarType::Float>( \ |
| 92 | + {10, 10}, exec_aten::TensorShapeDynamism::DYNAMIC_BOUND); |
| 93 | + ET_FORALL_REAL_TYPES(TEST_ENTRY); |
| 94 | +#undef TEST_ENTRY |
| 95 | +} |
| 96 | + |
| 97 | +void UnaryUfuncRealHBToFloatHTest:: |
| 98 | + test_all_real_input_double_output_bound_dynamism_support() { |
| 99 | +#define TEST_ENTRY(ctype, dtype) \ |
| 100 | + test_floating_point_op_out< \ |
| 101 | + exec_aten::ScalarType::dtype, \ |
| 102 | + exec_aten::ScalarType::Double>( \ |
| 103 | + {10, 10}, exec_aten::TensorShapeDynamism::DYNAMIC_BOUND); |
| 104 | + ET_FORALL_REAL_TYPES(TEST_ENTRY); |
| 105 | +#undef TEST_ENTRY |
| 106 | +} |
| 107 | + |
| 108 | +void UnaryUfuncRealHBToFloatHTest:: |
| 109 | + test_all_real_input_float_output_unbound_dynamism_support() { |
| 110 | + if (!get_supported_features()->is_aten) { |
| 111 | + GTEST_SKIP() << "Dynamic shape unbound not supported"; |
| 112 | + } |
| 113 | +#define TEST_ENTRY(ctype, dtype) \ |
| 114 | + test_floating_point_op_out< \ |
| 115 | + exec_aten::ScalarType::dtype, \ |
| 116 | + exec_aten::ScalarType::Float>( \ |
| 117 | + {1, 1}, exec_aten::TensorShapeDynamism::DYNAMIC_UNBOUND); |
| 118 | + ET_FORALL_REAL_TYPES(TEST_ENTRY); |
| 119 | +#undef TEST_ENTRY |
| 120 | +} |
| 121 | + |
| 122 | +void UnaryUfuncRealHBToFloatHTest:: |
| 123 | + test_all_real_input_double_output_unbound_dynamism_support() { |
| 124 | + if (!get_supported_features()->is_aten) { |
| 125 | + GTEST_SKIP() << "Dynamic shape unbound not supported"; |
| 126 | + } |
| 127 | +#define TEST_ENTRY(ctype, dtype) \ |
| 128 | + test_floating_point_op_out< \ |
| 129 | + exec_aten::ScalarType::dtype, \ |
| 130 | + exec_aten::ScalarType::Double>( \ |
| 131 | + {1, 1}, exec_aten::TensorShapeDynamism::DYNAMIC_UNBOUND); |
| 132 | + ET_FORALL_REAL_TYPES(TEST_ENTRY); |
| 133 | +#undef TEST_ENTRY |
| 134 | +} |
| 135 | + |
| 136 | +void UnaryUfuncRealHBToFloatHTest::test_non_float_output_dtype_dies() { |
| 137 | +#define TEST_ENTRY(ctype, dtype) \ |
| 138 | + test_op_invalid_output_dtype_dies< \ |
| 139 | + exec_aten::ScalarType::Float, \ |
| 140 | + exec_aten::ScalarType::dtype>(); |
| 141 | + ET_FORALL_INT_TYPES(TEST_ENTRY); |
| 142 | +#undef TEST_ENTRY |
| 143 | +} |
| 144 | + |
| 145 | +} // namespace torch::executor::testing |
0 commit comments