Core C-API

Contents

Core C-API#

Common#

Common Definitions#

TINYTC_VERSION_MAJOR#

TINYTC_VERSION_MAJOR 0#

Major version (X.x.x)

TINYTC_VERSION_MINOR#

TINYTC_VERSION_MINOR 4#

Minor version (x.X.x)

TINYTC_VERSION_PATCH#

TINYTC_VERSION_PATCH 0#

Patch version (x.x.X)

TINYTC_VERSION_HASH#

TINYTC_VERSION_HASH "9f0273b"#

Git commit hash.

TINYTC_VERSION_NUMBER_OF_COMMITS_SINCE_RELEASE#

TINYTC_VERSION_NUMBER_OF_COMMITS_SINCE_RELEASE 0#

Number of commits since last tag.

TINYTC_VERSION_DESCRIPTION#

TINYTC_VERSION_DESCRIPTION "v0.4.0-0-9f0273b"#

Version string (vx.x.x-x-x)

Common Enumerations#

tinytc_address_space_t#

enum tinytc_address_space_t#

Address space

Values:

enumerator tinytc_address_space_global = 1#

Global memory.

enumerator tinytc_address_space_local = 2#

Local memory, returned by alloca.

tinytc_bundle_format_t#

enum tinytc_bundle_format_t#

Target binary format

Values:

enumerator tinytc_bundle_format_spirv = 0#

SPIR-V.

enumerator tinytc_bundle_format_native = 1#

Native device binary.

tinytc_checked_flag_t#

enum tinytc_checked_flag_t#

Checked flag.

Checks can be combined by bitwise or, that is,

tinytc_checked_flag_both = tinytc_checked_flag_rows | tinytc_checked_flag_cols tinytc_checked_flag_rows = tinytc_checked_flag_rows | tinytc_checked_flag_none

Values:

enumerator tinytc_checked_flag_none = 0#

Perform no checks.

enumerator tinytc_checked_flag_rows = 1#

Check for out-of-bound rows.

enumerator tinytc_checked_flag_cols = 2#

Check for out-of-bound cols.

enumerator tinytc_checked_flag_both = 3#

Check for out-of-bound rows and cols.

tinytc_comp3_t#

enum tinytc_comp3_t#

Named components of 3d vector

Values:

enumerator tinytc_comp3_x = 0#

.x

enumerator tinytc_comp3_y = 1#

.y

enumerator tinytc_comp3_z = 2#

.z

tinytc_core_feature_flag_t#

enum tinytc_core_feature_flag_t#

Core features that may be optionally enabled

Values:

enumerator tinytc_core_feature_flag_large_register_file = 1#

Request a large register file. On PVC this doubles the number of registers per vector engine but halves the number of available hardware threads. When this feature is activated, the kernel is compiled with the -ze-opt-large-register-file option.

tinytc_intel_gpu_architecture_t#

enum tinytc_intel_gpu_architecture_t#

IP versions for Intel GPUs.

Note: IP versions are extracted from

Values:

enumerator tinytc_intel_gpu_architecture_tgl = 50331648#

Tiger Lake.

enumerator tinytc_intel_gpu_architecture_pvc = 51314688#

Ponte Vecchio.

enumerator tinytc_intel_gpu_architecture_bmg = 83902464#

Battlemage.

tinytc_matrix_use_t#

enum tinytc_matrix_use_t#

Matrix use

Values:

enumerator tinytc_matrix_use_a = 0#

matrix_a

enumerator tinytc_matrix_use_b = 1#

matrix_b

enumerator tinytc_matrix_use_acc = 2#

matrix_acc

tinytc_mem_type_t#

enum tinytc_mem_type_t#

Memory object type

Values:

enumerator tinytc_mem_type_buffer = 0#

Buffer object (e.g. cl_mem)

enumerator tinytc_mem_type_usm_pointer = 1#

Unified shared memory pointer.

enumerator tinytc_mem_type_svm_pointer = 2#

Shared virtual memory pointer.

tinytc_memory_scope_t#

enum tinytc_memory_scope_t#

Memory scope flag

Values:

enumerator tinytc_memory_scope_cross_device = 0#
enumerator tinytc_memory_scope_device = 1#
enumerator tinytc_memory_scope_work_group = 2#
enumerator tinytc_memory_scope_subgroup = 3#

tinytc_memory_semantics_t#

enum tinytc_memory_semantics_t#

Memory semantics

Values:

enumerator tinytc_memory_semantics_relaxed = 0#

Relaxed.

enumerator tinytc_memory_semantics_acquire = 2#

Acquire.

enumerator tinytc_memory_semantics_release = 4#

Release.

enumerator tinytc_memory_semantics_acquire_release = 8#

Acquire and release.

enumerator tinytc_memory_semantics_sequentially_consistent = 16#

Sequentially consistent.

tinytc_optflag_t#

enum tinytc_optflag_t#

Flags for optimizer

Values:

enumerator tinytc_optflag_unsafe_fp_math = 0#

Unsafe floating point math (e.g. 0.0 * x => 0.0)

tinytc_reduce_mode_t#

enum tinytc_reduce_mode_t#

Reduce mode

Values:

enumerator tinytc_reduce_mode_row = 0#

Reduction over rows.

enumerator tinytc_reduce_mode_column = 1#

