-
Notifications
You must be signed in to change notification settings - Fork 531
/
Copy pathpattern.h
95 lines (82 loc) · 3.36 KB
/
pattern.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
/* Naming Convention
--------------------
Each pattern name should be all lowercase words separated by underscores.
It should start with unary/binary/ternary depending on the number of input
tensors.
It should then specify the type of function that it is. E.g: ufunc, reduce, etc
Ufunc is a concept used in NumPy and PyTorch (short for universal function)
See NumPy's definition here: https://numpy.org/doc/stable/reference/ufuncs.html
It should then specify the sets of dtypes accepted as inputs and output.
We currently support the following sets of dtypes:
- bool {Bool}
- int {Byte, Char, Short, Int, Long}
- intb {Byte, Char, Short, Int, Long, Bool}
- float {Float, Double}
- floath {Half, Float, Double}
- floatb {Float, Double, Bool}
- real {Byte, Char, Short, Int, Long, Float, Double}
- realb {Byte, Char, Short, Int, Long, Float, Double, Bool}
- realh {Byte, Char, Short, Int, Long, Half, Float, Double}
- realhb {Byte, Char, Short, Int, Long, Half, Float, Double, Bool}
Input types are separated from output types by the "to" word.
Input types are separated by underscores. Output types as well, in the cases
when there are multiple outputs.
In the case of ops that only allow the same dtype (for example abs/neg where
the input and output dtype must be the same, only that dtype is specified.
E.g, there is a difference between:
- unary_ufunc_real_to_real
(output and input types must be real, but might be different)
- unary_ufunc_real
(output must be same type than input, which must be real)
A pattern named using this convention will be quite generic. If the pattern in
question is a bit more specific, then add a descriptive sufix. */
#pragma once
#include <executorch/runtime/kernel/kernel_includes.h>
namespace torch {
namespace executor {
namespace native {
namespace internal {
/**
* Implements an op pattern for ops that take a single input tensor of any
* realh dtye, no additional arguments, and outputs a tensor of the same size
* and dtype. The function fn specifies the math operation which is applied to
* the input tensor element-wise.
*/
Tensor& unary_ufunc_realhbf16(
double (*fn)(double),
KernelRuntimeContext& ctx,
const Tensor& in,
Tensor& out);
/**
* Implements an op pattern for ops that take a single input tensor of any
* realhb dtye (real, half and boolean), no additional arguments, and outputs a
* boolean tensor of the same size. The function fn specifies the math
* operation which is applied to the input tensor element-wise.
*/
Tensor& unary_ufunc_realhb_to_bool(
bool (*fn)(double),
KernelRuntimeContext& ctx,
const Tensor& in,
Tensor& out);
/**
* Implements an op pattern for ops that take a single input tensor of any
* realhbbf16 dtype (real/half/bool/bfloat16), no additional arguments, and
* outputs a floating point tensor of the same size. The function fn specifies
* the math operation which is applied to the input tensor element-wise.
*/
Tensor& unary_ufunc_realhbbf16_to_floathbf16(
double (*fn)(double),
KernelRuntimeContext& ctx,
const Tensor& in,
Tensor& out);
} // namespace internal
} // namespace native
} // namespace executor
} // namespace torch