Builder C++-API#
Common#
Enumerations
Functions
Classes
Typedefs
Variables
Common Enumerations#
arithmetic#
-
enum class tinytc::arithmetic#
Arithmetic operations.
Values:
-
enumerator add = tinytc_arithmetic_add#
add
-
enumerator sub = tinytc_arithmetic_sub#
subtract
-
enumerator mul = tinytc_arithmetic_mul#
multiply
-
enumerator div = tinytc_arithmetic_div#
divide
-
enumerator rem = tinytc_arithmetic_rem#
division remainder
-
enumerator shl = tinytc_arithmetic_shl#
left shift
-
enumerator shr = tinytc_arithmetic_shr#
arithmetic right shift
-
enumerator and_ = tinytc_arithmetic_and#
bitwise and
-
enumerator or_ = tinytc_arithmetic_or#
bitwise or
-
enumerator xor_ = tinytc_arithmetic_xor#
bitwise xor
-
enumerator add = tinytc_arithmetic_add#
arithmetic_unary#
cmp_condition#
-
enum class tinytc::cmp_condition#
Compare operation.
Values:
-
enumerator eq = tinytc_cmp_condition_eq#
equals
-
enumerator ne = tinytc_cmp_condition_ne#
not equal
-
enumerator gt = tinytc_cmp_condition_gt#
greater than
-
enumerator ge = tinytc_cmp_condition_ge#
greather or equal than
-
enumerator lt = tinytc_cmp_condition_lt#
less than
-
enumerator le = tinytc_cmp_condition_le#
less or equal than
-
enumerator eq = tinytc_cmp_condition_eq#
scalar_type#
-
enum class tinytc::scalar_type#
Scalar types.
Values:
-
enumerator i1 = tinytc_scalar_type_i1#
Signed 1 bit integer (boolean)
-
enumerator i8 = tinytc_scalar_type_i8#
Signed 8 bit integer.
-
enumerator i16 = tinytc_scalar_type_i16#
Signed 16 bit integer.
-
enumerator i32 = tinytc_scalar_type_i32#
Signed 32 bit integer.
-
enumerator i64 = tinytc_scalar_type_i64#
Signed 64 bit integer.
-
enumerator index = tinytc_scalar_type_index#
Unsigned Integer type for indices.
-
enumerator f32 = tinytc_scalar_type_f32#
Single precision floating point (32 bit)
-
enumerator f64 = tinytc_scalar_type_f64#
Double precision floating point (64 bit)
-
enumerator i1 = tinytc_scalar_type_i1#
transpose#
Common Functions#
is_dynamic_value#
-
inline bool tinytc::is_dynamic_value(std::int64_t i)#
Check if mode i is dynamic (‘?’)
to_string(arithmetic)#
-
inline char const *tinytc::to_string(arithmetic op)#
Convert arithmetic operation type to string.
- Parameters:
op – Arithmetic operation type
- Returns:
C-string
to_string(arithmetic_unary)#
-
inline char const *tinytc::to_string(arithmetic_unary op)#
Convert arithmetic operation type to string (unary)
- Parameters:
op – Arithmetic operation type
- Returns:
C-string
to_string(cmp_condition)#
-
inline char const *tinytc::to_string(cmp_condition cond)#
Convert cmp condition to string.
- Parameters:
cond – Condition
- Returns:
C-string
to_string(scalar_type)#
-
inline char const *tinytc::to_string(scalar_type ty)#
Convert scalar type to string.
to_string(transpose)#
size#
-
inline std::size_t tinytc::size(scalar_type ty)#
Size of scalar type in bytes.
Common Classes#
builder_error#
-
class builder_error : public std::exception#
Builder exception enhanced with location.
Common Typedefs#
position#
-
using tinytc::position = ::tinytc_position#
Alias for tinytc_position in namespace tinytc.
location#
-
using tinytc::location = ::tinytc_location#
Alias for tinytc_location in namespace tinytc.
Common Variables#
dynamic#
-
static constexpr std::int64_t tinytc::dynamic = TINYTC_DYNAMIC#
Data Type#
Functions
Classes
Structures
Variables
Data Type Functions#
make_memref#
-
inline data_type tinytc::make_memref(scalar_type scalar_ty, std::vector<std::int64_t> const &shape, std::vector<std::int64_t> const &stride = {}, location const &loc = {})#
Make a memref data type.
- Parameters:
scalar_ty – Element type
shape – Tensor shape
stride – Tensor stride
loc – Source code location
- Returns:
Data type
make_group#
make_scalar#
-
inline data_type tinytc::make_scalar(scalar_type scalar_ty, location const &loc = {})#
Make a scalar data type.
- Parameters:
scalar_ty – Scalar type
loc – Source code location
- Returns:
Data type
Data Type Classes#
data_type#
-
class data_type : public tinytc::shared_handle<tinytc_data_type_t>#
Reference-counting wrapper for tinytc_data_type_t.
Public Functions
Create empty (invalid) handle.
Create handle from C handle.
Copy ctor.
Move ctor.
Data Type Structures#
to_scalar_type#
-
template<typename T>
struct to_scalar_type# Returns the scalar type corresponding to C++ type T
Specializations exist for bool, (u)int8_t, (u)int16_t, (u)int32_t, (u)int64_t, float, double. The scalar_type is stored in the static constexpr member “value”.
Data Type Variables#
to_scalar_type_v#
-
template<typename T>
constexpr scalar_type tinytc::to_scalar_type_v = to_scalar_type<T>::value# Convenience variable for to_scalar_type.
Example:
scalar_type ty = to_scalar_type_v<float>;
Function#
Functions
Classes
Function Functions#
make_function#
make_function_prototype#
set_work_group_size#
set_subgroup_size#
Function Classes#
func#
-
class func : public tinytc::shared_handle<tinytc_func_t>#
Reference-counting wrapper for tinytc_func_t.
Public Functions
Create empty (invalid) handle.
Create handle from C handle.
Copy ctor.
Move ctor.
function_builder#
-
class function_builder#
Builder for functions.
Public Functions
-
inline function_builder(std::string name)#
creates function @name
- Parameters:
name – Function name
-
inline func get_product(location const &loc = {})#
Returns built product.
- Parameters:
loc – Source code location
- Returns:
Function
-
inline value argument(data_type const &ty, std::string const &name = "", location const &loc = {})#
%name: %ty
- Parameters:
ty – Argument type
name – Argument name
loc – Source code location
- Returns:
Value
-
inline void work_group_size(std::int32_t x, std::int32_t y)#
work_group_size(%x, %y)
- Parameters:
x – x
y – y
-
inline void subgroup_size(std::int32_t subgroup_size)#
subgroup_size(%subgroup_size)
- Parameters:
subgroup_size – Subgroup size
-
inline function_builder(std::string name)#
Instruction#
Functions
Classes
Instruction Functions#
make_alloca#
make_axpby#
-
inline inst tinytc::make_axpby(transpose tA, bool atomic, value const &alpha, value const &A, value const &beta, value const &B, location const &loc = {})#
Make AXPBY instruction.
- Parameters:
tA – Operation applied on A
atomic – true for atomic updates of B
alpha – \(\alpha\)
A – A
beta – \(\beta\)
B – B
loc – Source code location
- Returns:
Instruction
make_arith(arithmetic,value const&,value const&,location const&)#
make_arith(arithmetic_unary,value const&,location const&)#
-
inline inst tinytc::make_arith(arithmetic_unary op, value const &a, location const &loc = {})#
Make arithmetic instruction (unary)
- Parameters:
op – Arithmetic operation type
a – Operand
loc – Source code location
- Returns:
Instruction
make_cast#
-
inline inst tinytc::make_cast(value const &a, scalar_type to_ty, location const &loc = {})#
Make cast instruction.
- Parameters:
a – Operand
to_ty – Target type
loc – Source code lcoation
- Returns:
Instruction
make_cmp#
make_expand#
make_for#
-
inline inst tinytc::make_for(value const &loop_var, value const &from, value const &to, value const &step, region const &body, location const &loc = {})#
Make for loop instruction.
- Parameters:
loop_var – Loop variable
from – Loop variable start
to – Loop variable bound
step – Loop variable step
body – Loop body
loc – Source code location
- Returns:
Instruction
make_foreach#
-
inline inst tinytc::make_foreach(value const &loop_var, value const &from, value const &to, region const &body, location const &loc = {})#
Make foreach loop instruction.
- Parameters:
loop_var – Loop variable
from – Loop variable start
to – Loop variable bound
body – Loop body
loc – Source code location
- Returns:
Instruction
make_fuse#
make_gemm#
-
inline inst tinytc::make_gemm(transpose tA, transpose tB, bool atomic, value const &alpha, value const &A, value const &B, value const &beta, value const &C, location const &loc = {})#
Make GEMM instruction.
- Parameters:
tA – Operation applied on A
tB – Operation applied on B
atomic – true for atomic updates of C
alpha – \(\alpha\)
A – A
B – B
beta – \(\beta\)
C – C
loc – Source code location
- Returns:
Instruction
make_gemv#
-
inline inst tinytc::make_gemv(transpose tA, bool atomic, value const &alpha, value const &A, value const &B, value const &beta, value const &C, location const &loc = {})#
Make GEMV instruction.
- Parameters:
tA – Operation applied on A
atomic – true for atomic updates of C
alpha – \(\alpha\)
A – A
B – B
beta – \(\beta\)
C – C
loc – Source code location
- Returns:
Instruction
make_ger#
-
inline inst tinytc::make_ger(bool atomic, value const &alpha, value const &A, value const &B, value const &beta, value const &C, location const &loc = {})#
Make GER instruction.
- Parameters:
atomic – true for atomic updates of C
alpha – \(\alpha\)
A – A
B – B
beta – \(\beta\)
C – C
loc – Source code location
- Returns:
Instruction
make_group_id#
make_group_size#
make_hadamard#
-
inline inst tinytc::make_hadamard(bool atomic, value const &alpha, value const &A, value const &B, value const &beta, value const &C, location const &loc = {})#
Make hadamard instruction.
- Parameters:
atomic – true for atomic updates of C
alpha – \(\alpha\)
A – A
B – B
beta – \(\beta\)
C – C
loc – Source code location
- Returns:
Instruction
make_if#
-
inline inst tinytc::make_if(value const &condition, region const &then, region const &otherwise = region{}, std::vector<scalar_type> const &return_type_list = {}, location const &loc = {})#
Make if condition instruction.
- Parameters:
condition – Condition value (of type bool)
then – Then region
otherwise – Else region
return_type_list – Types of returned values
loc – Source code location
- Returns:
Instruction
make_load#
make_size#
make_store#
make_subview#
-
inline inst tinytc::make_subview(value const &a, std::vector<value> const &offset_list, std::vector<value> const &size_list, location const &loc = {})#
Make subview instruction.
- Parameters:
a – Operand
offset_list – Vector of offsets
size_list – Vector of sizes; initialize with empty value if only offset is required
loc – Source code location
- Returns:
Instruction
make_sum#
-
inline inst tinytc::make_sum(transpose tA, bool atomic, value const &alpha, value const &A, value const &beta, value const &B, location const &loc = {})#
Make sum instruction.
- Parameters:
tA – Operation applied on A
atomic – true for atomic updates of B
alpha – \(\alpha\)
A – A
beta – \(\beta\)
B – B
loc – Source code location
- Returns:
Instruction
make_yield#
Instruction Classes#
inst#
-
class inst : public tinytc::shared_handle<tinytc_inst_t>#
Reference-counting wrapper for tinytc_inst_t.
Program#
Functions
Classes
Program Functions#
make_program#
Program Classes#
prog#
-
class prog : public tinytc::shared_handle<tinytc_prog_t>#
Reference-counting wrapper for tinytc_prog_t.
Public Functions
-
inline void dump() const#
Dump program to stderr.
-
inline void print_to_file(char const *filename) const#
Dump program to file.
- Parameters:
filename – Path to file
-
inline auto print_to_string() const -> unique_handle<char*>#
Dump program to string.
- Returns:
C-string (unique handle)
Create empty (invalid) handle.
Create handle from C handle.
Copy ctor.
Move ctor.
-
inline void dump() const#
program_builder#
-
class program_builder#
Builder for programs.
Region#
Functions
Classes
Region Functions#
make_region#
Region Classes#
region#
-
class region : public tinytc::shared_handle<tinytc_region_t>#
Reference-counting wrapper for tinytc_region_t.
Public Functions
Create empty (invalid) handle.
Create handle from C handle.
Copy ctor.
Move ctor.
region_builder#
-
class region_builder#
Builder for regions.
Public Functions
-
inline auto get_product(location const &loc = {}) -> region#
Returns built product.
- Parameters:
loc – Source code location
- Returns:
Region
-
inline auto add(inst i, std::string const &name = "") -> value#
Add instruction.
- Parameters:
i – Instruction
name – Result name
- Returns:
Value returned by instruction; may be empty
-
inline auto add_multivalued(inst i, std::string const &name = "") -> std::vector<value>#
Add instruction that returns multiple values.
- Parameters:
i – Instruction
name – Result name
- Returns:
Values returned by instruction
-
template<typename F>
inline void for_loop(scalar_type loop_var_ty, value const &from, value const &to, F &&f, std::string const &name = "", location const &loc = {})# Build for-loop with functor f(region_builder&) -> void.
- Template Parameters:
F – Functor type
- Parameters:
loop_var_ty – Type of loop variable
from – Loop variable start
to – Loop variable bound
f – Functor
name – Loop variable name
loc – Source code location
-
template<typename F>
inline void for_loop(scalar_type loop_var_ty, value const &from, value const &to, value const &step, F &&f, std::string const &name = "", location const &loc = {})# Build for-loop with functor f(region_builder&) -> void.
- Template Parameters:
F – Functor type
- Parameters:
loop_var_ty – Type of loop variable
from – Loop variable start
to – Loop variable bound
step – Loop variable step
f – Functor
name – Loop variable name
loc – Source code location
-
template<typename F>
inline void foreach(data_type const &loop_var_ty, value const &from, value const &to, F &&f, std::string const &name = "", location const &loc = {})# Build foreach-loop with functor f(region_builder&) -> void.
- Template Parameters:
F – Functor type
- Parameters:
loop_var_ty – Type of loop variable
from – Loop variable start
to – Loop variable bound
f – functor
name – Loop variable name
loc – Source code location
-
template<typename F>
inline auto if_condition(value const &condition, F &&then, std::vector<scalar_type> const &return_type_list = {}, location const &loc = {}) -> std::vector<value># Build if with functor then(region_builder&) -> void.
- Template Parameters:
F – Functor type
- Parameters:
condition – Condition value
then – Then region functor
return_type_list – Types of returned values
loc – Source code location
- Returns:
Returned values
-
template<typename F, typename G>
inline auto ifelse(value const &condition, F &&then, G &&otherwise, std::vector<scalar_type> const &return_type_list = {}, location const &loc = {}) -> std::vector<value># Build if/else with functors then(region_builder&) -> void and otherwise(region_builder&) -> void.
- Template Parameters:
F – “if” functor type
G – “else” functor type
- Parameters:
condition – If condition
then – “if” functor
otherwise – “else” functor
return_type_list – List of types of returned values
loc – Source code location
- Returns:
Returned values
-
inline auto get_product(location const &loc = {}) -> region#
Value#
Functions
Classes
Value Functions#
make_dynamic(location const&)#
make_imm(float,location const&)#
make_imm(double,scalar_type,location const&)#
-
inline auto tinytc::make_imm(double imm, scalar_type type = scalar_type::f64, location const &loc = {}) -> value#
Make immediate value.
- Parameters:
imm – Float value
type – Type of immediate value
loc – Source code location
- Returns:
Value
make_imm(std::int8_t,location const&)#
make_imm(std::int16_t,location const&)#
make_imm(std::int32_t,location const&)#
make_imm(std::int64_t,scalar_type,location const&)#
-
inline auto tinytc::make_imm(std::int64_t imm, scalar_type type = scalar_type::i64, location const &loc = {}) -> value#
Make immediate value.
- Parameters:
imm – Int value
type – Type of immediate value
loc – Source code location
- Returns:
Value
make_index(std::int32_t,location const&)#
make_index(std::int64_t,location const&)#
make_value(data_type const&,location const&)#
make_value(scalar_type,location const&)#
-
inline auto tinytc::make_value(scalar_type scalar_ty, location const &loc = {}) -> value#
Make value.
- Parameters:
scalar_ty – Scalar type
loc – Source code location
- Returns:
Value
Value Classes#
value#
-
class value : public tinytc::shared_handle<tinytc_value_t>#
Reference-counting wrapper for tinytc_value_t.