Reduction over columns.

tinytc_spirv_feature_t#

enum tinytc_spirv_feature_t#

SPIR-V features

Values:

enumerator tinytc_spirv_feature_float16 = 0#

f16 support

enumerator tinytc_spirv_feature_float64 = 1#

f64 support

enumerator tinytc_spirv_feature_int64_atomics = 2#

i64 atomics support

enumerator tinytc_spirv_feature_groups = 3#

work group collectives

enumerator tinytc_spirv_feature_subgroup_dispatch = 4#

subgroup support

enumerator tinytc_spirv_feature_atomic_float16_add_local = 5#

f16 atomic add on local pointer

enumerator tinytc_spirv_feature_atomic_float16_add_global = 6#

f16 atomic add on global pointer

enumerator tinytc_spirv_feature_atomic_float32_add_local = 7#

f32 atomic add on local pointer

enumerator tinytc_spirv_feature_atomic_float32_add_global = 8#

f32 atomic add on global pointer

enumerator tinytc_spirv_feature_atomic_float64_add_local = 9#

f64 atomic add on local pointer

enumerator tinytc_spirv_feature_atomic_float64_add_global = 10#

f64 atomic add on global pointer

enumerator tinytc_spirv_feature_atomic_float16_min_max_local = 11#

f16 atomic min/max on local pointer

enumerator tinytc_spirv_feature_atomic_float16_min_max_global = 12#

f16 atomic min/max on global pointer

enumerator tinytc_spirv_feature_atomic_float32_min_max_local = 13#

f32 atomic min/max on local pointer

enumerator tinytc_spirv_feature_atomic_float32_min_max_global = 14#

f32 atomic min/max on global pointer

enumerator tinytc_spirv_feature_atomic_float64_min_max_local = 15#

f64 atomic min/max on local pointer

enumerator tinytc_spirv_feature_atomic_float64_min_max_global = 16#

f64 atomic minmax on global pointer

enumerator tinytc_spirv_feature_bfloat16_conversion = 17#

bf16 -> f32 and f32 -> bf16 conversion

enumerator tinytc_spirv_feature_subgroup_buffer_block_io = 18#

subgroup block read/write support

tinytc_status_t#

enum tinytc_status_t#

Status codes

Values:

enumerator tinytc_status_success = 0#

Success.

enumerator tinytc_status_bad_alloc = 1#

Bad allocation.

enumerator tinytc_status_invalid_arguments = 2#

Invalid arguments passed to function.

enumerator tinytc_status_out_of_range = 3#

Out of range.

enumerator tinytc_status_runtime_error = 4#

General runtime error.

enumerator tinytc_status_internal_compiler_error = 5#

Internal compiler error.

enumerator tinytc_status_unsupported_subgroup_size = 6#

Device does not support subgroup size.

enumerator tinytc_status_unsupported_work_group_size = 7#

Device does not support work-group size.

enumerator tinytc_status_compilation_error = 8#

Compilation error.

enumerator tinytc_status_file_io_error = 9#

I/O error occured in file operation.

enumerator tinytc_status_parse_error = 10#

Parse error.

enumerator tinytc_status_unavailable_extension = 11#

Required vendor extension is unavailable.

enumerator tinytc_status_unsupported_backend = 12#

Unsupported backend.

enumerator tinytc_status_invalid_kernel_arguments = 13#

Invalid arguments passed to kernel.

enumerator tinytc_status_unsupported_device = 14#

Unsupported device.

enumerator tinytc_status_invalid_core_info = 15#

Invalid core info object (e.g. max work group size is 0 or subgroup sizes vector is empty)

enumerator tinytc_status_unknown_pass_name = 16#

Unknown compiler pass name.

enumerator tinytc_status_not_implemented = 17#

Not implemented.

enumerator tinytc_status_compute_runtime_error = 18#

Error occured in compute runtime.

enumerator tinytc_status_ir_out_of_bounds = 256#

Argument is out of bounds.

enumerator tinytc_status_ir_invalid_shape = 257#

Invalid shape.

enumerator tinytc_status_ir_incompatible_shapes = 258#

Incompatible tensor shapes.

enumerator tinytc_status_ir_shape_stride_mismatch = 259#

Dimension of shape and stride must match.

enumerator tinytc_status_ir_number_mismatch = 260#

Number type mismatch.

enumerator tinytc_status_ir_invalid_number_of_indices = 261#

Number of indices must match memref order or must be 1 for group types.

enumerator tinytc_status_ir_expected_boolean = 262#

Expected boolean type.

enumerator tinytc_status_ir_expected_number = 263#

Expected number type.

enumerator tinytc_status_ir_expected_int = 264#

Expected integer type.

enumerator tinytc_status_ir_expected_float = 265#

Expected floating point type.

enumerator tinytc_status_ir_expected_complex = 266#

Expected complex type.

enumerator tinytc_status_ir_expected_i32 = 267#

Expected i32 type.

enumerator tinytc_status_ir_expected_index = 268#

Expected index type.

enumerator tinytc_status_ir_expected_coopmatrix = 269#

Expected coopmatrix type.

enumerator tinytc_status_ir_expected_coopmatrix_or_number = 270#

Expected coopmatrix or number type.

enumerator tinytc_status_ir_expected_coopmatrix_number_or_boolean = 271#

Expected coopmatrix type, number type, or boolean type.

enumerator tinytc_status_ir_expected_memref = 272#

Expected memref type.

enumerator tinytc_status_ir_expected_memref_or_number = 273#

Expected memref or number type.

enumerator tinytc_status_ir_expected_memref_or_group = 274#

Expected memref or group type.

enumerator tinytc_status_ir_expected_memref_order_0 = 275#

Expected memref of order 0 (scalar)

enumerator tinytc_status_ir_expected_memref_order_1 = 276#

Expected memref of order 1 (vector)

enumerator tinytc_status_ir_expected_memref_order_2 = 277#

Expected memref of order 2 (matrix)

enumerator tinytc_status_ir_expected_memref_order_0_or_1 = 278#

Expected memref of order 0 or 1 (scalar or vector)

enumerator tinytc_status_ir_expected_memref_order_1_or_2 = 279#

Expected memref of order 1 or 2 (vector or matrix)

enumerator tinytc_status_ir_expected_memref_order_0_1_or_2 = 280#

Expected memref of order 0, 1, or 2 (scalar, vector, or matrix)

enumerator tinytc_status_ir_unexpected_yield = 281#

Yield encountered in non-yielding region.

enumerator tinytc_status_ir_yield_mismatch = 282#

values yielded by region or the types are different

Number of yielded values does not match number of

enumerator tinytc_status_ir_subview_mismatch = 283#

Number of dynamic offsets and sizes must match number of dynamic operands.

enumerator tinytc_status_ir_invalid_slice = 284#

Static offset and size must be non-negative or dynamic (?)

enumerator tinytc_status_ir_expand_shape_order_too_small = 285#

Expand shape must have at least 2 entries.

enumerator tinytc_status_ir_expand_shape_mismatch = 286#

Number of dynamic expand shape operands must equal number of dynamic modes in static expand shape

enumerator tinytc_status_ir_collective_called_from_spmd = 287#

Collective instruction must not be called from SPMD region.

enumerator tinytc_status_ir_fp_unsupported = 288#

Floating point type unsupported by instruction.

enumerator tinytc_status_ir_spmd_called_from_collective = 289#

SPMD instruction must not be called from collective region.

enumerator tinytc_status_ir_expected_local_address_space = 290#

Expected memref with local address space.

enumerator tinytc_status_ir_expected_global_address_space = 291#

Expected memref with global address space.

enumerator tinytc_status_ir_address_space_mismatch = 292#

Address space must match.

enumerator tinytc_status_ir_invalid_offset = 293#

Offset must be non-negative or dynamic.

enumerator tinytc_status_ir_int_unsupported = 294#

Instruction does not support int type.

enumerator tinytc_status_ir_boolean_unsupported = 295#

Instruction does not support boolean type.

enumerator tinytc_status_ir_complex_unsupported = 296#

Instruction does not support complex type.

enumerator tinytc_status_ir_coopmatrix_unsupported = 297#

Instruction does not support coopmatrix type.

enumerator tinytc_status_ir_forbidden_cast = 298#

Forbidden cast.

enumerator tinytc_status_ir_invalid_beta = 299#

beta must be constant and 0 or 1 for atomic linear algebra operations

enumerator tinytc_status_ir_init_return_mismatch = 300#

The number or types of the initial values does not match the return type list.

enumerator tinytc_status_ir_invalid_matrix_use = 301#

Operands have invalid matrix use.

enumerator tinytc_status_ir_unsupported_coopmatrix_shape = 302#

Unsupported coopmatrix shape for the combination of Number type, matrix use, and target architecture

enumerator tinytc_status_ir_forbidden_promotion = 303#

Number type promotion is forbidden.

enumerator tinytc_status_ir_constant_mismatch = 304#

Type of constant does not match type or returned value.

enumerator tinytc_status_ir_insufficient_alignment = 305#

Pointer does not satisfy minimum alignment requirements.

enumerator tinytc_status_ir_must_have_yield = 306#

Last instruction of region that returns values must be yield.

enumerator tinytc_status_ir_yield_in_else_branch_missing = 307#

Else-branch must have yield instruction if then-branch has yield instruction.

enumerator tinytc_status_ir_from_to_mismatch = 308#

length(from) != length(to)

enumerator tinytc_status_ir_from_tile_shape_mismatch = 309#

length(from) != length(tile_shape)

enumerator tinytc_status_ir_operand_type_must_match_return_type = 310#

Operand type must match return type.

enumerator tinytc_status_ir_invalid_stride = 311#

Invalid stride.

enumerator tinytc_status_ir_init_return_type_mismatch = 312#

Type of initializer does not match return type or the number of return types is not equal the number of initializers

enumerator tinytc_status_ir_value_still_has_uses = 313#

A value shall be erased that still has uses.

enumerator tinytc_status_ir_expected_array_attribute = 320#

Expected array attribute.

enumerator tinytc_status_ir_expected_boolean_attribute = 321#

Expected boolean attribute.

enumerator tinytc_status_ir_expected_dictionary_attribute = 322#

Expected dictionary attribute.

enumerator tinytc_status_ir_expected_integer_attribute = 323#

Expected integer attribute.

enumerator tinytc_status_ir_expected_string_attribute = 324#

Expected string attribute.

enumerator tinytc_status_ir_duplicate_key_in_dictionary = 325#

Duplicate key detected in list of named attributes.

enumerator tinytc_status_ir_unexpected_array_attribute_size = 326#

Unexpected array size.

enumerator tinytc_status_ir_expected_non_scalar_memref = 336#

Expected memref of dimension greater or equal than 1.

enumerator tinytc_status_ir_complex_number_type_unsupported = 337#

Complex number type not supported.

enumerator tinytc_status_ir_tile_shape0_not_multiple_of_sgs = 338#

Tile shape 0 is not a multiple of the subgroup size.

enumerator tinytc_status_ir_division_by_zero = 339#

Division by zero detected.

enumerator tinytc_status_spirv_forbidden_forward_declaration = 4096#

Forward declaration of id is forbidden.

enumerator tinytc_status_spirv_undefined_value = 4097#

Undefined SPIR-V value.

enumerator tinytc_status_spirv_missing_dope_vector = 4098#

Dope vector missing.

enumerator tinytc_status_spirv_unsupported_atomic_data_type = 4099#

Atomic data type unsupported by SPIR-V.

enumerator tinytc_status_spirv_required_feature_unavailable = 4100#

A required SPIR-V feature is unavailable.

enumerator tinytc_status_unknown = 2147483647#

Unknown status code.

tinytc_support_level_t#

enum tinytc_support_level_t#

Support level of a device

Values:

enumerator tinytc_support_level_none = 0#

Device is unsupported (e.g. subgroups feature missing in OpenCL-C)

enumerator tinytc_support_level_basic = 1#

Device provides necessary features but is not well tested.

enumerator tinytc_support_level_tuned = 2#

Device provides necessary features and is well tested.

tinytc_transpose_t#

enum tinytc_transpose_t#

Transpose

Values:

enumerator tinytc_transpose_N = 0#

n

enumerator tinytc_transpose_T = 1#

t

Common Functions#

tinytc_address_space_to_string#

char const *tinytc_address_space_to_string(tinytc_address_space_t val)#

Convert address_space to string.

tinytc_bundle_format_to_string#

char const *tinytc_bundle_format_to_string(tinytc_bundle_format_t val)#

Convert bundle_format to string.

tinytc_checked_flag_to_string#

char const *tinytc_checked_flag_to_string(tinytc_checked_flag_t val)#

Convert checked_flag to string.

tinytc_comp3_to_string#

char const *tinytc_comp3_to_string(tinytc_comp3_t val)#

Convert comp3 to string.

tinytc_core_feature_flag_to_string#

char const *tinytc_core_feature_flag_to_string(tinytc_core_feature_flag_t val)#

Convert core_feature_flag to string.

tinytc_intel_gpu_architecture_to_string#

char const *tinytc_intel_gpu_architecture_to_string(tinytc_intel_gpu_architecture_t val)#

Convert intel_gpu_architecture to string.

tinytc_matrix_use_to_string#

char const *tinytc_matrix_use_to_string(tinytc_matrix_use_t val)#

Convert matrix_use to string.

tinytc_mem_type_to_string#

char const *tinytc_mem_type_to_string(tinytc_mem_type_t val)#

Convert mem_type to string.

tinytc_memory_scope_to_string#

char const *tinytc_memory_scope_to_string(tinytc_memory_scope_t val)#

Convert memory_scope to string.

tinytc_memory_semantics_to_string#

char const *tinytc_memory_semantics_to_string(tinytc_memory_semantics_t val)#

Convert memory_semantics to string.

tinytc_optflag_to_string#

char const *tinytc_optflag_to_string(tinytc_optflag_t val)#

Convert optflag to string.

tinytc_reduce_mode_to_string#

char const *tinytc_reduce_mode_to_string(tinytc_reduce_mode_t val)#

Convert reduce_mode to string.

tinytc_spirv_feature_to_string#

char const *tinytc_spirv_feature_to_string(tinytc_spirv_feature_t val)#

Convert spirv_feature to string.

tinytc_status_to_string#

char const *tinytc_status_to_string(tinytc_status_t val)#

Convert status to string.

tinytc_string_destroy#

void tinytc_string_destroy(char *str)#

Delete a (non-const) string returned from tinytc API.

Parameters:
  • str – [in] string

tinytc_support_level_to_string#

char const *tinytc_support_level_to_string(tinytc_support_level_t val)#

Convert support_level to string.

tinytc_transpose_to_string#

char const *tinytc_transpose_to_string(tinytc_transpose_t val)#

Convert transpose to string.

Common Typedefs#

tinytc_address_spaces_t#

typedef uint32_t tinytc_address_spaces_t#

Type for combination of address spaces.

tinytc_binary_t#

typedef struct tinytc_binary *tinytc_binary_t#

binary handle

tinytc_bool_t#

typedef uint8_t tinytc_bool_t#

Bool type {0,1}.

tinytc_core_info_t#

typedef struct tinytc_core_info *tinytc_core_info_t#

core_info handle

tinytc_prog_t#

typedef struct tinytc_prog *tinytc_prog_t#

prog handle

tinytc_recipe_t#

typedef struct tinytc_recipe *tinytc_recipe_t#

recipe handle

tinytc_recipe_handler_t#

typedef struct tinytc_recipe_handler *tinytc_recipe_handler_t#

recipe_handler handle

tinytc_spv_mod_t#

typedef struct tinytc_spv_mod *tinytc_spv_mod_t#

spv_mod handle

tinytc_compiler_context_t#

typedef struct tinytc_compiler_context *tinytc_compiler_context_t#

compiler_context handle

const_tinytc_binary_t#

typedef const struct tinytc_binary *const_tinytc_binary_t#

const binary handle

const_tinytc_core_info_t#

typedef const struct tinytc_core_info *const_tinytc_core_info_t#

const core_info handle

const_tinytc_prog_t#

typedef const struct tinytc_prog *const_tinytc_prog_t#

const prog handle

const_tinytc_recipe_t#

typedef const struct tinytc_recipe *const_tinytc_recipe_t#

const recipe handle

const_tinytc_recipe_handler_t#

typedef const struct tinytc_recipe_handler *const_tinytc_recipe_handler_t#

const recipe_handler handle

const_tinytc_spv_mod_t#

typedef const struct tinytc_spv_mod *const_tinytc_spv_mod_t#

const spv_mod handle

const_tinytc_compiler_context_t#

typedef const struct tinytc_compiler_context *const_tinytc_compiler_context_t#

const compiler_context handle

tinytc_error_reporter_t#

typedef void (*tinytc_error_reporter_t)(char const *what, const tinytc_location_t *location, void *user_data)#

Signature for error reporting callback.

Param what:

Error description

Param location:

Source code location

Param user_data:

user data that is passed on to callback

Binary#

Binary Functions#

tinytc_binary_create#

tinytc_status_t tinytc_binary_create(tinytc_binary_t *bin, tinytc_compiler_context_t ctx, tinytc_bundle_format_t format, size_t data_size, uint8_t const *data, tinytc_core_feature_flags_t core_features)#

Create binary.

Parameters:
  • bin – [out] pointer to binary object

  • ctx – [in] compiler context

  • format – [in] Bundle format (SPIR-V or Native)

  • data_size – [in] Size of data in bytes

  • data – [in][range(0, data_size)] Binary data; data is copied

  • core_features – [in][optional] requested core features; must be 0 (default) or a combination of tinytc_core_feature_flag_t

Returns:

tinytc_status_success on success and error otherwise

tinytc_binary_get_compiler_context#

tinytc_status_t tinytc_binary_get_compiler_context(const_tinytc_binary_t bin, tinytc_compiler_context_t *ctx)#

Get context object from binary object.

The reference count of the context remains unchanged.

Parameters:
  • bin – [in] binary object

  • ctx – [out] pointer to context object

Returns:

tinytc_status_success on success and error otherwise

tinytc_binary_get_core_features#

tinytc_status_t tinytc_binary_get_core_features(const_tinytc_binary_t bin, tinytc_core_feature_flags_t *core_features)#

Get requested core features.

Parameters:
  • bin – [in] binary object

  • core_features – [out] core features

Returns:

tinytc_status_success on success and error otherwise

tinytc_binary_get_raw#

tinytc_status_t tinytc_binary_get_raw(const_tinytc_binary_t bin, tinytc_bundle_format_t *format, size_t *data_size, uint8_t const **data)#

Get raw binary data.

Parameters:
  • bin – [in] binary object

  • format – [out] binary format

  • data_size – [out] size of data

  • data – [out] data array; returned pointer is invalidated if the binary object is deleted

Returns:

tinytc_status_success on success and error otherwise

tinytc_binary_release#

tinytc_status_t tinytc_binary_release(tinytc_binary_t bin)#

Release binary object.

Decreases reference count by 1, free memory if reference count is 0.

Parameters:
  • bin – [inout] binary object

Returns:

tinytc_status_success on success and error otherwise

tinytc_binary_retain#

tinytc_status_t tinytc_binary_retain(tinytc_binary_t bin)#

Increase reference count of binary object by 1.

Parameters:
  • bin – [inout] binary object

Returns:

tinytc_status_success on success and error otherwise

Compiler#

Compiler Functions#

tinytc_list_function_passes#

tinytc_status_t tinytc_list_function_passes(size_t *names_size, char const *const **names)#

List function passes.

Parameters:
  • names_size – [out] pointer to number of function pass names

  • names – [out][range(0,names_size)] pointer to array of C-strings; array owned by tinytc

Returns:

tinytc_prog_compile_to_spirv#

tinytc_status_t tinytc_prog_compile_to_spirv(tinytc_spv_mod_t *mod, tinytc_prog_t prg, const_tinytc_core_info_t info)#

Compile tensor language to SPIR-V.

Parameters:
  • mod – [out] pointer to the SPIR-V module created

  • prg – [inout] tensor program; modified as compiler passes are run

  • info – [in] core info object

Returns:

tinytc_status_success on success and error otherwise

tinytc_prog_compile_to_spirv_and_assemble#

tinytc_status_t tinytc_prog_compile_to_spirv_and_assemble(tinytc_binary_t *bin, tinytc_prog_t prg, const_tinytc_core_info_t info)#

Compiler tensor language to SPIR-V and assemble.

Parameters:
  • bin – [out] pointer to the binary object created

  • prg – [inout] tensor program; modified as compiler passes are run

  • info – [in] core info object

Returns:

tinytc_status_success on success and error otherwise

tinytc_run_function_pass#

tinytc_status_t tinytc_run_function_pass(char const *pass_name, tinytc_prog_t prg, const_tinytc_core_info_t info)#

Run a function pass on every function of a program.

Parameters:
  • pass_name – [in] name of function pass; cf. tinytc_list_function_passes

  • prg – [inout] tensor program; modified as compiler pass is run

  • info – [in][optional] core info object; might be nullptr if core info is not required for pass

Returns:

tinytc_status_success on success and error otherwise

tinytc_spirv_assemble#

tinytc_status_t tinytc_spirv_assemble(tinytc_binary_t *bin, const_tinytc_spv_mod_t mod)#

Assemble SPIR-V module.

Parameters:
  • bin – [out] pointer to the binary object created

  • mod – [in] SPIR-V module

Returns:

tinytc_status_success on success and error otherwise

Compiler Context#

Compiler Context Functions#

tinytc_compiler_context_create#

tinytc_status_t tinytc_compiler_context_create(tinytc_compiler_context_t *ctx)#

Create context.

The context stores the tensor language source and reports enhaces error messages with source code context. Moreover, the context caches data such as types and constants.

Parameters:
  • ctx – [out] pointer to the context object created

Returns:

tinytc_status_success on success and error otherwise

tinytc_compiler_context_add_source#

tinytc_status_t tinytc_compiler_context_add_source(tinytc_compiler_context_t ctx, char const *name, char const *text, int32_t *source_id)#

Add source context.

Manually add a source file to the context that can be referenced in a tinytc_location. Useful to enhance error messages when using the builder methods and classes.

Parameters:
  • ctx – [in] context object

  • name – [in] source name

  • text – [in] source text

  • source_id – [out] pointer to source id

Returns:

tinytc_status_success on success and error otherwise

tinytc_compiler_context_set_error_reporter#

tinytc_status_t tinytc_compiler_context_set_error_reporter(tinytc_compiler_context_t ctx, tinytc_error_reporter_t reporter, void *user_data)#

Set error reporter.

Error reporting function that is called whenever an error occurs in the parser or the builder.

Parameters:
  • ctx – [inout] context object

  • reporter – [in] error reporting callback; set to nullptr to disable reporting

  • user_data – [in][optional] pointer to user data that is passed to the callback; can be nullptr

Returns:

tinytc_status_success on success and error otherwise

tinytc_compiler_context_set_optimization_flag#

tinytc_status_t tinytc_compiler_context_set_optimization_flag(tinytc_compiler_context_t ctx, tinytc_optflag_t flag, int32_t state)#

Sets an optimization flag.

The state can be 0 (disabled), 1 (enabled), or -1 (use default according to optimization level).

Parameters:
  • ctx – [inout] context object

  • flag – [in] optimization flag

  • state – [in] flag state

Returns:

tinytc_status_success on success and error otherwise

tinytc_compiler_context_set_optimization_level#

tinytc_status_t tinytc_compiler_context_set_optimization_level(tinytc_compiler_context_t ctx, int32_t level)#

Set optimization level (from 0 to 2)

Parameters:
  • ctx – [inout] context object

  • level – [in] optimization level

Returns:

tinytc_status_success on success and error otherwise

tinytc_compiler_context_report_error#

tinytc_status_t tinytc_compiler_context_report_error(tinytc_compiler_context_t ctx, const tinytc_location_t *location, char const *what)#

Report an error and augment the error with source context.

Parameters:
  • ctx – [in] context object

  • location – [in] source location

  • what – [in] error description

Returns:

tinytc_status_success on success and error otherwise

tinytc_compiler_context_release#

tinytc_status_t tinytc_compiler_context_release(tinytc_compiler_context_t obj)#

Release context object.

Decreases reference count by 1, free memory if reference count is 0.

Parameters:
  • obj – [inout] context object

Returns:

tinytc_status_success on success and error otherwise

tinytc_compiler_context_retain#

tinytc_status_t tinytc_compiler_context_retain(tinytc_compiler_context_t obj)#

Increase reference count of context object by 1.

Parameters:
  • obj – [inout] context object

Returns:

tinytc_status_success on success and error otherwise

Device Info#

Device Info Functions#

tinytc_core_info_generic_create#

tinytc_status_t tinytc_core_info_generic_create(tinytc_core_info_t *info, int32_t register_space, int32_t max_work_group_size, size_t sgs_size, int32_t const *sgs)#

Create core_info for a generic GPUs.

Parameters:
  • info – [out] pointer to the core_info object created

  • register_space – [in] Size of register file per subgroup in bytes

  • max_work_group_size – [in] Maximum size of local work group

  • sgs_size – [in] Length of sgs array

  • sgs – [in] Allowed subgroup sizes

Returns:

tinytc_status_success on success and error otherwise

tinytc_core_info_get_core_features#

tinytc_status_t tinytc_core_info_get_core_features(const_tinytc_core_info_t info, tinytc_core_feature_flags_t *flags)#

Get core features.

Parameters:
  • info – [in] core info object

  • flags – [out] pointer to core feature flags

Returns:

tinytc_status_success on success and error otherwise

tinytc_core_info_get_default_alignment#

tinytc_status_t tinytc_core_info_get_default_alignment(const_tinytc_core_info_t info, int32_t *alignment)#

Get default memref alignment.

Parameters:
  • info – [in] Core info

  • alignment – [out] pointer to alignment in bytes

Returns:

tinytc_status_success on success and error otherwise

tinytc_core_info_get_register_space#

tinytc_status_t tinytc_core_info_get_register_space(const_tinytc_core_info_t info, int32_t *space)#

Returns register space per subgroup in bytes.

Parameters:
  • info – [in] core info object

  • space – [out] pointer to register space

Returns:

tinytc_status_success on success and error otherwise

tinytc_core_info_get_subgroup_sizes#

tinytc_status_t tinytc_core_info_get_subgroup_sizes(const_tinytc_core_info_t info, size_t *sgs_size, int32_t const **sgs)#

Returns available subgroup sizes.

Parameters:
  • info – [in] core info object

  • sgs_size – [out] pointer to number of subgroup sizes

  • sgs – [out] pointer to subgroup size array; pointer is invalidated when core info is deleted

Returns:

tinytc_status_success on success and error otherwise

tinytc_core_info_have_spirv_feature#

tinytc_status_t tinytc_core_info_have_spirv_feature(const_tinytc_core_info_t info, tinytc_spirv_feature_t feature, tinytc_bool_t *available)#

Get SPIR-V feature.

Parameters:
  • info – [in] core info object

  • feature – [in] SPIR-V feature

  • available – [out] Writes true to available if feature is available and false otherwise

Returns:

tinytc_status_success on success and error otherwise

tinytc_core_info_intel_create#

tinytc_status_t tinytc_core_info_intel_create(tinytc_core_info_t *info, uint32_t ip_version, int32_t num_eus_per_subslice, int32_t num_threads_per_eu, size_t sgs_size, int32_t const *sgs)#

Create core_info for Intel GPUs.

Parameters:
  • info – [out] pointer to the core_info object created

  • ip_version – [in] IP version of architecture

  • num_eus_per_subslice – [in] Number of Execution Units (Xe Vector Engines) per subslice (Xe Core)

  • num_threads_per_eu – [in] Number of threads per Execution Unit (Xe Vector Engine)

  • sgs_size – [in] Length of sgs array

  • sgs – [in] Allowed subgroup sizes

Returns:

tinytc_status_success on success and error otherwise

tinytc_core_info_intel_create_from_arch#

tinytc_status_t tinytc_core_info_intel_create_from_arch(tinytc_core_info_t *info, tinytc_intel_gpu_architecture_t arch)#

Look up core info for Intel GPU architecture.

Parameters:
  • info – [out] pointer to the core_info object created

  • arch – [in] IP version

Returns:

tinytc_status_success on success and error otherwise

tinytc_core_info_intel_create_from_name#

tinytc_status_t tinytc_core_info_intel_create_from_name(tinytc_core_info_t *info, char const *name)#

Look up core info for Intel GPU architecture.

Parameters:
  • info – [out] pointer to the core_info object created

  • name – [in] architecture name

Returns:

tinytc_status_success on success and error otherwise

tinytc_core_info_release#

tinytc_status_t tinytc_core_info_release(tinytc_core_info_t obj)#

Release core info object.

Decreases reference count by 1, free memory if reference count is 0.

Parameters:
  • obj – [inout] core info object

Returns:

tinytc_status_success on success and error otherwise

tinytc_core_info_retain#

tinytc_status_t tinytc_core_info_retain(tinytc_core_info_t obj)#

Increase reference count of core info object by 1.

Parameters:
  • obj – [inout] core info object

Returns:

tinytc_status_success on success and error otherwise

tinytc_core_info_set_core_features#

tinytc_status_t tinytc_core_info_set_core_features(tinytc_core_info_t info, tinytc_core_feature_flags_t flags)#

Set core features.

Parameters:
Returns:

tinytc_status_success on success and error otherwise

tinytc_core_info_set_default_alignment#

tinytc_status_t tinytc_core_info_set_default_alignment(tinytc_core_info_t info, int32_t alignment)#

Set default memref alignment.

Parameters:
  • info – [inout] Core info

  • alignment – [in] alignment in bytes

Returns:

tinytc_status_success on success and error otherwise

tinytc_core_info_set_spirv_feature#

tinytc_status_t tinytc_core_info_set_spirv_feature(tinytc_core_info_t info, tinytc_spirv_feature_t feature, tinytc_bool_t available)#

Set SPIR-V feature.

Parameters:
  • info – [inout] core info object

  • feature – [in] SPIR-V feature

  • available – [in] Set to true if feature is available and false otherwise

Returns:

tinytc_status_success on success and error otherwise

Device Info Typedefs#

tinytc_core_feature_flags_t#

typedef uint32_t tinytc_core_feature_flags_t#

Type for combination of core feature flags.

FP math#

FP math Functions#

tinytc_f32_to_bf16_as_ui16#

uint16_t tinytc_f32_to_bf16_as_ui16(float x)#

Convert f32 number to bf16 number (represented as ushort)

Parameters:
  • x – f32 number

Returns:

bf16 number

tinytc_f32_to_f16_as_ui16#

uint16_t tinytc_f32_to_f16_as_ui16(float x)#

Convert f32 number to f16 number (represented as ushort)

Parameters:
  • x – f32 number

Returns:

f16 number

tinytc_f16_as_ui16_to_f32#

float tinytc_f16_as_ui16_to_f32(uint16_t x)#

Convert f16 number (represented as ushort) to f32 number.

Parameters:
  • x – f16 number

Returns:

f32 number

tinytc_bf16_as_ui16_to_f32#

float tinytc_bf16_as_ui16_to_f32(uint16_t x)#

Convert bf16 number (represented as ushort) to f32 number.

Parameters:
  • x – bf16 number

Returns:

f32 number

Parser#

Parser Functions#

tinytc_parse_file#

tinytc_status_t tinytc_parse_file(tinytc_prog_t *prg, char const *filename, tinytc_compiler_context_t ctx)#

Parser tensor language source file and create prog.

Parameters:
  • prg – [out] pointer to prog object created

  • filename – [in] path to source file

  • ctx – [inout][optional] context object; a new context is created if ctx is nullptr

Returns:

tinytc_status_success on success and error otherwise

tinytc_parse_stdin#

tinytc_status_t tinytc_parse_stdin(tinytc_prog_t *prg, tinytc_compiler_context_t ctx)#

Parser tensor language source from stdin and create prog.

Parameters:
  • prg – [out] pointer to prog object created

  • ctx – [inout][optional] context object; a new context is created if ctx is nullptr

Returns:

tinytc_status_success on success and error otherwise

tinytc_parse_string#

tinytc_status_t tinytc_parse_string(tinytc_prog_t *prg, size_t source_size, char const *source, tinytc_compiler_context_t ctx)#

Parser tensor language source from string and create prog.

Parameters:
  • prg – [out] pointer to prog object created

  • source_size – [in] length of source string

  • source – [in] source string

  • ctx – [inout][optional] context object; a new context is created if ctx is nullptr

Returns:

tinytc_status_success on success and error otherwise

Program#

Program Functions#

tinytc_prog_dump#

tinytc_status_t tinytc_prog_dump(tinytc_prog_t prg)#

Dump program to stderr.

Parameters:
  • prg – [in] program object

Returns:

tinytc_status_success on success and error otherwise

tinytc_prog_get_compiler_context#

tinytc_status_t tinytc_prog_get_compiler_context(const_tinytc_prog_t prg, tinytc_compiler_context_t *ctx)#

Get context object from program object.

The reference count of the context remains unchanged.

Parameters:
  • prg – [in] program object

  • ctx – [out] pointer to context object

Returns:

tinytc_status_success on success and error otherwise

tinytc_prog_print_to_file#

tinytc_status_t tinytc_prog_print_to_file(tinytc_prog_t prg, char const *filename)#

Print program to file.

Parameters:
  • prg – [in] program object

  • filename – [in] filename

Returns:

tinytc_status_success on success and error otherwise

tinytc_prog_print_to_string#

tinytc_status_t tinytc_prog_print_to_string(tinytc_prog_t prg, char **str)#

Print program to string.

The user is responsible to dispose the string with tinytc_string_destroy.

Parameters:
  • prg – [in] program object

  • str – [out] pointer to string

Returns:

tinytc_status_success on success and error otherwise

tinytc_prog_release#

tinytc_status_t tinytc_prog_release(tinytc_prog_t prg)#

Release program object.

Decreases reference count by 1, free memory if reference count is 0.

Parameters:
  • prg – [inout] program object

Returns:

tinytc_status_success on success and error otherwise

tinytc_prog_retain#

tinytc_status_t tinytc_prog_retain(tinytc_prog_t prg)#

Increase reference count of program object by 1.

Parameters:
  • prg – [inout] program object

Returns:

tinytc_status_success on success and error otherwise

SPIR-V module#

SPIR-V module Functions#

tinytc_spv_mod_dump#

tinytc_status_t tinytc_spv_mod_dump(const_tinytc_spv_mod_t mod)#

Dump SPIR-V module to stderr.

Parameters:
  • mod – [in] module

Returns:

tinytc_status_success on success and error otherwise

tinytc_spv_mod_print_to_file#

tinytc_status_t tinytc_spv_mod_print_to_file(const_tinytc_spv_mod_t mod, char const *filename)#

Print SPIR-V module to file.

Parameters:
  • mod – [in] module

  • filename – [in] filename

Returns:

tinytc_status_success on success and error otherwise

tinytc_spv_mod_print_to_string#

tinytc_status_t tinytc_spv_mod_print_to_string(const_tinytc_spv_mod_t mod, char **str)#

Print SPIR-V module to string.

The user is responsible to dispose the string with tinytc_string_destroy.

Parameters:
  • mod – [in] module

  • str – [out] pointer to string

Returns:

tinytc_status_success on success and error otherwise

tinytc_spv_mod_release#

tinytc_status_t tinytc_spv_mod_release(tinytc_spv_mod_t mod)#

Release SPIR-V module.

Decreases reference count by 1, free memory if reference count is 0.

Parameters:
  • mod – [inout] SPIR-V module

Returns:

tinytc_status_success on success and error otherwise

tinytc_spv_mod_retain#

tinytc_status_t tinytc_spv_mod_retain(tinytc_spv_mod_t mod)#

Increase reference count of SPIR-V module by 1.

Parameters:
  • mod – [inout] SPIR-V module

Returns:

tinytc_status_success on success and error otherwise