use std::collections::HashMap;
use inkwell::context::Context;
use inkwell::execution_engine::ExecutionEngine;
use inkwell::module::Module as InkwellModule;
use inkwell::AddressSpace;
use crate::compiler::ast::Type;
use tl_runtime as runtime;
use tl_cpu::ffi as cpu_ffi;
unsafe extern "C" {
fn malloc(size: usize) -> *mut std::ffi::c_void;
fn calloc(count: usize, size: usize) -> *mut std::ffi::c_void;
fn realloc(ptr: *mut std::ffi::c_void, size: usize) -> *mut std::ffi::c_void;
fn free(ptr: *mut std::ffi::c_void);
fn abort();
}
pub fn declare_runtime_functions<'ctx>(
context: &'ctx Context,
module: &InkwellModule<'ctx>,
execution_engine: &ExecutionEngine<'ctx>,
ret_types: &mut HashMap<String, Type>,
) {
#[unsafe(no_mangle)]
extern "C" fn tl_debug_print_ptr(name: *const i8, ptr: *const i8) {
let name_str = unsafe { std::ffi::CStr::from_ptr(name).to_string_lossy() };
eprintln!("Cleanup: {} Ptr: {:p}", name_str, ptr);
}
let is_cpu = std::env::var("TL_DEVICE").map_or(false, |d| d == "cpu");
let i64_type = context.i64_type(); let i32_type = context.i32_type();
let f32_type = context.f32_type();
let f32_ptr = context.ptr_type(AddressSpace::default());
let usize_ptr = context.ptr_type(AddressSpace::default());
let i64_ptr = context.ptr_type(AddressSpace::default());
let void_ptr = context.ptr_type(AddressSpace::default()); let void_type = context.void_type();
let i8_ptr = context.ptr_type(AddressSpace::default());
let c_tensor_result_type = context.struct_type(
&[
void_ptr.into(), i8_ptr.into(), i32_type.into(), i8_ptr.into(), i32_type.into(), i32_type.into(), ],
false,
);
let add_fn = |name: &str, ty: inkwell::types::FunctionType<'ctx>| {
if module.get_function(name).is_none() {
module.add_function(name, ty, None);
}
};
let add_fn_typed = |name: &str, ty: inkwell::types::FunctionType<'ctx>, ret_type: Type, ret_types: &mut HashMap<String, Type>| {
if module.get_function(name).is_none() {
module.add_function(name, ty, None);
}
ret_types.insert(name.to_string(), ret_type);
};
let print_i64_type = void_type.fn_type(&[i64_type.into()], false);
add_fn("tl_print_i64", print_i64_type.clone());
add_fn("tl_display_i64", print_i64_type);
let print_i32_type = void_type.fn_type(&[i32_type.into()], false);
add_fn("tl_print_i32", print_i32_type.clone());
add_fn("tl_display_i32", print_i32_type);
let print_char_type = void_type.fn_type(&[i32_type.into()], false);
add_fn("tl_print_char", print_char_type.clone());
add_fn("tl_display_char", print_char_type);
let print_f32_type = void_type.fn_type(&[f32_type.into()], false);
add_fn("tl_print_f32", print_f32_type.clone());
add_fn("tl_display_f32", print_f32_type);
let f64_type = context.f64_type();
let print_f64_type = void_type.fn_type(&[f64_type.into()], false);
add_fn("tl_print_f64", print_f64_type.clone());
add_fn("tl_display_f64", print_f64_type);
let print_bool_type = void_type.fn_type(&[context.bool_type().into()], false);
add_fn("tl_print_bool", print_bool_type.clone());
add_fn("tl_display_bool", print_bool_type);
let f32_unary_type = f32_type.fn_type(&[f32_type.into()], false);
let f32_binary_type = f32_type.fn_type(&[f32_type.into(), f32_type.into()], false);
let f32_powi_type = f32_type.fn_type(&[f32_type.into(), i64_type.into()], false);
let f64_unary_type = f64_type.fn_type(&[f64_type.into()], false);
let f64_binary_type = f64_type.fn_type(&[f64_type.into(), f64_type.into()], false);
let f64_powi_type = f64_type.fn_type(&[f64_type.into(), i64_type.into()], false);
let i64_unary_type = i64_type.fn_type(&[i64_type.into()], false);
let i64_binary_type = i64_type.fn_type(&[i64_type.into(), i64_type.into()], false);
let i32_unary_type = i32_type.fn_type(&[i32_type.into()], false);
let i32_binary_type = i32_type.fn_type(&[i32_type.into(), i32_type.into()], false);
let i64_bool_unary_type = context.bool_type().fn_type(&[i64_type.into()], false);
let i32_bool_unary_type = context.bool_type().fn_type(&[i32_type.into()], false);
let f32_unary_methods = [
"abs",
"acos",
"acosh",
"asin",
"asinh",
"atan",
"atanh",
"cbrt",
"ceil",
"cos",
"cosh",
"exp",
"exp2",
"exp_m1",
"floor",
"fract",
"ln",
"ln_1p",
"log10",
"log2",
"recip",
"round",
"signum",
"sin",
"sinh",
"sqrt",
"tan",
"tanh",
"to_degrees",
"to_radians",
"trunc",
];
for name in f32_unary_methods {
add_fn(&format!("tl_f32_{}", name), f32_unary_type);
}
let f32_binary_methods = ["atan2", "copysign", "hypot", "log", "powf"];
for name in f32_binary_methods {
add_fn(&format!("tl_f32_{}", name), f32_binary_type);
}
add_fn("tl_f32_powi", f32_powi_type);
let f64_unary_methods = [
"abs",
"acos",
"acosh",
"asin",
"asinh",
"atan",
"atanh",
"cbrt",
"ceil",
"cos",
"cosh",
"exp",
"exp2",
"exp_m1",
"floor",
"fract",
"ln",
"ln_1p",
"log10",
"log2",
"recip",
"round",
"signum",
"sin",
"sinh",
"sqrt",
"tan",
"tanh",
"to_degrees",
"to_radians",
"trunc",
];
for name in f64_unary_methods {
add_fn(&format!("tl_f64_{}", name), f64_unary_type);
}
let f64_binary_methods = ["atan2", "copysign", "hypot", "log", "powf"];
for name in f64_binary_methods {
add_fn(&format!("tl_f64_{}", name), f64_binary_type);
}
add_fn("tl_f64_powi", f64_powi_type);
let i64_unary_methods = ["abs", "signum"];
for name in i64_unary_methods {
add_fn(&format!("tl_i64_{}", name), i64_unary_type);
}
let i64_binary_methods = ["div_euclid", "rem_euclid", "pow"];
for name in i64_binary_methods {
add_fn(&format!("tl_i64_{}", name), i64_binary_type);
}
add_fn("tl_i64_is_positive", i64_bool_unary_type);
add_fn("tl_i64_is_negative", i64_bool_unary_type);
let i32_unary_methods = ["abs", "signum"];
for name in i32_unary_methods {
add_fn(&format!("tl_i32_{}", name), i32_unary_type);
}
let i32_binary_methods = ["div_euclid", "rem_euclid", "pow"];
for name in i32_binary_methods {
add_fn(&format!("tl_i32_{}", name), i32_binary_type);
}
add_fn("tl_i32_is_positive", i32_bool_unary_type);
add_fn("tl_i32_is_negative", i32_bool_unary_type);
let print_str_type = void_type.fn_type(&[void_ptr.into()], false);
add_fn("tl_print_string", print_str_type.clone());
add_fn("tl_display_string", print_str_type);
let file_exists_type = context.bool_type().fn_type(&[i8_ptr.into()], false);
add_fn("tl_file_exists", file_exists_type);
let file_exists_i64_type = i64_type.fn_type(&[i8_ptr.into()], false);
add_fn("tl_file_exists_i64", file_exists_i64_type);
let download_file_type = i64_type.fn_type(&[i8_ptr.into(), i8_ptr.into()], false);
add_fn("tl_download_file", download_file_type);
let read_file_type = i8_ptr.fn_type(&[i8_ptr.into()], false);
add_fn_typed("tl_read_file", read_file_type, Type::String("String".to_string()), ret_types);
let write_file_type = i64_type.fn_type(&[i8_ptr.into(), i8_ptr.into()], false);
add_fn("tl_write_file", write_file_type);
let print_ptr_type = void_type.fn_type(&[void_ptr.into()], false);
add_fn("tl_print_ptr", print_ptr_type);
let report_err_type = void_type.fn_type(&[i8_ptr.into()], false);
add_fn("tl_report_runtime_error", report_err_type);
let handle_err_type = void_type.fn_type(
&[
i32_type.into(),
i8_ptr.into(),
i8_ptr.into(),
i32_type.into(),
i32_type.into(),
],
false,
);
add_fn("tl_handle_runtime_error", handle_err_type.clone());
let amend_err_type =
void_type.fn_type(&[i8_ptr.into(), i32_type.into(), i32_type.into()], false);
add_fn("tl_amend_error_loc", amend_err_type);
let report_err_loc_type =
void_type.fn_type(&[i8_ptr.into(), i32_type.into(), i32_type.into()], false);
add_fn("tl_report_runtime_error_loc", report_err_loc_type);
if let Some(f) = module.get_function("tl_handle_runtime_error") {
execution_engine.add_global_mapping(&f, runtime::tl_handle_runtime_error as *const () as usize);
}
if let Some(f) = module.get_function("tl_amend_error_loc") {
execution_engine.add_global_mapping(&f, runtime::tl_amend_error_loc as *const () as usize);
}
if let Some(f) = module.get_function("tl_report_runtime_error_loc") {
execution_engine.add_global_mapping(&f, runtime::tl_report_runtime_error_loc as *const () as usize);
}
let get_last_error_type = c_tensor_result_type.fn_type(&[], false);
add_fn("tl_get_last_error", get_last_error_type);
let set_dev_type = void_type.fn_type(&[void_ptr.into()], false);
add_fn("tl_set_device", set_dev_type);
let enable_grad_type = void_type.fn_type(&[void_ptr.into()], false);
add_fn("tl_tensor_enable_grad", enable_grad_type);
let to_dev_type = void_ptr.fn_type(&[void_ptr.into(), void_ptr.into()], false);
add_fn("tl_tensor_to_device", to_dev_type);
let malloc_type = void_ptr.fn_type(&[i64_type.into()], false);
add_fn("malloc", malloc_type);
let calloc_type = void_ptr.fn_type(&[i64_type.into(), i64_type.into()], false);
add_fn("calloc", calloc_type);
let free_type = void_type.fn_type(&[void_ptr.into()], false);
add_fn("free", free_type);
let realloc_type = void_ptr.fn_type(&[void_ptr.into(), i64_type.into()], false);
add_fn("realloc", realloc_type);
let abort_type = void_type.fn_type(&[], false);
add_fn("abort", abort_type);
let dim_type = i64_type.fn_type(&[void_ptr.into(), i64_type.into()], false);
add_fn("tl_tensor_dim", dim_type);
let get_md_type = f32_type.fn_type(&[void_ptr.into(), i64_ptr.into(), i64_type.into()], false);
add_fn("tl_tensor_get_f32_md", get_md_type);
let get_md_i64_type =
i64_type.fn_type(&[void_ptr.into(), i64_ptr.into(), i64_type.into()], false);
add_fn("tl_tensor_get_i64_md", get_md_i64_type);
let set_md_type = void_ptr.fn_type(
&[
void_ptr.into(),
i64_ptr.into(),
i64_type.into(),
f32_type.into(),
],
false,
);
add_fn("tl_tensor_set_f32_md", set_md_type);
let new_type = void_ptr.fn_type(&[f32_ptr.into(), i64_type.into(), usize_ptr.into()], false);
add_fn("tl_tensor_new", new_type);
let from_i64_type = void_ptr.fn_type(&[i64_ptr.into(), i64_type.into()], false);
add_fn("tl_tensor_from_i64_array", from_i64_type);
let new_i64_type =
void_ptr.fn_type(&[i64_ptr.into(), i64_type.into(), usize_ptr.into()], false);
add_fn("tl_tensor_new_i64", new_i64_type);
let binop_type = void_ptr.fn_type(&[void_ptr.into(), void_ptr.into()], false);
add_fn("tl_tensor_sub", binop_type);
let free_type = void_type.fn_type(&[void_ptr.into()], false);
add_fn("tl_tensor_free", free_type);
let clone_type = void_ptr.fn_type(&[void_ptr.into()], false);
add_fn("tl_tensor_clone", clone_type);
add_fn("tl_tensor_acquire", clone_type);
add_fn("tl_tensor_release", free_type);
add_fn("tl_tensor_release_safe", free_type);
add_fn("tl_qtensor_retain", clone_type);
add_fn("tl_qtensor_release_safe", free_type);
add_fn("tl_tensor_promote", free_type);
add_fn("tl_tensor_register", free_type);
let data_type = void_ptr.fn_type(&[void_ptr.into()], false);
add_fn("tl_tensor_data", data_type);
let numel_type = i64_type.fn_type(&[void_ptr.into()], false);
add_fn("tl_tensor_numel", numel_type);
let dec_ref_type = i32_type.fn_type(&[void_ptr.into()], false);
add_fn("tl_ptr_dec_ref", dec_ref_type);
let inc_ref_type = void_type.fn_type(&[void_ptr.into()], false);
add_fn("tl_ptr_inc_ref", inc_ref_type);
let inc_ref_i64_type = void_type.fn_type(&[i64_type.into()], false);
add_fn("tl_ptr_inc_ref_i64", inc_ref_i64_type);
add_fn("tl_mem_free", free_type);
let bin_type = void_ptr.fn_type(&[void_ptr.into(), void_ptr.into()], false);
add_fn("tl_tensor_add", bin_type);
add_fn("tl_tensor_mul", bin_type);
let print_type = void_type.fn_type(&[void_ptr.into()], false);
add_fn("tl_print_string", print_type.clone());
add_fn("tl_string_print", print_type.clone());
add_fn("tl_display_string", print_type.clone());
add_fn("tl_tensor_print", print_type.clone());
add_fn("tl_tensor_display", print_type.clone());
add_fn("tl_tensor_print_1", print_type.clone());
add_fn("tl_tensor_print_2", print_type.clone());
add_fn("tl_tensor_print_3", print_type.clone());
let get_type = f32_type.fn_type(&[void_ptr.into(), i64_type.into()], false);
add_fn("tl_tensor_get", get_type);
let slice_type = void_ptr.fn_type(&[void_ptr.into(), i64_type.into(), i64_type.into(), i64_type.into(), i64_type.into()], false);
add_fn("tl_tensor_slice", slice_type);
let len_str_type = i64_type.fn_type(&[i8_ptr.into()], false);
add_fn("tl_string_len", len_str_type);
let from_char_type = i8_ptr.fn_type(&[i32_type.into()], false);
add_fn_typed("tl_string_from_char", from_char_type, Type::String("String".to_string()), ret_types);
let char_at_type = i64_type.fn_type(&[void_ptr.into(), i64_type.into()], false);
add_fn("tl_string_char_at", char_at_type);
let string_eq_type = context.bool_type().fn_type(&[void_ptr.into(), void_ptr.into()], false);
add_fn("tl_string_eq", string_eq_type);
let new_string_type = void_ptr.fn_type(&[i8_ptr.into()], false);
add_fn_typed("tl_string_new", new_string_type, Type::String("String".to_string()), ret_types);
add_fn("tl_string_free", free_type);
let len_type = i64_type.fn_type(&[void_ptr.into()], false);
add_fn("tl_tensor_len", len_type);
let neg_type = void_ptr.fn_type(&[void_ptr.into()], false);
add_fn("tl_tensor_neg", neg_type);
let transpose_type =
void_ptr.fn_type(&[void_ptr.into(), i64_type.into(), i64_type.into()], false);
add_fn("tl_tensor_transpose", transpose_type);
let pow_type = void_ptr.fn_type(&[void_ptr.into(), void_ptr.into()], false);
add_fn("tl_tensor_pow", pow_type);
let pow_scalar_type = void_ptr.fn_type(&[void_ptr.into(), f32_type.into()], false);
add_fn("tl_tensor_pow_scalar", pow_scalar_type);
let scalar_op_type = void_ptr.fn_type(&[void_ptr.into(), f64_type.into()], false);
add_fn("tl_tensor_add_scalar", scalar_op_type.clone());
add_fn("tl_tensor_sub_scalar", scalar_op_type.clone());
add_fn("tl_tensor_mul_scalar", scalar_op_type.clone());
add_fn("tl_tensor_div_scalar", scalar_op_type);
let unary_type = void_ptr.fn_type(&[void_ptr.into()], false);
add_fn("tl_tensor_sqrt", unary_type);
add_fn("tl_tensor_sin", unary_type);
add_fn("tl_tensor_cos", unary_type);
add_fn("tl_tensor_relu", unary_type);
add_fn("tl_tensor_gelu", unary_type);
let tril_type = void_ptr.fn_type(&[void_ptr.into(), i64_type.into()], false);
add_fn("tl_tensor_tril", tril_type);
let clear_grads_type = void_type.fn_type(&[], false);
add_fn("tl_clear_grads", clear_grads_type);
let set_md_type = void_ptr.fn_type(
&[
void_ptr.into(),
void_ptr.into(), i64_type.into(), f32_type.into(), ],
false,
);
add_fn("tl_tensor_set_f32_md", set_md_type);
let get_md_type = f32_type.fn_type(
&[
void_ptr.into(),
void_ptr.into(), i64_type.into(), ],
false,
);
add_fn("tl_tensor_get_f32_md", get_md_type);
if let Some(f) = module.get_function("malloc") {
execution_engine.add_global_mapping(&f, malloc as *const () as usize);
}
if let Some(f) = module.get_function("calloc") {
execution_engine.add_global_mapping(&f, calloc as *const () as usize);
}
if let Some(f) = module.get_function("realloc") {
execution_engine.add_global_mapping(&f, realloc as *const () as usize);
}
if let Some(f) = module.get_function("free") {
execution_engine.add_global_mapping(&f, free as *const () as usize);
}
if let Some(f) = module.get_function("abort") {
execution_engine.add_global_mapping(&f, abort as *const () as usize);
}
if let Some(f) = module.get_function("tl_clear_grads") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_clear_grads as *const () as usize); }
if let Some(f) = module.get_function("tl_file_exists") {
execution_engine.add_global_mapping(&f, runtime::tl_file_exists as *const () as usize);
}
if let Some(f) = module.get_function("tl_file_exists_i64") {
execution_engine.add_global_mapping(&f, runtime::tl_file_exists_i64 as *const () as usize);
}
if let Some(f) = module.get_function("tl_download_file") {
execution_engine.add_global_mapping(&f, runtime::tl_download_file as *const () as usize);
}
if let Some(f) = module.get_function("tl_read_file") {
execution_engine.add_global_mapping(&f, runtime::tl_read_file as *const () as usize);
}
if let Some(f) = module.get_function("tl_write_file") {
execution_engine.add_global_mapping(&f, runtime::tl_write_file as *const () as usize);
}
if let Some(f) = module.get_function("tl_string_new") {
execution_engine.add_global_mapping(&f, runtime::tl_string_new as *const () as usize);
}
if let Some(f) = module.get_function("tl_print_string") {
execution_engine.add_global_mapping(&f, runtime::tl_print_string as *const () as usize);
}
if let Some(f) = module.get_function("tl_string_print") {
execution_engine.add_global_mapping(&f, runtime::tl_string_print as *const () as usize);
}
if let Some(f) = module.get_function("tl_display_string") {
execution_engine.add_global_mapping(&f, runtime::tl_display_string as *const () as usize);
}
if let Some(f) = module.get_function("tl_string_concat") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_string_concat as *const () as usize);
}
if let Some(f) = module.get_function("tl_string_len") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_string_len as *const () as usize);
}
if let Some(f) = module.get_function("tl_string_from_char") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_string_from_char as *const () as usize);
}
if let Some(f) = module.get_function("tl_string_to_i64") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_string_to_i64 as *const () as usize);
}
if let Some(f) = module.get_function("tl_string_contains") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_string_contains as *const () as usize);
}
if let Some(f) = module.get_function("tl_string_char_at") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_string_char_at as *const () as usize);
}
if let Some(f) = module.get_function("tl_string_eq") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_string_eq as *const () as usize);
}
if let Some(f) = module.get_function("tl_string_free") {
execution_engine.add_global_mapping(&f, runtime::string_ffi::tl_string_free as *const () as usize);
}
let hash_string_type = i64_type.fn_type(&[void_ptr.into()], false);
add_fn("tl_hash_string", hash_string_type);
if let Some(f) = module.get_function("tl_hash_string") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_hash_string as *const () as usize);
}
let checkpoint_type =
void_ptr.fn_type(&[void_ptr.into(), void_ptr.into(), void_ptr.into()], false);
add_fn("tl_checkpoint", checkpoint_type);
if let Some(f) = module.get_function("tl_checkpoint") {
execution_engine.add_global_mapping(&f, runtime::checkpoint::tl_checkpoint as *const () as usize);
}
let channel_new_type = i64_type.fn_type(&[i64_type.into()], false);
add_fn("tl_channel_new", channel_new_type);
let channel_send_type = context.bool_type().fn_type(&[i64_type.into(), i64_type.into()], false);
add_fn("tl_channel_send", channel_send_type);
let channel_recv_type = i64_type.fn_type(&[i64_type.into()], false);
add_fn("tl_channel_recv", channel_recv_type);
let channel_try_recv_type = i64_type.fn_type(&[i64_type.into(), context.ptr_type(AddressSpace::default()).into()], false);
add_fn("tl_channel_try_recv", channel_try_recv_type);
add_fn("tl_channel_clone", clone_type);
add_fn("tl_channel_free", free_type);
if let Some(f) = module.get_function("tl_channel_new") { execution_engine.add_global_mapping(&f, runtime::channel_ffi::tl_channel_new as *const () as usize); }
if let Some(f) = module.get_function("tl_channel_send") { execution_engine.add_global_mapping(&f, runtime::channel_ffi::tl_channel_send as *const () as usize); }
if let Some(f) = module.get_function("tl_channel_recv") { execution_engine.add_global_mapping(&f, runtime::channel_ffi::tl_channel_recv as *const () as usize); }
if let Some(f) = module.get_function("tl_channel_try_recv") { execution_engine.add_global_mapping(&f, runtime::channel_ffi::tl_channel_try_recv as *const () as usize); }
if let Some(f) = module.get_function("tl_channel_clone") { execution_engine.add_global_mapping(&f, runtime::channel_ffi::tl_channel_clone as *const () as usize); }
if let Some(f) = module.get_function("tl_channel_free") { execution_engine.add_global_mapping(&f, runtime::channel_ffi::tl_channel_free as *const () as usize); }
let atomic_new_type = i64_type.fn_type(&[i64_type.into()], false);
add_fn("tl_atomic_i64_new", atomic_new_type);
let atomic_load_type = i64_type.fn_type(&[i64_type.into()], false);
add_fn("tl_atomic_i64_load", atomic_load_type);
let atomic_store_type = void_type.fn_type(&[i64_type.into(), i64_type.into()], false);
add_fn("tl_atomic_i64_store", atomic_store_type);
let atomic_op_type = i64_type.fn_type(&[i64_type.into(), i64_type.into()], false);
add_fn("tl_atomic_i64_add", atomic_op_type);
add_fn("tl_atomic_i64_sub", atomic_op_type);
add_fn("tl_atomic_i64_swap", atomic_op_type);
let atomic_cmpxchg_type = context.bool_type().fn_type(&[i64_type.into(), i64_type.into(), i64_type.into()], false);
add_fn("tl_atomic_i64_compare_exchange", atomic_cmpxchg_type);
add_fn("tl_atomic_i64_clone", clone_type);
add_fn("tl_atomic_i64_free", free_type);
if let Some(f) = module.get_function("tl_atomic_i64_new") { execution_engine.add_global_mapping(&f, runtime::atomic_ffi::tl_atomic_i64_new as *const () as usize); }
if let Some(f) = module.get_function("tl_atomic_i64_load") { execution_engine.add_global_mapping(&f, runtime::atomic_ffi::tl_atomic_i64_load as *const () as usize); }
if let Some(f) = module.get_function("tl_atomic_i64_store") { execution_engine.add_global_mapping(&f, runtime::atomic_ffi::tl_atomic_i64_store as *const () as usize); }
if let Some(f) = module.get_function("tl_atomic_i64_add") { execution_engine.add_global_mapping(&f, runtime::atomic_ffi::tl_atomic_i64_add as *const () as usize); }
if let Some(f) = module.get_function("tl_atomic_i64_sub") { execution_engine.add_global_mapping(&f, runtime::atomic_ffi::tl_atomic_i64_sub as *const () as usize); }
if let Some(f) = module.get_function("tl_atomic_i64_swap") { execution_engine.add_global_mapping(&f, runtime::atomic_ffi::tl_atomic_i64_swap as *const () as usize); }
if let Some(f) = module.get_function("tl_atomic_i64_compare_exchange") { execution_engine.add_global_mapping(&f, runtime::atomic_ffi::tl_atomic_i64_compare_exchange as *const () as usize); }
if let Some(f) = module.get_function("tl_atomic_i64_clone") { execution_engine.add_global_mapping(&f, runtime::atomic_ffi::tl_atomic_i64_clone as *const () as usize); }
if let Some(f) = module.get_function("tl_atomic_i64_free") { execution_engine.add_global_mapping(&f, runtime::atomic_ffi::tl_atomic_i64_free as *const () as usize); }
let atomic_i32_new_type = i64_type.fn_type(&[i32_type.into()], false);
add_fn("tl_atomic_i32_new", atomic_i32_new_type);
let atomic_i32_load_type = i32_type.fn_type(&[i64_type.into()], false);
add_fn("tl_atomic_i32_load", atomic_i32_load_type);
let atomic_i32_store_type = void_type.fn_type(&[i64_type.into(), i32_type.into()], false);
add_fn("tl_atomic_i32_store", atomic_i32_store_type);
let atomic_i32_op_type = i32_type.fn_type(&[i64_type.into(), i32_type.into()], false);
add_fn("tl_atomic_i32_add", atomic_i32_op_type);
add_fn("tl_atomic_i32_sub", atomic_i32_op_type);
add_fn("tl_atomic_i32_swap", atomic_i32_op_type);
let atomic_i32_cmpxchg_type = context.bool_type().fn_type(&[i64_type.into(), i32_type.into(), i32_type.into()], false);
add_fn("tl_atomic_i32_compare_exchange", atomic_i32_cmpxchg_type);
add_fn("tl_atomic_i32_clone", clone_type);
add_fn("tl_atomic_i32_free", free_type);
if let Some(f) = module.get_function("tl_atomic_i32_new") { execution_engine.add_global_mapping(&f, runtime::atomic_ffi::tl_atomic_i32_new as *const () as usize); }
if let Some(f) = module.get_function("tl_atomic_i32_load") { execution_engine.add_global_mapping(&f, runtime::atomic_ffi::tl_atomic_i32_load as *const () as usize); }
if let Some(f) = module.get_function("tl_atomic_i32_store") { execution_engine.add_global_mapping(&f, runtime::atomic_ffi::tl_atomic_i32_store as *const () as usize); }
if let Some(f) = module.get_function("tl_atomic_i32_add") { execution_engine.add_global_mapping(&f, runtime::atomic_ffi::tl_atomic_i32_add as *const () as usize); }
if let Some(f) = module.get_function("tl_atomic_i32_sub") { execution_engine.add_global_mapping(&f, runtime::atomic_ffi::tl_atomic_i32_sub as *const () as usize); }
if let Some(f) = module.get_function("tl_atomic_i32_swap") { execution_engine.add_global_mapping(&f, runtime::atomic_ffi::tl_atomic_i32_swap as *const () as usize); }
if let Some(f) = module.get_function("tl_atomic_i32_compare_exchange") { execution_engine.add_global_mapping(&f, runtime::atomic_ffi::tl_atomic_i32_compare_exchange as *const () as usize); }
if let Some(f) = module.get_function("tl_atomic_i32_clone") { execution_engine.add_global_mapping(&f, runtime::atomic_ffi::tl_atomic_i32_clone as *const () as usize); }
if let Some(f) = module.get_function("tl_atomic_i32_free") { execution_engine.add_global_mapping(&f, runtime::atomic_ffi::tl_atomic_i32_free as *const () as usize); }
let duration_fn_type = i64_type.fn_type(&[i64_type.into()], false);
add_fn("tl_rt_duration_from_secs", duration_fn_type);
add_fn("tl_rt_duration_from_millis", duration_fn_type);
add_fn("tl_rt_duration_from_nanos", duration_fn_type);
add_fn("tl_rt_duration_as_secs", duration_fn_type);
add_fn("tl_rt_duration_as_millis", duration_fn_type);
let instant_now_type = i64_type.fn_type(&[], false);
add_fn("tl_rt_instant_now", instant_now_type);
add_fn("tl_rt_instant_elapsed", duration_fn_type);
let datetime_now_type = i64_type.fn_type(&[context.ptr_type(AddressSpace::default()).into()], false);
add_fn("tl_rt_datetime_now", datetime_now_type);
add_fn("tl_rt_datetime_utc_now", instant_now_type); add_fn("tl_rt_datetime_from_timestamp", duration_fn_type); add_fn("tl_rt_datetime_local_offset", instant_now_type); let datetime_component_type = i64_type.fn_type(&[i64_type.into(), i64_type.into()], false);
add_fn("tl_rt_datetime_year", datetime_component_type);
add_fn("tl_rt_datetime_month", datetime_component_type);
add_fn("tl_rt_datetime_day", datetime_component_type);
add_fn("tl_rt_datetime_hour", datetime_component_type);
add_fn("tl_rt_datetime_minute", datetime_component_type);
add_fn("tl_rt_datetime_second", datetime_component_type);
let datetime_format_type = void_ptr.fn_type(&[i64_type.into(), i64_type.into(), void_ptr.into()], false);
add_fn("tl_rt_datetime_format", datetime_format_type);
if let Some(f) = module.get_function("tl_rt_duration_from_secs") { execution_engine.add_global_mapping(&f, runtime::time_ffi::tl_rt_duration_from_secs as *const () as usize); }
if let Some(f) = module.get_function("tl_rt_duration_from_millis") { execution_engine.add_global_mapping(&f, runtime::time_ffi::tl_rt_duration_from_millis as *const () as usize); }
if let Some(f) = module.get_function("tl_rt_duration_from_nanos") { execution_engine.add_global_mapping(&f, runtime::time_ffi::tl_rt_duration_from_nanos as *const () as usize); }
if let Some(f) = module.get_function("tl_rt_duration_as_secs") { execution_engine.add_global_mapping(&f, runtime::time_ffi::tl_rt_duration_as_secs as *const () as usize); }
if let Some(f) = module.get_function("tl_rt_duration_as_millis") { execution_engine.add_global_mapping(&f, runtime::time_ffi::tl_rt_duration_as_millis as *const () as usize); }
if let Some(f) = module.get_function("tl_rt_instant_now") { execution_engine.add_global_mapping(&f, runtime::time_ffi::tl_rt_instant_now as *const () as usize); }
if let Some(f) = module.get_function("tl_rt_instant_elapsed") { execution_engine.add_global_mapping(&f, runtime::time_ffi::tl_rt_instant_elapsed as *const () as usize); }
if let Some(f) = module.get_function("tl_rt_datetime_now") { execution_engine.add_global_mapping(&f, runtime::time_ffi::tl_rt_datetime_now as *const () as usize); }
if let Some(f) = module.get_function("tl_rt_datetime_utc_now") { execution_engine.add_global_mapping(&f, runtime::time_ffi::tl_rt_datetime_utc_now as *const () as usize); }
if let Some(f) = module.get_function("tl_rt_datetime_from_timestamp") { execution_engine.add_global_mapping(&f, runtime::time_ffi::tl_rt_datetime_from_timestamp as *const () as usize); }
if let Some(f) = module.get_function("tl_rt_datetime_local_offset") { execution_engine.add_global_mapping(&f, runtime::time_ffi::tl_rt_datetime_local_offset as *const () as usize); }
if let Some(f) = module.get_function("tl_rt_datetime_year") { execution_engine.add_global_mapping(&f, runtime::time_ffi::tl_rt_datetime_year as *const () as usize); }
if let Some(f) = module.get_function("tl_rt_datetime_month") { execution_engine.add_global_mapping(&f, runtime::time_ffi::tl_rt_datetime_month as *const () as usize); }
if let Some(f) = module.get_function("tl_rt_datetime_day") { execution_engine.add_global_mapping(&f, runtime::time_ffi::tl_rt_datetime_day as *const () as usize); }
if let Some(f) = module.get_function("tl_rt_datetime_hour") { execution_engine.add_global_mapping(&f, runtime::time_ffi::tl_rt_datetime_hour as *const () as usize); }
if let Some(f) = module.get_function("tl_rt_datetime_minute") { execution_engine.add_global_mapping(&f, runtime::time_ffi::tl_rt_datetime_minute as *const () as usize); }
if let Some(f) = module.get_function("tl_rt_datetime_second") { execution_engine.add_global_mapping(&f, runtime::time_ffi::tl_rt_datetime_second as *const () as usize); }
if let Some(f) = module.get_function("tl_rt_datetime_format") { execution_engine.add_global_mapping(&f, runtime::time_ffi::tl_rt_datetime_format as *const () as usize); }
if let Some(f) = module.get_function("tl_set_device") {
execution_engine.add_global_mapping(&f, runtime::tl_set_device as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_to_device") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_to_device as *const () as usize);
}
if let Some(f) = module.get_function("tl_report_runtime_error") {
execution_engine.add_global_mapping(&f, runtime::tl_report_runtime_error as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_acquire") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_acquire as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_replace_data") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_replace_data as *const () as usize);
}
let sum_dim_type = void_ptr.fn_type(
&[void_ptr.into(), i64_type.into(), context.bool_type().into()],
false,
);
add_fn("tl_tensor_sum_dim", sum_dim_type);
let embedding_type = void_ptr.fn_type(&[
void_ptr.into(), void_ptr.into(), i64_type.into(), context.bool_type().into(), context.bool_type().into(), ], false);
add_fn("tl_tensor_embedding", embedding_type);
let unary_res_type = void_ptr.fn_type(&[void_ptr.into()], false);
add_fn("tl_tensor_sum", unary_res_type);
add_fn("tl_tensor_div", bin_type);
add_fn("tl_tensor_eq", bin_type);
add_fn("tl_tensor_neq", bin_type);
add_fn("tl_tensor_gt", bin_type);
add_fn("tl_tensor_lt", bin_type);
add_fn("tl_tensor_ge", bin_type);
add_fn("tl_tensor_le", bin_type);
add_fn("tl_tensor_matmul", bin_type);
add_fn("tl_tensor_rem", bin_type);
add_fn("tl_tensor_exp", unary_res_type);
add_fn("tl_tensor_log", unary_res_type);
let assign_type = void_type.fn_type(&[void_ptr.into(), void_ptr.into()], false);
add_fn("tl_tensor_add_assign", assign_type);
add_fn("tl_tensor_sub_assign", assign_type);
add_fn("tl_tensor_mul_assign", assign_type);
add_fn("tl_tensor_div_assign", assign_type);
let scalar_assign_type =
void_type.fn_type(&[void_ptr.into(), context.f32_type().into()], false);
add_fn("tl_tensor_add_assign_scalar_f32", scalar_assign_type);
add_fn("tl_tensor_sub_assign_scalar_f32", scalar_assign_type);
add_fn("tl_tensor_mul_assign_scalar_f32", scalar_assign_type);
add_fn("tl_tensor_div_assign_scalar_f32", scalar_assign_type);
add_fn("tl_tensor_mod_assign_scalar_f32", scalar_assign_type);
add_fn("tl_tensor_mod_assign", assign_type);
let i8_ptr = context.ptr_type(AddressSpace::default());
let register_type = void_type.fn_type(&[i8_ptr.into(), void_ptr.into()], false);
add_fn("tl_register_tensor", register_type);
let set_req_grad_type = void_type.fn_type(&[void_ptr.into(), context.bool_type().into()], false);
add_fn("tl_device_tensor_set_requires_grad", set_req_grad_type);
let clip_grad_value_type = void_type.fn_type(&[void_ptr.into(), context.f64_type().into(), context.f64_type().into()], false);
add_fn("tl_device_tensor_clip_grad_value", clip_grad_value_type);
let clip_grad_norm_type = context.f64_type().fn_type(&[void_ptr.into(), context.f64_type().into(), context.f64_type().into()], false);
add_fn("tl_device_tensor_clip_grad_norm", clip_grad_norm_type);
let strcmp_type = context
.i32_type()
.fn_type(&[i8_ptr.into(), i8_ptr.into()], false);
add_fn("strcmp", strcmp_type);
let save_type = void_type.fn_type(&[void_ptr.into(), i8_ptr.into()], false);
add_fn("tl_tensor_save", save_type);
let load_type = void_ptr.fn_type(&[i8_ptr.into()], false);
add_fn("tl_tensor_load", load_type);
let replace_data_type = void_type.fn_type(&[void_ptr.into(), void_ptr.into()], false);
add_fn("tl_tensor_replace_data", replace_data_type);
let add_entity_type = context.i64_type().fn_type(&[i8_ptr.into()], false);
add_fn("tl_kb_add_entity", add_entity_type);
let add_fact_serialized_type = void_type.fn_type(&[i8_ptr.into()], false);
add_fn("tl_kb_add_fact_serialized", add_fact_serialized_type);
add_fn("tl_kb_fact_args_clear", void_type.fn_type(&[], false));
add_fn("tl_kb_fact_args_add_int", void_type.fn_type(&[context.i64_type().into()], false));
add_fn("tl_kb_fact_args_add_float", void_type.fn_type(&[context.f64_type().into()], false));
add_fn("tl_kb_fact_args_add_bool", void_type.fn_type(&[context.bool_type().into()], false));
add_fn("tl_kb_fact_args_add_entity", void_type.fn_type(&[context.i64_type().into()], false));
add_fn("tl_kb_fact_args_add_string", void_type.fn_type(&[i8_ptr.into()], false));
let args_ptr_type = context.ptr_type(AddressSpace::default());
let add_fact_type = void_type.fn_type(
&[
i8_ptr.into(),
args_ptr_type.into(),
context.i64_type().into(), ],
false,
);
add_fn("tl_kb_add_fact", add_fact_type);
let infer_type = void_type.fn_type(&[], false);
add_fn("tl_kb_infer", infer_type);
let rule_start_type = void_type.fn_type(&[i8_ptr.into()], false);
add_fn("tl_kb_rule_start", rule_start_type);
let arg_i64_type = void_type.fn_type(&[context.i64_type().into()], false);
add_fn("tl_kb_rule_add_head_arg_var", arg_i64_type);
add_fn("tl_kb_rule_add_head_arg_const_int", arg_i64_type);
let arg_f64_type = void_type.fn_type(&[context.f64_type().into()], false);
add_fn("tl_kb_rule_add_head_arg_const_float", arg_f64_type);
add_fn("tl_kb_rule_add_head_arg_const_entity", arg_i64_type);
add_fn("tl_kb_rule_add_body_atom", rule_start_type);
add_fn("tl_kb_rule_add_body_atom_neg", rule_start_type);
add_fn("tl_kb_rule_add_body_arg_var", arg_i64_type);
add_fn("tl_kb_rule_add_body_arg_const_int", arg_i64_type);
add_fn("tl_kb_rule_add_body_arg_const_float", arg_f64_type);
add_fn("tl_kb_rule_add_body_arg_const_entity", arg_i64_type);
add_fn("tl_kb_rule_finish", infer_type);
let map_new_type = void_ptr.fn_type(&[], false);
add_fn("tl_tensor_map_new", map_new_type);
let map_insert_type =
void_type.fn_type(&[void_ptr.into(), i8_ptr.into(), void_ptr.into()], false);
add_fn("tl_tensor_map_insert", map_insert_type);
let map_save_type = void_type.fn_type(&[void_ptr.into(), i8_ptr.into()], false);
add_fn("tl_tensor_map_save", map_save_type);
let map_load_type = void_ptr.fn_type(&[i8_ptr.into()], false);
add_fn("tl_tensor_map_load", map_load_type);
let map_free_type = void_type.fn_type(&[void_ptr.into()], false);
add_fn("tl_tensor_map_free", map_free_type);
let reshape_dims_type =
void_ptr.fn_type(&[void_ptr.into(), i64_ptr.into(), i64_type.into()], false);
add_fn("tl_tensor_reshape_dims", reshape_dims_type);
let reshape_tensor_type = void_ptr.fn_type(&[void_ptr.into(), void_ptr.into()], false);
add_fn("tl_tensor_reshape_new", reshape_tensor_type);
let randn_type = void_ptr.fn_type(
&[
i64_type.into(), usize_ptr.into(), i64_type.into(), context.bool_type().into(), ],
false,
);
add_fn("tl_tensor_randn_debug", randn_type);
let zeros_type = void_ptr.fn_type(
&[
i64_type.into(), usize_ptr.into(), context.bool_type().into(), ],
false,
);
add_fn("tl_tensor_zeros", zeros_type);
add_fn("tl_tensor_ones", zeros_type);
let full_type = void_ptr.fn_type(
&[
i64_type.into(), usize_ptr.into(), f32_type.into(), context.bool_type().into(), ],
false,
);
add_fn("tl_tensor_full", full_type);
let eye_type = void_ptr.fn_type(
&[
i64_type.into(), context.bool_type().into(), ],
false,
);
add_fn("tl_tensor_eye", eye_type);
let arange_type = void_ptr.fn_type(
&[
f64_type.into(), f64_type.into(), f64_type.into(), ],
false,
);
add_fn("tl_tensor_arange", arange_type);
add_fn("tl_tensor_zeros_like", unary_type);
add_fn("tl_tensor_ones_like", unary_type);
let from_vec_f32_type = void_ptr.fn_type(&[void_ptr.into(), void_ptr.into()], false);
add_fn("tl_tensor_from_vec_f32", from_vec_f32_type);
let from_vec_u8_type = void_ptr.fn_type(&[void_ptr.into(), i64_type.into(), void_ptr.into(), i64_type.into()], false);
add_fn("tl_tensor_from_vec_u8", from_vec_u8_type);
add_fn("tl_tensor_from_vec_u8_f32_shape", from_vec_u8_type);
let from_u8_labels_type = void_ptr.fn_type(&[i8_ptr.into(), i64_type.into()], false);
add_fn("tl_tensor_from_u8_labels", from_u8_labels_type);
let to_vec_f32_type = void_ptr.fn_type(&[void_ptr.into()], false);
add_fn("tl_tensor_to_vec_f32", to_vec_f32_type);
let linspace_type = void_ptr.fn_type(
&[
f64_type.into(), f64_type.into(), i64_type.into(), ],
false,
);
add_fn("tl_tensor_linspace", linspace_type);
add_fn("tl_tensor_rand", zeros_type);
add_fn("tl_tensor_rand_like", unary_type);
add_fn("tl_tensor_randn_like", unary_type);
let ternary_type = void_ptr.fn_type(&[void_ptr.into(), void_ptr.into(), void_ptr.into()], false);
add_fn("tl_tensor_where_cond", ternary_type);
let masked_fill_type = void_ptr.fn_type(&[void_ptr.into(), void_ptr.into(), f64_type.into()], false);
add_fn("tl_tensor_masked_fill_scalar", masked_fill_type);
let reduce_dim_type = void_ptr.fn_type(&[void_ptr.into(), i64_type.into(), context.bool_type().into()], false);
add_fn("tl_tensor_var_dim", reduce_dim_type);
add_fn("tl_tensor_std_dim", reduce_dim_type);
add_fn("tl_tensor_var", unary_type);
add_fn("tl_tensor_std", unary_type);
add_fn("tl_tensor_prod_dim", reduce_dim_type);
add_fn("tl_tensor_prod", unary_type);
let fill_type = context.void_type().fn_type(&[void_ptr.into(), f32_type.into()], false);
add_fn("tl_tensor_fill_", fill_type);
let cumsum_type = void_ptr.fn_type(&[void_ptr.into(), i64_type.into()], false);
add_fn("tl_tensor_cumsum", cumsum_type);
let norm_type = void_ptr.fn_type(&[void_ptr.into(), f32_type.into(), i64_type.into()], false);
add_fn("tl_tensor_norm", norm_type);
let topk_type = void_ptr.fn_type(&[void_ptr.into(), i64_type.into(), i64_type.into()], false);
add_fn("tl_tensor_topk", topk_type);
let logical_binary_type = void_ptr.fn_type(&[void_ptr.into(), void_ptr.into()], false);
add_fn("tl_tensor_logical_and", logical_binary_type);
add_fn("tl_tensor_logical_or", logical_binary_type);
add_fn("tl_tensor_logical_not", unary_type);
let expand_type = void_ptr.fn_type(&[void_ptr.into(), context.ptr_type(inkwell::AddressSpace::default()).into(), i64_type.into()], false);
add_fn("tl_tensor_expand", expand_type);
let expand_new_type = void_ptr.fn_type(&[void_ptr.into(), void_ptr.into()], false);
add_fn("tl_tensor_expand_new", expand_new_type);
let stack_type = void_ptr.fn_type(&[void_ptr.into(), void_ptr.into(), i64_type.into()], false);
add_fn("tl_tensor_stack", stack_type);
let chunk_split_type = void_ptr.fn_type(&[void_ptr.into(), i64_type.into(), i64_type.into(), i64_type.into()], false);
add_fn("tl_tensor_chunk", chunk_split_type);
add_fn("tl_tensor_split", chunk_split_type);
let leaky_relu_type = void_ptr.fn_type(&[void_ptr.into(), f32_type.into()], false);
add_fn("tl_tensor_leaky_relu", leaky_relu_type);
add_fn("tl_tensor_elu", leaky_relu_type);
add_fn("tl_tensor_mish", unary_type);
let loss_binary_type = void_ptr.fn_type(&[void_ptr.into(), void_ptr.into()], false);
add_fn("tl_tensor_mse_loss", loss_binary_type);
add_fn("tl_tensor_l1_loss", loss_binary_type);
add_fn("tl_tensor_bce_loss", loss_binary_type);
add_fn("tl_tensor_nll_loss", loss_binary_type);
let linear_type = void_ptr.fn_type(&[void_ptr.into(), void_ptr.into(), void_ptr.into()], false);
add_fn("tl_tensor_linear", linear_type);
add_fn("tl_tensor_hardswish", unary_type);
add_fn("tl_tensor_hardsigmoid", unary_type);
let group_norm_type = void_ptr.fn_type(&[void_ptr.into(), i64_type.into(), void_ptr.into(), void_ptr.into(), f64_type.into()], false);
add_fn("tl_tensor_group_norm", group_norm_type);
let adaptive_pool_type = void_ptr.fn_type(&[void_ptr.into(), i64_type.into(), i64_type.into()], false);
add_fn("tl_tensor_adaptive_avg_pool2d", adaptive_pool_type);
let pad_type = void_ptr.fn_type(&[void_ptr.into(), i64_type.into(), i64_type.into(), f32_type.into()], false);
add_fn("tl_tensor_pad", pad_type);
let instance_norm_type = void_ptr.fn_type(&[void_ptr.into(), void_ptr.into(), void_ptr.into(), f64_type.into()], false);
add_fn("tl_tensor_instance_norm", instance_norm_type);
let conv1d_type = void_ptr.fn_type(&[void_ptr.into(), void_ptr.into(), void_ptr.into(), i64_type.into(), i64_type.into()], false);
add_fn("tl_tensor_conv1d", conv1d_type);
add_fn("tl_tensor_kl_div_loss", loss_binary_type);
let conv_transpose2d_type = void_ptr.fn_type(&[void_ptr.into(), void_ptr.into(), void_ptr.into(), i64_type.into(), i64_type.into(), i64_type.into()], false);
add_fn("tl_tensor_conv_transpose2d", conv_transpose2d_type);
let interpolate_type = void_ptr.fn_type(&[void_ptr.into(), i64_type.into(), i64_type.into(), i64_type.into()], false);
add_fn("tl_tensor_interpolate", interpolate_type);
let sdpa_type = void_ptr.fn_type(&[void_ptr.into(), void_ptr.into(), void_ptr.into(), void_ptr.into()], false);
add_fn("tl_tensor_sdpa", sdpa_type);
let topk_type = void_ptr.fn_type(&[void_ptr.into(), i64_type.into()], false);
add_fn("tl_tensor_top_k_sample", topk_type);
let topp_type = void_ptr.fn_type(&[void_ptr.into(), f64_type.into()], false);
add_fn("tl_tensor_top_p_sample", topp_type);
add_fn("tl_tensor_temperature_scale", topp_type); let rep_penalty_type = void_ptr.fn_type(&[void_ptr.into(), void_ptr.into(), f64_type.into()], false);
add_fn("tl_tensor_repetition_penalty", rep_penalty_type);
add_fn("tl_tensor_dot", loss_binary_type);
let varbuilder_get_type =
void_ptr.fn_type(&[i8_ptr.into(), i64_type.into(), usize_ptr.into()], false);
add_fn("tl_varbuilder_get", varbuilder_get_type);
let varbuilder_get_tensor_type = void_ptr.fn_type(&[i8_ptr.into(), void_ptr.into()], false);
add_fn("tl_varbuilder_get_from_tensor", varbuilder_get_tensor_type);
let update_type = void_type.fn_type(&[f32_type.into()], false);
add_fn("tl_update_all_params", update_type);
let grad_type = void_ptr.fn_type(&[i8_ptr.into()], false);
add_fn("tl_varbuilder_grad", grad_type);
let backward_type = void_type.fn_type(&[void_ptr.into()], false);
add_fn("tl_tensor_backward", backward_type);
let grad_fn_type = void_ptr.fn_type(&[void_ptr.into()], false);
add_fn("tl_tensor_grad", grad_fn_type);
let detach_type = void_ptr.fn_type(&[void_ptr.into(), context.bool_type().into()], false);
add_fn("tl_tensor_detach", detach_type);
let contiguous_type = void_ptr.fn_type(&[void_ptr.into()], false);
add_fn("tl_tensor_contiguous", contiguous_type);
let softmax_type = void_ptr.fn_type(&[void_ptr.into(), i64_type.into()], false);
add_fn("tl_tensor_softmax", softmax_type);
let cross_entropy_type = void_ptr.fn_type(&[void_ptr.into(), void_ptr.into()], false);
add_fn("tl_tensor_cross_entropy", cross_entropy_type);
let params_io_type = void_type.fn_type(&[i8_ptr.into()], false);
add_fn("tl_save_all_params", params_io_type);
let add_param_type = void_type.fn_type(&[i8_ptr.into(), void_ptr.into()], false);
add_fn("tl_add_parameter", add_param_type);
add_fn("tl_load_all_params", params_io_type);
let register_param_type = void_ptr.fn_type(&[void_ptr.into()], false);
add_fn("tl_register_parameter", register_param_type);
let str_new_type = i8_ptr.fn_type(&[i8_ptr.into()], false);
add_fn("tl_string_new", str_new_type);
let str_concat_type = i8_ptr.fn_type(&[i8_ptr.into(), i8_ptr.into()], false);
add_fn("tl_string_concat", str_concat_type);
let file_open_type = void_ptr.fn_type(&[i8_ptr.into(), i8_ptr.into()], false);
add_fn("tl_file_open", file_open_type);
let file_read_type = i8_ptr.fn_type(&[void_ptr.into()], false); add_fn("tl_file_read_string", file_read_type);
let file_write_type = void_type.fn_type(&[void_ptr.into(), i8_ptr.into()], false);
add_fn("tl_file_write_string", file_write_type);
let file_close_type = void_type.fn_type(&[void_ptr.into()], false);
add_fn("tl_file_close", file_close_type);
let path_new_type = void_ptr.fn_type(&[i8_ptr.into()], false);
add_fn("tl_path_new", path_new_type);
let path_join_type = void_ptr.fn_type(&[void_ptr.into(), i8_ptr.into()], false);
add_fn("tl_path_join", path_join_type);
let path_exists_type = context.bool_type().fn_type(&[void_ptr.into()], false);
add_fn("tl_path_exists", path_exists_type);
add_fn("tl_path_is_dir", path_exists_type);
add_fn("tl_path_is_file", path_exists_type);
let get_buffer_type = void_ptr.fn_type(&[i64_type.into(), i64_type.into()], false);
add_fn("tl_mem_get_buffer", get_buffer_type);
let log_alloc_type = void_type.fn_type(&[void_ptr.into(), i64_type.into(), i8_ptr.into(), i32_type.into()], false);
add_fn("tl_log_alloc", log_alloc_type);
let log_free_type = void_type.fn_type(&[void_ptr.into(), i8_ptr.into(), i32_type.into()], false);
add_fn("tl_log_free", log_free_type);
let trace_mem_type = void_type.fn_type(
&[
i8_ptr.into(),
i32_type.into(),
i32_type.into(),
i8_ptr.into(),
],
false
);
add_fn("tl_trace_mem", trace_mem_type);
if let Some(f) = module.get_function("tl_log_alloc") {
execution_engine.add_global_mapping(&f, runtime::tl_log_alloc as *const () as usize);
}
if let Some(f) = module.get_function("tl_log_free") {
execution_engine.add_global_mapping(&f, runtime::tl_log_free as *const () as usize);
}
if let Some(f) = module.get_function("tl_trace_mem") {
execution_engine.add_global_mapping(&f, runtime::tl_trace_mem as *const () as usize);
}
if let Some(f) = module.get_function("tl_mem_get_buffer") {
execution_engine.add_global_mapping(&f, runtime::tl_mem_get_buffer as *const () as usize);
}
let fn_enter_type = void_type.fn_type(&[i64_type.into()], false);
add_fn("tl_mem_function_enter", fn_enter_type);
let fn_exit_type = void_type.fn_type(&[], false);
add_fn("tl_mem_function_exit", fn_exit_type);
if let Some(f) = module.get_function("tl_mem_function_enter") {
execution_engine.add_global_mapping(&f, runtime::tl_mem_function_enter as *const () as usize);
}
if let Some(f) = module.get_function("tl_mem_function_exit") {
execution_engine.add_global_mapping(&f, runtime::tl_mem_function_exit as *const () as usize);
}
let path_to_str_type = i8_ptr.fn_type(&[void_ptr.into()], false);
add_fn("tl_path_to_string", path_to_str_type);
if let Some(f) = module.get_function("tl_print_string") {
execution_engine.add_global_mapping(&f, runtime::tl_print_string as *const () as usize);
}
let exit_fn_type = void_type.fn_type(&[], false);
add_fn("tl_mem_function_exit", exit_fn_type);
if let Some(f) = module.get_function("tl_mem_function_exit") {
execution_engine.add_global_mapping(&f, runtime::memory_manager::tl_mem_function_exit as *const () as usize);
}
let arena_init_type = void_type.fn_type(&[i64_type.into()], false);
add_fn("tl_arena_init", arena_init_type);
let path_free_type = void_type.fn_type(&[void_ptr.into()], false);
add_fn("tl_path_free", path_free_type);
let http_dl_type = context
.bool_type()
.fn_type(&[i8_ptr.into(), i8_ptr.into()], false);
add_fn("tl_http_download", http_dl_type);
let http_get_type = i8_ptr.fn_type(&[i8_ptr.into()], false);
add_fn("tl_http_get", http_get_type);
let env_get_type = i8_ptr.fn_type(&[i8_ptr.into()], false);
add_fn("tl_env_get", env_get_type);
let env_set_type = void_type.fn_type(&[i8_ptr.into(), i8_ptr.into()], false);
add_fn("tl_env_set", env_set_type);
let args_count_type = i64_type.fn_type(&[], false);
add_fn("tl_args_count", args_count_type);
let args_get_type = i8_ptr.fn_type(&[i64_type.into()], false);
add_fn("tl_args_get", args_get_type);
let str_to_int_type = i64_type.fn_type(&[i8_ptr.into()], false);
add_fn("tl_string_to_i64", str_to_int_type);
let string_len_type = i64_type.fn_type(&[i8_ptr.into()], false);
add_fn("tl_string_len", string_len_type);
let read_line_type = i8_ptr.fn_type(&[void_ptr.into()], false); add_fn("tl_read_line", read_line_type);
let sys_time_type = f32_type.fn_type(&[], false); add_fn("tl_system_time", sys_time_type);
let sys_sleep_type = void_type.fn_type(&[f32_type.into()], false);
add_fn("tl_system_sleep", sys_sleep_type);
let mem_mb_type = f64_type.fn_type(&[], false);
add_fn("tl_get_memory_mb", mem_mb_type);
add_fn("tl_get_metal_pool_mb", mem_mb_type);
let purge_type = void_type.fn_type(&[], false);
add_fn("tl_mem_purge", purge_type);
let mem_count_type = i64_type.fn_type(&[], false);
add_fn("tl_get_memory_bytes", mem_count_type);
add_fn("tl_get_metal_pool_bytes", mem_count_type);
add_fn("tl_get_metal_pool_count", mem_count_type);
add_fn("tl_get_pool_count", mem_count_type);
add_fn("tl_get_refcount_count", mem_count_type);
add_fn("tl_get_scope_depth", mem_count_type);
let trace_type = void_type.fn_type(
&[
i8_ptr.into(),
context.i32_type().into(),
context.i32_type().into(),
i8_ptr.into(),
],
false,
);
add_fn("tl_trace_mem", trace_type);
let metal_sync_type = void_type.fn_type(&[], false);
add_fn("tl_metal_sync", metal_sync_type);
let mem_report_type = void_type.fn_type(&[], false);
add_fn("tl_system_mem_report", mem_report_type);
let enter_scope_type = void_type.fn_type(&[], false);
add_fn("tl_mem_enter_scope", enter_scope_type);
let exit_scope_type = void_type.fn_type(&[], false);
add_fn("tl_mem_exit_scope", exit_scope_type);
let reg_struct_type = void_type.fn_type(&[void_ptr.into()], false);
add_fn("tl_mem_register_struct", reg_struct_type);
add_fn("tl_mem_register_tensor", reg_struct_type);
add_fn("tl_mem_unregister", reg_struct_type);
let prepare_ret_type = void_ptr.fn_type(&[void_ptr.into()], false);
add_fn("tl_tensor_prepare_return", prepare_ret_type);
let pool_acq = void_ptr.fn_type(&[i64_type.into()], false);
add_fn("tl_pool_acquire", pool_acq);
let pool_rel = void_type.fn_type(&[void_ptr.into(), i64_type.into()], false);
add_fn("tl_pool_release", pool_rel);
let arena_init = void_type.fn_type(&[i64_type.into()], false);
add_fn("tl_arena_init", arena_init);
let arena_alloc = void_ptr.fn_type(&[i64_type.into()], false);
add_fn("tl_arena_alloc", arena_alloc);
let arena_free = void_type.fn_type(&[], false);
add_fn("tl_arena_free", arena_free);
let arena_active = context.bool_type().fn_type(&[], false);
add_fn("tl_arena_is_active", arena_active);
let arena_reset = void_type.fn_type(&[], false);
add_fn("tl_arena_reset", arena_reset);
let arena_offset = i64_type.fn_type(&[], false);
add_fn("tl_arena_get_offset", arena_offset);
let arena_capacity = i64_type.fn_type(&[], false);
add_fn("tl_arena_get_capacity", arena_capacity);
let tok_new_type = i64_type.fn_type(&[i8_ptr.into()], false);
add_fn("tl_tokenizer_new", tok_new_type);
let tok_enc_type = void_ptr.fn_type(&[i64_type.into(), i8_ptr.into()], false);
add_fn("tl_tokenizer_encode", tok_enc_type);
let tok_enc_chat_type = void_ptr.fn_type(&[i64_type.into(), i8_ptr.into()], false);
add_fn("tl_tokenizer_encode_chat", tok_enc_chat_type);
let tok_enc_chat_zephyr_type = void_ptr.fn_type(&[i64_type.into(), i8_ptr.into()], false);
add_fn("tl_tokenizer_encode_chat_zephyr", tok_enc_chat_zephyr_type);
let tok_dec_type = i8_ptr.fn_type(&[i64_type.into(), void_ptr.into()], false);
add_fn("tl_tokenizer_decode", tok_dec_type);
let gguf_load_type = void_ptr.fn_type(&[i8_ptr.into()], false);
add_fn("tl_gguf_load", gguf_load_type);
let map_get_type = void_ptr.fn_type(&[void_ptr.into(), i8_ptr.into()], false);
add_fn("tl_tensor_map_get", map_get_type);
let cat_type = void_ptr.fn_type(&[void_ptr.into(), i64_type.into()], false);
add_fn("tl_tensor_cat", cat_type);
add_fn("tl_tensor_silu", unary_type);
let scale_type = void_ptr.fn_type(&[void_ptr.into(), f32_type.into()], false);
add_fn("tl_tensor_scale", scale_type);
let cat2_type = void_ptr.fn_type(&[void_ptr.into(), void_ptr.into(), i64_type.into()], false);
add_fn("tl_tensor_cat2", cat2_type);
add_fn("tl_tensor_cat_4d", cat2_type);
let rms_type = void_ptr.fn_type(&[void_ptr.into(), void_ptr.into(), f32_type.into()], false);
add_fn("tl_tensor_rms_norm", rms_type);
let rope_type = void_ptr.fn_type(&[void_ptr.into(), void_ptr.into(), void_ptr.into()], false);
add_fn("tl_tensor_apply_rope", rope_type);
add_fn("tl_tensor_transpose_2d", transpose_type);
add_fn("tl_tensor_matmul_4d", bin_type);
add_fn("tl_tensor_add_4d", bin_type);
add_fn("tl_tensor_silu_4d", unary_type);
let tensor_reshape_2d_type =
void_ptr.fn_type(&[void_ptr.into(), void_ptr.into(), i64_type.into()], false);
add_fn("tl_tensor_reshape_2d", tensor_reshape_2d_type);
add_fn("tl_tensor_reshape_3d_to_2d", tensor_reshape_2d_type);
let map_get_1d_type = void_ptr.fn_type(&[void_ptr.into(), i8_ptr.into()], false);
add_fn("tl_tensor_map_get_1d", map_get_1d_type);
let narrow_type = void_ptr.fn_type(
&[
void_ptr.into(),
i64_type.into(),
i64_type.into(),
i64_type.into(),
],
false,
);
add_fn("tl_tensor_narrow", narrow_type);
let repeat_interleave_type =
void_ptr.fn_type(&[void_ptr.into(), i64_type.into(), i64_type.into()], false);
add_fn("tl_tensor_repeat_interleave", repeat_interleave_type);
let rope_new_type =
void_ptr.fn_type(&[i64_type.into(), i64_type.into(), f32_type.into()], false);
add_fn("tl_tensor_rope_new_cos", rope_new_type);
add_fn("tl_tensor_rope_new_sin", rope_new_type);
let causal_mask_type = void_ptr.fn_type(&[i64_type.into()], false);
add_fn("tl_tensor_new_causal_mask", causal_mask_type);
let cat_i64_type =
void_ptr.fn_type(&[void_ptr.into(), void_ptr.into(), i64_type.into()], false);
add_fn("tl_tensor_cat_i64", cat_i64_type);
let device_id_type = i64_type.fn_type(&[void_ptr.into()], false);
add_fn("tl_tensor_device_id", device_id_type);
if let Some(f) = module.get_function("tl_print_string") {
execution_engine.add_global_mapping(&f, runtime::tl_print_string as *const () as usize);
}
if let Some(f) = module.get_function("tl_display_string") {
execution_engine.add_global_mapping(&f, runtime::tl_display_string as *const () as usize);
}
if let Some(f) = module.get_function("tl_prompt") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_prompt as *const () as usize);
}
if let Some(f) = module.get_function("tl_print_f32") {
execution_engine.add_global_mapping(&f, runtime::tl_print_f32 as *const () as usize);
}
if let Some(f) = module.get_function("tl_display_f32") {
execution_engine.add_global_mapping(&f, runtime::tl_display_f32 as *const () as usize);
}
if let Some(f) = module.get_function("tl_print_f64") {
execution_engine.add_global_mapping(&f, runtime::tl_print_f64 as *const () as usize);
}
if let Some(f) = module.get_function("tl_display_f64") {
execution_engine.add_global_mapping(&f, runtime::tl_display_f64 as *const () as usize);
}
if let Some(f) = module.get_function("tl_print_bool") {
execution_engine.add_global_mapping(&f, runtime::tl_print_bool as *const () as usize);
}
if let Some(f) = module.get_function("tl_display_bool") {
execution_engine.add_global_mapping(&f, runtime::tl_display_bool as *const () as usize);
}
let f32_unary_mappings: [(&str, usize); 31] = [
("tl_f32_abs", runtime::tl_f32_abs as *const () as usize),
("tl_f32_acos", runtime::tl_f32_acos as *const () as usize),
("tl_f32_acosh", runtime::tl_f32_acosh as *const () as usize),
("tl_f32_asin", runtime::tl_f32_asin as *const () as usize),
("tl_f32_asinh", runtime::tl_f32_asinh as *const () as usize),
("tl_f32_atan", runtime::tl_f32_atan as *const () as usize),
("tl_f32_atanh", runtime::tl_f32_atanh as *const () as usize),
("tl_f32_cbrt", runtime::tl_f32_cbrt as *const () as usize),
("tl_f32_ceil", runtime::tl_f32_ceil as *const () as usize),
("tl_f32_cos", runtime::tl_f32_cos as *const () as usize),
("tl_f32_cosh", runtime::tl_f32_cosh as *const () as usize),
("tl_f32_exp", runtime::tl_f32_exp as *const () as usize),
("tl_f32_exp2", runtime::tl_f32_exp2 as *const () as usize),
(
"tl_f32_exp_m1",
runtime::tl_f32_exp_m1 as *const () as usize,
),
("tl_f32_floor", runtime::tl_f32_floor as *const () as usize),
("tl_f32_fract", runtime::tl_f32_fract as *const () as usize),
("tl_f32_ln", runtime::tl_f32_ln as *const () as usize),
("tl_f32_ln_1p", runtime::tl_f32_ln_1p as *const () as usize),
("tl_f32_log10", runtime::tl_f32_log10 as *const () as usize),
("tl_f32_log2", runtime::tl_f32_log2 as *const () as usize),
("tl_f32_recip", runtime::tl_f32_recip as *const () as usize),
("tl_f32_round", runtime::tl_f32_round as *const () as usize),
(
"tl_f32_signum",
runtime::tl_f32_signum as *const () as usize,
),
("tl_f32_sin", runtime::tl_f32_sin as *const () as usize),
("tl_f32_sinh", runtime::tl_f32_sinh as *const () as usize),
("tl_f32_sqrt", runtime::tl_f32_sqrt as *const () as usize),
("tl_f32_tan", runtime::tl_f32_tan as *const () as usize),
("tl_f32_tanh", runtime::tl_f32_tanh as *const () as usize),
(
"tl_f32_to_degrees",
runtime::tl_f32_to_degrees as *const () as usize,
),
(
"tl_f32_to_radians",
runtime::tl_f32_to_radians as *const () as usize,
),
("tl_f32_trunc", runtime::tl_f32_trunc as *const () as usize),
];
for (name, addr) in f32_unary_mappings {
if let Some(f) = module.get_function(name) {
execution_engine.add_global_mapping(&f, addr);
}
}
let f32_to_string_type = i8_ptr.fn_type(&[context.f32_type().into()], false);
add_fn("tl_f32_to_string", f32_to_string_type);
if let Some(f) = module.get_function("tl_f32_to_string") {
execution_engine.add_global_mapping(&f, runtime::tl_f32_to_string as *const () as usize);
}
let f64_to_string_type = i8_ptr.fn_type(&[context.f64_type().into()], false);
add_fn("tl_f64_to_string", f64_to_string_type);
if let Some(f) = module.get_function("tl_f64_to_string") {
execution_engine.add_global_mapping(&f, runtime::tl_f64_to_string as *const () as usize);
}
let f32_binary_mappings: [(&str, usize); 5] = [
("tl_f32_atan2", runtime::tl_f32_atan2 as *const () as usize),
(
"tl_f32_copysign",
runtime::tl_f32_copysign as *const () as usize,
),
("tl_f32_hypot", runtime::tl_f32_hypot as *const () as usize),
("tl_f32_log", runtime::tl_f32_log as *const () as usize),
("tl_f32_powf", runtime::tl_f32_powf as *const () as usize),
];
for (name, addr) in f32_binary_mappings {
if let Some(f) = module.get_function(name) {
execution_engine.add_global_mapping(&f, addr);
}
}
if let Some(f) = module.get_function("tl_f32_powi") {
execution_engine.add_global_mapping(&f, runtime::tl_f32_powi as *const () as usize);
}
let f64_unary_mappings: [(&str, usize); 31] = [
("tl_f64_abs", runtime::tl_f64_abs as *const () as usize),
("tl_f64_acos", runtime::tl_f64_acos as *const () as usize),
("tl_f64_acosh", runtime::tl_f64_acosh as *const () as usize),
("tl_f64_asin", runtime::tl_f64_asin as *const () as usize),
("tl_f64_asinh", runtime::tl_f64_asinh as *const () as usize),
("tl_f64_atan", runtime::tl_f64_atan as *const () as usize),
("tl_f64_atanh", runtime::tl_f64_atanh as *const () as usize),
("tl_f64_cbrt", runtime::tl_f64_cbrt as *const () as usize),
("tl_f64_ceil", runtime::tl_f64_ceil as *const () as usize),
("tl_f64_cos", runtime::tl_f64_cos as *const () as usize),
("tl_f64_cosh", runtime::tl_f64_cosh as *const () as usize),
("tl_f64_exp", runtime::tl_f64_exp as *const () as usize),
("tl_f64_exp2", runtime::tl_f64_exp2 as *const () as usize),
(
"tl_f64_exp_m1",
runtime::tl_f64_exp_m1 as *const () as usize,
),
("tl_f64_floor", runtime::tl_f64_floor as *const () as usize),
("tl_f64_fract", runtime::tl_f64_fract as *const () as usize),
("tl_f64_ln", runtime::tl_f64_ln as *const () as usize),
("tl_f64_ln_1p", runtime::tl_f64_ln_1p as *const () as usize),
("tl_f64_log10", runtime::tl_f64_log10 as *const () as usize),
("tl_f64_log2", runtime::tl_f64_log2 as *const () as usize),
("tl_f64_recip", runtime::tl_f64_recip as *const () as usize),
("tl_f64_round", runtime::tl_f64_round as *const () as usize),
(
"tl_f64_signum",
runtime::tl_f64_signum as *const () as usize,
),
("tl_f64_sin", runtime::tl_f64_sin as *const () as usize),
("tl_f64_sinh", runtime::tl_f64_sinh as *const () as usize),
("tl_f64_sqrt", runtime::tl_f64_sqrt as *const () as usize),
("tl_f64_tan", runtime::tl_f64_tan as *const () as usize),
("tl_f64_tanh", runtime::tl_f64_tanh as *const () as usize),
(
"tl_f64_to_degrees",
runtime::tl_f64_to_degrees as *const () as usize,
),
(
"tl_f64_to_radians",
runtime::tl_f64_to_radians as *const () as usize,
),
("tl_f64_trunc", runtime::tl_f64_trunc as *const () as usize),
];
for (name, addr) in f64_unary_mappings {
if let Some(f) = module.get_function(name) {
execution_engine.add_global_mapping(&f, addr);
}
}
let f64_binary_mappings: [(&str, usize); 5] = [
("tl_f64_atan2", runtime::tl_f64_atan2 as *const () as usize),
(
"tl_f64_copysign",
runtime::tl_f64_copysign as *const () as usize,
),
("tl_f64_hypot", runtime::tl_f64_hypot as *const () as usize),
("tl_f64_log", runtime::tl_f64_log as *const () as usize),
("tl_f64_powf", runtime::tl_f64_powf as *const () as usize),
];
for (name, addr) in f64_binary_mappings {
if let Some(f) = module.get_function(name) {
execution_engine.add_global_mapping(&f, addr);
}
}
if let Some(f) = module.get_function("tl_f64_powi") {
execution_engine.add_global_mapping(&f, runtime::tl_f64_powi as *const () as usize);
}
let i64_mappings: [(&str, usize); 5] = [
("tl_i64_abs", runtime::tl_i64_abs as *const () as usize),
(
"tl_i64_signum",
runtime::tl_i64_signum as *const () as usize,
),
("tl_i64_pow", runtime::tl_i64_pow as *const () as usize),
(
"tl_i64_div_euclid",
runtime::tl_i64_div_euclid as *const () as usize,
),
(
"tl_i64_rem_euclid",
runtime::tl_i64_rem_euclid as *const () as usize,
),
];
for (name, addr) in i64_mappings {
if let Some(f) = module.get_function(name) {
execution_engine.add_global_mapping(&f, addr);
}
}
if let Some(f) = module.get_function("tl_i64_is_positive") {
execution_engine.add_global_mapping(&f, runtime::tl_i64_is_positive as *const () as usize);
}
if let Some(f) = module.get_function("tl_i64_is_negative") {
execution_engine.add_global_mapping(&f, runtime::tl_i64_is_negative as *const () as usize);
}
let i32_mappings: [(&str, usize); 5] = [
("tl_i32_abs", runtime::tl_i32_abs as *const () as usize),
(
"tl_i32_signum",
runtime::tl_i32_signum as *const () as usize,
),
("tl_i32_pow", runtime::tl_i32_pow as *const () as usize),
(
"tl_i32_div_euclid",
runtime::tl_i32_div_euclid as *const () as usize,
),
(
"tl_i32_rem_euclid",
runtime::tl_i32_rem_euclid as *const () as usize,
),
];
for (name, addr) in i32_mappings {
if let Some(f) = module.get_function(name) {
execution_engine.add_global_mapping(&f, addr);
}
}
if let Some(f) = module.get_function("tl_i32_is_positive") {
execution_engine.add_global_mapping(&f, runtime::tl_i32_is_positive as *const () as usize);
}
if let Some(f) = module.get_function("tl_i32_is_negative") {
execution_engine.add_global_mapping(&f, runtime::tl_i32_is_negative as *const () as usize);
}
if let Some(f) = module.get_function("tl_print_i64") {
execution_engine.add_global_mapping(&f, runtime::tl_print_i64 as *const () as usize);
}
if let Some(f) = module.get_function("tl_print_i32") {
execution_engine.add_global_mapping(&f, runtime::tl_print_i32 as *const () as usize);
}
if let Some(f) = module.get_function("tl_display_i64") {
execution_engine.add_global_mapping(&f, runtime::tl_display_i64 as *const () as usize);
}
if let Some(f) = module.get_function("tl_display_i32") {
execution_engine.add_global_mapping(&f, runtime::tl_display_i32 as *const () as usize);
}
if let Some(f) = module.get_function("tl_print_char") {
execution_engine.add_global_mapping(&f, runtime::tl_print_char as *const () as usize);
}
if let Some(f) = module.get_function("tl_display_char") {
execution_engine.add_global_mapping(&f, runtime::tl_display_char as *const () as usize);
}
if let Some(f) = module.get_function("tl_print_ptr") {
execution_engine.add_global_mapping(&f, runtime::tl_print_ptr as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_new") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_new as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_new_i64") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_new_i64 as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_from_i64_array") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_from_i64_array as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_matmul") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_matmul as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_contiguous") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_contiguous as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_print") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_print as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_display") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_display as *const () as usize); }
if !is_cpu {
if let Some(f) = module.get_function("tl_tensor_print_1") {
execution_engine.add_global_mapping(&f, runtime::tl_tensor_print_1 as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_print_2") {
execution_engine.add_global_mapping(&f, runtime::tl_tensor_print_2 as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_print_3") {
execution_engine.add_global_mapping(&f, runtime::tl_tensor_print_3 as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_device_id") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_device_id as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_prepare_return") {
execution_engine.add_global_mapping(
&f,
runtime::tl_tensor_prepare_return as *const () as usize,
);
}
}
if let Some(f) = module.get_function("tl_tensor_acquire") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_acquire as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_release_safe") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_release_safe as *const () as usize); }
if let Some(f) = module.get_function("tl_qtensor_retain") { execution_engine.add_global_mapping(&f, runtime::system::tl_qtensor_retain as *const () as usize); }
if let Some(f) = module.get_function("tl_qtensor_release_safe") { execution_engine.add_global_mapping(&f, runtime::system::tl_qtensor_release_safe as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_add_scalar") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_add_scalar as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_sub_scalar") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_sub_scalar as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_mul_scalar") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_mul_scalar as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_div_scalar") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_div_scalar as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_len") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_len as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_dim") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_dim as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_get_f32_md") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_get_f32_md as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_get_i64_md") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_get_i64_md as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_neg") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_neg as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_transpose") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_transpose as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_reshape_new") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_reshape_new as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_get") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_get as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_slice") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_slice as *const () as usize); }
if let Some(f) = module.get_function("tl_register_tensor") {
execution_engine.add_global_mapping(&f, runtime::registry::tl_register_tensor as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_randn_debug") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_randn_debug as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_zeros") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_zeros as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_backward") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_backward as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_grad") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_grad as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_detach") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_detach as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_promote") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_promote as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_register") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_register as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_enable_grad") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_enable_grad as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_softmax") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_softmax as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_cross_entropy") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_cross_entropy as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_conv2d") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_conv2d as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_clamp") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_clamp as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_ones") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_ones as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_full") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_full as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_eye") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_eye as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_arange") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_arange as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_zeros_like") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_zeros_like as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_ones_like") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_ones_like as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_from_vec_f32") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_from_vec_f32 as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_to_vec_f32") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_to_vec_f32 as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_linspace") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_linspace as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_rand") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_rand as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_rand_like") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_rand_like as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_randn_like") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_randn_like as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_where_cond") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_where_cond as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_masked_fill_scalar") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_masked_fill_scalar as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_var_dim") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_var_dim as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_std_dim") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_std_dim as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_var") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_var as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_std") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_std as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_prod_dim") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_prod_dim as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_prod") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_prod as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_fill_") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_fill_ as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_cumsum") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_cumsum as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_norm") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_norm as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_topk") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_topk as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_logical_and") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_logical_and as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_logical_or") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_logical_or as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_logical_not") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_logical_not as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_expand") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_expand as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_expand_new") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_expand_new as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_stack") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_stack as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_chunk") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_chunk as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_split") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_split as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_leaky_relu") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_leaky_relu as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_elu") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_elu as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_mish") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_mish as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_mse_loss") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_mse_loss as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_l1_loss") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_l1_loss as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_bce_loss") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_bce_loss as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_nll_loss") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_nll_loss as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_linear") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_linear as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_hardswish") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_hardswish as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_hardsigmoid") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_hardsigmoid as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_group_norm") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_group_norm as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_adaptive_avg_pool2d") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_adaptive_avg_pool2d as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_pad") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_pad as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_instance_norm") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_instance_norm as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_conv1d") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_conv1d as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_kl_div_loss") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_kl_div_loss as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_conv_transpose2d") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_conv_transpose2d as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_interpolate") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_interpolate as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_sdpa") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_sdpa as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_top_k_sample") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_top_k_sample as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_top_p_sample") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_top_p_sample as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_temperature_scale") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_temperature_scale as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_repetition_penalty") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_repetition_penalty as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_dot") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_dot as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_sub_assign") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_sub_assign as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_sum") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_sum as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_add") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_add as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_sub") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_sub as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_mul") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_mul as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_div") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_div as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_rem") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_rem as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_eq") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_eq as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_neq") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_neq as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_gt") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_gt as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_lt") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_lt as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_ge") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_ge as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_le") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_le as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_pow") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_pow as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_pow_scalar") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_pow_scalar as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_add_assign") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_add_assign as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_set_f32_md") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_set_f32_md as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_mul_assign") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_mul_assign as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_div_assign") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_div_assign as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_mul_assign_scalar_f32") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_mul_assign_scalar_f32 as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_div_assign_scalar_f32") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_div_assign_scalar_f32 as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_mod_assign_scalar_f32") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_mod_assign_scalar_f32 as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_reshape_dims") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_reshape_dims as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_cat") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_cat as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_cat_i64") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_cat_i64 as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_narrow") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_narrow as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_replace_data") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_replace_data as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_scale") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_scale as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_silu") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_silu as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_cross_entropy") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_cross_entropy as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_device_id") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_device_id as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_to_device") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_to_device as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_repeat_interleave") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_repeat_interleave as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_new_causal_mask") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_new_causal_mask as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_cat2") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_cat2 as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_cat_4d") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_cat_4d as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_rms_norm") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_rms_norm as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_print_1") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_print_1 as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_print_2") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_print_2 as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_print_3") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_print_3 as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_save") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_save as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_load") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_load as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_rope_new_cos") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_rope_new_cos as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_rope_new_sin") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_rope_new_sin as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_apply_rope") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_apply_rope as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_clone") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_clone as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_free") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_free as *const () as usize); } if let Some(f) = module.get_function("tl_tensor_release") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_release as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_numel") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_numel as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_data") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_data as *const () as usize); }
if is_cpu {
if let Some(f) = module.get_function("tl_tensor_transpose_2d") {
execution_engine.add_global_mapping(&f, cpu_ffi::tl_cpu_tensor_transpose_2d as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_prepare_return") {
execution_engine.add_global_mapping(&f, cpu_ffi::tl_cpu_tensor_prepare_return as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_reshape_2d") {
execution_engine.add_global_mapping(&f, cpu_ffi::tl_cpu_tensor_reshape_2d as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_reshape_3d_to_2d") {
execution_engine.add_global_mapping(&f, cpu_ffi::tl_cpu_tensor_reshape_3d_to_2d as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_matmul_4d") {
execution_engine.add_global_mapping(&f, cpu_ffi::tl_cpu_tensor_matmul_4d as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_add_4d") {
execution_engine.add_global_mapping(&f, cpu_ffi::tl_cpu_tensor_add_4d as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_silu_4d") {
execution_engine.add_global_mapping(&f, cpu_ffi::tl_cpu_tensor_silu_4d as *const () as usize);
}
}
if let Some(f) = module.get_function("tl_kb_add_entity") {
execution_engine.add_global_mapping(&f, runtime::knowledge_base::tl_kb_add_entity as *const () as usize);
}
if let Some(f) = module.get_function("tl_kb_add_fact") {
execution_engine.add_global_mapping(&f, runtime::knowledge_base::tl_kb_add_fact as *const () as usize);
}
if let Some(f) = module.get_function("tl_kb_infer") {
execution_engine.add_global_mapping(&f, runtime::knowledge_base::tl_kb_infer as *const () as usize);
}
if let Some(f) = module.get_function("tl_kb_rule_start") {
execution_engine.add_global_mapping(&f, runtime::knowledge_base::tl_kb_rule_start as *const () as usize);
}
if let Some(f) = module.get_function("tl_kb_rule_add_head_arg_var") {
execution_engine.add_global_mapping(
&f,
runtime::knowledge_base::tl_kb_rule_add_head_arg_var as *const () as usize,
);
}
if let Some(f) = module.get_function("tl_kb_add_fact_serialized") {
execution_engine.add_global_mapping(
&f,
runtime::knowledge_base::tl_kb_add_fact_serialized as *const () as usize,
);
}
if let Some(f) = module.get_function("tl_kb_fact_args_clear") {
execution_engine.add_global_mapping(
&f,
runtime::knowledge_base::tl_kb_fact_args_clear as *const () as usize,
);
}
if let Some(f) = module.get_function("tl_kb_fact_args_add_int") {
execution_engine.add_global_mapping(
&f,
runtime::knowledge_base::tl_kb_fact_args_add_int as *const () as usize,
);
}
if let Some(f) = module.get_function("tl_kb_fact_args_add_float") {
execution_engine.add_global_mapping(
&f,
runtime::knowledge_base::tl_kb_fact_args_add_float as *const () as usize,
);
}
if let Some(f) = module.get_function("tl_kb_fact_args_add_bool") {
execution_engine.add_global_mapping(
&f,
runtime::knowledge_base::tl_kb_fact_args_add_bool as *const () as usize,
);
}
if let Some(f) = module.get_function("tl_kb_fact_args_add_entity") {
execution_engine.add_global_mapping(
&f,
runtime::knowledge_base::tl_kb_fact_args_add_entity as *const () as usize,
);
}
if let Some(f) = module.get_function("tl_kb_fact_args_add_string") {
execution_engine.add_global_mapping(
&f,
runtime::knowledge_base::tl_kb_fact_args_add_string as *const () as usize,
);
}
if let Some(f) = module.get_function("tl_kb_rule_add_head_arg_const_int") {
execution_engine.add_global_mapping(
&f,
runtime::knowledge_base::tl_kb_rule_add_head_arg_const_int as *const () as usize,
);
}
if let Some(f) = module.get_function("tl_kb_rule_add_head_arg_const_float") {
execution_engine.add_global_mapping(
&f,
runtime::knowledge_base::tl_kb_rule_add_head_arg_const_float as *const () as usize,
);
}
if let Some(f) = module.get_function("tl_kb_rule_add_head_arg_const_entity") {
execution_engine.add_global_mapping(
&f,
runtime::knowledge_base::tl_kb_rule_add_head_arg_const_entity as *const () as usize,
);
}
if let Some(f) = module.get_function("tl_kb_rule_add_body_atom") {
execution_engine.add_global_mapping(
&f,
runtime::knowledge_base::tl_kb_rule_add_body_atom as *const () as usize,
);
}
if let Some(f) = module.get_function("tl_kb_rule_add_body_atom_neg") {
execution_engine.add_global_mapping(
&f,
runtime::knowledge_base::tl_kb_rule_add_body_atom_neg as *const () as usize,
);
}
if let Some(f) = module.get_function("tl_kb_rule_add_body_arg_var") {
execution_engine.add_global_mapping(
&f,
runtime::knowledge_base::tl_kb_rule_add_body_arg_var as *const () as usize,
);
}
if let Some(f) = module.get_function("tl_kb_rule_add_body_arg_const_int") {
execution_engine.add_global_mapping(
&f,
runtime::knowledge_base::tl_kb_rule_add_body_arg_const_int as *const () as usize,
);
}
if let Some(f) = module.get_function("tl_kb_rule_add_body_arg_const_float") {
execution_engine.add_global_mapping(
&f,
runtime::knowledge_base::tl_kb_rule_add_body_arg_const_float as *const () as usize,
);
}
if let Some(f) = module.get_function("tl_kb_rule_add_body_arg_const_entity") {
execution_engine.add_global_mapping(
&f,
runtime::knowledge_base::tl_kb_rule_add_body_arg_const_entity as *const () as usize,
);
}
if let Some(f) = module.get_function("tl_kb_rule_finish") {
execution_engine
.add_global_mapping(&f, runtime::knowledge_base::tl_kb_rule_finish as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_add_assign_scalar_f32") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_add_assign_scalar_f32 as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_sub_assign_scalar_f32") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_sub_assign_scalar_f32 as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_mod_assign") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_mod_assign as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_mod_assign_scalar_f32") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_mod_assign_scalar_f32 as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_exp") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_exp as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_log") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_log as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_sqrt") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_sqrt as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_sin") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_sin as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_cos") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_cos as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_relu") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_relu as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_gelu") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_gelu as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_tril") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_tril as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_sum_dim") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_sum_dim as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_embedding") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_embedding as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_save") {
execution_engine.add_global_mapping(&f, runtime::tl_tensor_save as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_load") {
execution_engine.add_global_mapping(&f, runtime::tl_tensor_load as *const () as usize);
}
if let Some(f) = module.get_function("tl_save_all_params") {
execution_engine.add_global_mapping(&f, runtime::tl_save_all_params as *const () as usize);
}
if let Some(f) = module.get_function("tl_add_parameter") {
execution_engine.add_global_mapping(&f, runtime::tl_add_parameter as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_map_new") {
execution_engine.add_global_mapping(&f, runtime::tl_tensor_map_new as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_map_insert") {
execution_engine.add_global_mapping(&f, runtime::tl_tensor_map_insert as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_map_get") {
execution_engine.add_global_mapping(&f, runtime::tl_tensor_map_get as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_map_free") {
execution_engine.add_global_mapping(&f, runtime::tl_tensor_map_free as *const () as usize);
}
if let Some(f) = module.get_function("tl_mem_unregister") {
execution_engine
.add_global_mapping(&f, runtime::memory_manager::tl_mem_unregister as *const () as usize);
}
if let Some(f) = module.get_function("tl_load_all_params") {
execution_engine.add_global_mapping(&f, runtime::tl_load_all_params as *const () as usize);
}
if let Some(f) = module.get_function("tl_register_parameter") {
execution_engine.add_global_mapping(&f, runtime::tl_register_parameter as *const () as usize);
}
if let Some(f) = module.get_function("tl_string_new") {
execution_engine.add_global_mapping(&f, runtime::tl_string_new as *const () as usize);
}
if let Some(f) = module.get_function("tl_varbuilder_get") {
execution_engine.add_global_mapping(&f, runtime::tl_varbuilder_get as *const () as usize);
}
if let Some(f) = module.get_function("tl_varbuilder_get_from_tensor") {
execution_engine.add_global_mapping(&f, runtime::tl_varbuilder_get_from_tensor as *const () as usize);
}
if let Some(f) = module.get_function("tl_varbuilder_grad") {
execution_engine.add_global_mapping(&f, runtime::tl_varbuilder_grad as *const () as usize);
}
if let Some(f) = module.get_function("tl_update_all_params") {
execution_engine.add_global_mapping(&f, runtime::tl_update_all_params as *const () as usize);
}
if let Some(f) = module.get_function("tl_get_memory_mb") {
execution_engine.add_global_mapping(&f, runtime::tl_get_memory_mb as *const () as usize);
}
if let Some(f) = module.get_function("tl_mem_purge") {
execution_engine.add_global_mapping(&f, runtime::tl_mem_purge as *const () as usize);
}
if let Some(f) = module.get_function("tl_get_memory_bytes") {
execution_engine.add_global_mapping(&f, runtime::tl_get_memory_bytes as *const () as usize);
}
if let Some(f) = module.get_function("tl_get_metal_pool_bytes") {
if is_cpu {
execution_engine.add_global_mapping(&f, cpu_ffi::tl_cpu_get_pool_bytes as *const () as usize);
} else {
execution_engine.add_global_mapping(&f, runtime::tl_get_metal_pool_bytes as *const () as usize);
}
}
if let Some(f) = module.get_function("tl_get_metal_pool_mb") {
if is_cpu {
execution_engine.add_global_mapping(&f, cpu_ffi::tl_cpu_get_pool_mb as *const () as usize);
} else {
execution_engine.add_global_mapping(&f, runtime::tl_get_metal_pool_mb as *const () as usize);
}
}
if let Some(f) = module.get_function("tl_get_metal_pool_count") {
if is_cpu {
execution_engine.add_global_mapping(&f, cpu_ffi::tl_cpu_get_pool_count as *const () as usize);
} else {
execution_engine.add_global_mapping(&f, runtime::tl_get_metal_pool_count as *const () as usize);
}
}
if let Some(f) = module.get_function("tl_metal_sync") {
execution_engine.add_global_mapping(&f, runtime::tl_metal_sync as *const () as usize);
}
if let Some(f) = module.get_function("tl_system_mem_report") {
execution_engine.add_global_mapping(&f, runtime::tl_system_mem_report as *const () as usize);
}
if let Some(f) = module.get_function("tl_trace_mem") {
execution_engine.add_global_mapping(&f, runtime::tl_trace_mem as *const () as usize);
}
if let Some(f) = module.get_function("tl_get_pool_count") {
execution_engine.add_global_mapping(&f, runtime::tl_get_pool_count as *const () as usize);
}
if let Some(f) = module.get_function("tl_get_refcount_count") {
execution_engine.add_global_mapping(&f, runtime::tl_get_refcount_count as *const () as usize);
}
if let Some(f) = module.get_function("tl_get_scope_depth") {
execution_engine.add_global_mapping(&f, runtime::tl_get_scope_depth as *const () as usize);
}
if let Some(f) = module.get_function("tl_args_count") {
execution_engine.add_global_mapping(&f, runtime::args::tl_args_count as *const () as usize);
}
if let Some(f) = module.get_function("tl_args_get") {
execution_engine.add_global_mapping(&f, runtime::args::tl_args_get as *const () as usize);
}
if let Some(f) = module.get_function("tl_string_to_i64") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_string_to_i64 as *const () as usize);
}
if let Some(f) = module.get_function("tl_string_char_at") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_string_char_at as *const () as usize);
}
if let Some(f) = module.get_function("tl_string_len") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_string_len as *const () as usize);
}
if let Some(f) = module.get_function("tl_mem_enter_scope") {
execution_engine
.add_global_mapping(&f, runtime::memory_manager::tl_mem_enter_scope as *const () as usize);
}
if let Some(f) = module.get_function("tl_mem_exit_scope") {
execution_engine
.add_global_mapping(&f, runtime::memory_manager::tl_mem_exit_scope as *const () as usize);
}
if let Some(f) = module.get_function("tl_mem_register_struct") {
execution_engine
.add_global_mapping(&f, runtime::memory_manager::tl_mem_register_struct as *const () as usize);
}
if let Some(f) = module.get_function("tl_mem_register_struct_named") {
execution_engine.add_global_mapping(
&f,
runtime::memory_manager::tl_mem_register_struct_named as *const () as usize,
);
}
if let Some(f) = module.get_function("tl_mem_register_tensor") {
execution_engine
.add_global_mapping(&f, runtime::memory_manager::tl_mem_register_tensor as *const () as usize);
}
if let Some(f) = module.get_function("tl_mem_unregister") {
execution_engine
.add_global_mapping(&f, runtime::memory_manager::tl_mem_unregister as *const () as usize);
}
if let Some(f) = module.get_function("tl_ptr_dec_ref") {
execution_engine.add_global_mapping(
&f,
runtime::memory_manager::tl_ptr_dec_ref as *const () as usize,
);
}
if let Some(f) = module.get_function("tl_ptr_inc_ref") {
execution_engine.add_global_mapping(
&f,
runtime::memory_manager::tl_ptr_inc_ref as *const () as usize,
);
}
if let Some(f) = module.get_function("tl_ptr_acquire") {
execution_engine.add_global_mapping(
&f,
runtime::memory_manager::tl_ptr_acquire as *const () as usize,
);
}
if let Some(f) = module.get_function("tl_ptr_release") {
execution_engine.add_global_mapping(
&f,
runtime::memory_manager::tl_ptr_release as *const () as usize,
);
}
if let Some(f) = module.get_function("tl_mem_free") {
execution_engine.add_global_mapping(&f, runtime::tl_mem_free as *const () as usize);
}
if let Some(f) = module.get_function("tl_arena_init") {
execution_engine.add_global_mapping(&f, runtime::arena::tl_arena_init as *const () as usize);
}
if let Some(f) = module.get_function("tl_arena_alloc") {
execution_engine.add_global_mapping(&f, runtime::arena::tl_arena_alloc as *const () as usize);
}
if let Some(f) = module.get_function("tl_arena_free") {
execution_engine.add_global_mapping(&f, runtime::arena::tl_arena_free as *const () as usize);
}
if let Some(f) = module.get_function("tl_arena_is_active") {
execution_engine.add_global_mapping(&f, runtime::arena::tl_arena_is_active as *const () as usize);
}
if let Some(f) = module.get_function("tl_arena_reset") {
execution_engine.add_global_mapping(&f, runtime::arena::tl_arena_reset as *const () as usize);
}
if let Some(f) = module.get_function("tl_arena_get_offset") {
execution_engine.add_global_mapping(&f, runtime::arena::tl_arena_get_offset as *const () as usize);
}
if let Some(f) = module.get_function("tl_arena_get_capacity") {
execution_engine.add_global_mapping(&f, runtime::arena::tl_arena_get_capacity as *const () as usize);
}
if let Some(f) = module.get_function("tl_arena_malloc") {
execution_engine.add_global_mapping(&f, runtime::arena::tl_arena_malloc as *const () as usize);
}
if let Some(f) = module.get_function("tl_update_all_params") {
execution_engine.add_global_mapping(&f, runtime::tl_update_all_params as *const () as usize);
}
if let Some(f) = module.get_function("tl_varbuilder_grad") {
execution_engine.add_global_mapping(&f, runtime::tl_varbuilder_grad as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_reshape_dims") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_reshape_dims as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_map_save") {
execution_engine.add_global_mapping(&f, runtime::tl_tensor_map_save as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_map_load") {
execution_engine.add_global_mapping(&f, runtime::tl_tensor_map_load as *const () as usize);
}
if let Some(f) = module.get_function("tl_alloc_tmp") {
execution_engine.add_global_mapping(&f, runtime::tl_alloc_tmp as *const () as usize);
}
if let Some(f) = module.get_function("tl_free_tmp") {
execution_engine.add_global_mapping(&f, runtime::tl_free_tmp as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_argmax") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_argmax as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_to_i64") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_to_i64 as *const () as usize);
}
let _tensor_type = Type::Tensor(Box::new(Type::F32), 1);
let _tensor_type_local = Type::Tensor(Box::new(Type::I64), 1);
add_fn("tl_tensor_tan", unary_type);
if let Some(f) = module.get_function("tl_tensor_tan") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_tan as *const () as usize); }
add_fn("tl_tensor_abs", unary_type);
if let Some(f) = module.get_function("tl_tensor_abs") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_abs as *const () as usize); }
add_fn("tl_tensor_sigmoid", unary_type);
if let Some(f) = module.get_function("tl_tensor_sigmoid") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_sigmoid as *const () as usize); }
add_fn("tl_tensor_tanh", unary_type);
if let Some(f) = module.get_function("tl_tensor_tanh") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_tanh as *const () as usize); }
add_fn("tl_tensor_max", unary_type);
if let Some(f) = module.get_function("tl_tensor_max") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_max as *const () as usize); }
add_fn("tl_tensor_max_dim", sum_dim_type);
if let Some(f) = module.get_function("tl_tensor_max_dim") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_max_dim as *const () as usize); }
add_fn("tl_tensor_min", unary_type);
if let Some(f) = module.get_function("tl_tensor_min") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_min as *const () as usize); }
add_fn("tl_tensor_min_dim", sum_dim_type);
if let Some(f) = module.get_function("tl_tensor_min_dim") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_min_dim as *const () as usize); }
add_fn("tl_tensor_mean", unary_type);
if let Some(f) = module.get_function("tl_tensor_mean") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_mean as *const () as usize); }
add_fn("tl_tensor_mean_dim", sum_dim_type);
if let Some(f) = module.get_function("tl_tensor_mean_dim") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_mean_dim as *const () as usize); }
add_fn("tl_tensor_argmin", sum_dim_type);
if let Some(f) = module.get_function("tl_tensor_argmin") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_argmin as *const () as usize); }
add_fn("tl_tensor_argmax", sum_dim_type);
if let Some(f) = module.get_function("tl_tensor_argmax") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_argmax as *const () as usize); }
if let Some(f) = module.get_function("tl_tokenizer_new") {
execution_engine.add_global_mapping(&f, runtime::llm::tl_tokenizer_new as *const () as usize);
}
if let Some(f) = module.get_function("tl_tokenizer_encode") {
execution_engine.add_global_mapping(&f, runtime::llm::tl_tokenizer_encode as *const () as usize);
}
if let Some(f) = module.get_function("tl_tokenizer_encode_chat") {
execution_engine.add_global_mapping(&f, runtime::llm::tl_tokenizer_encode_chat as *const () as usize);
}
if let Some(f) = module.get_function("tl_tokenizer_encode_chat_zephyr") {
execution_engine.add_global_mapping(&f, runtime::llm::tl_tokenizer_encode_chat_zephyr as *const () as usize);
}
if let Some(f) = module.get_function("tl_tokenizer_decode") {
execution_engine.add_global_mapping(&f, runtime::llm::tl_tokenizer_decode as *const () as usize);
}
if let Some(f) = module.get_function("tl_gguf_load") {
execution_engine.add_global_mapping(&f, runtime::tl_gguf_load as *const () as usize);
}
if !is_cpu {
if let Some(f) = module.get_function("tl_tensor_map_get") {
execution_engine.add_global_mapping(&f, runtime::tl_tensor_map_get as *const () as usize);
}
}
if let Some(f) = module.get_function("tl_tensor_cat") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_cat as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_silu") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_silu as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_apply_rope") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_apply_rope as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_rms_norm") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_rms_norm as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_cat2") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_cat2 as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_cat_4d") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_cat_4d as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_transpose_2d") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_transpose_2d as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_matmul_4d") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_matmul_4d as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_add_4d") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_add_4d as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_silu_4d") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_silu_4d as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_scale") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_scale as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_rope_new_cos") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_rope_new_cos as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_rope_new_sin") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_rope_new_sin as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_new_causal_mask") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_new_causal_mask as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_cat_i64") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_cat_i64 as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_narrow") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_narrow as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_repeat_interleave") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_repeat_interleave as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_get_shape") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_get_shape as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_reshape_2d") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_reshape_2d as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_reshape_3d_to_2d") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_reshape_3d_to_2d as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_map_get_1d") {
execution_engine.add_global_mapping(&f, runtime::tl_tensor_map_get as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_from_vec_u8") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_from_vec_u8 as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_from_vec_u8_f32_shape") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_from_vec_u8_f32_shape as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_from_u8_labels") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_from_u8_labels as *const () as usize);
}
if let Some(f) = module.get_function("tl_file_read_binary_all") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_file_read_binary_all as *const () as usize);
}
if let Some(f) = module.get_function("tl_file_write_binary") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_file_write_binary as *const () as usize);
}
if let Some(f) = module.get_function("tl_image_load_grayscale") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_image_load_grayscale as *const () as usize);
}
if let Some(f) = module.get_function("tl_image_width") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_image_width as *const () as usize);
}
if let Some(f) = module.get_function("tl_image_height") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_image_height as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_to_f32") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_to_f32 as *const () as usize);
}
if let Some(f) = module.get_function("tl_tensor_to_i64") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_to_i64 as *const () as usize);
}
let _tensor_type = Type::Tensor(Box::new(Type::F32), 1);
let f32_unary_methods = [
"abs",
"acos",
"acosh",
"asin",
"asinh",
"atan",
"atanh",
"cbrt",
"ceil",
"cos",
"cosh",
"exp",
"exp2",
"exp_m1",
"floor",
"fract",
"ln",
"ln_1p",
"log10",
"log2",
"recip",
"round",
"signum",
"sin",
"sinh",
"sqrt",
"tan",
"tanh",
"to_degrees",
"to_radians",
"trunc",
];
for _name in f32_unary_methods {
}
let f32_binary_methods = ["atan2", "copysign", "hypot", "log", "powf"];
for _name in f32_binary_methods {
}
let f64_unary_methods = [
"abs",
"acos",
"acosh",
"asin",
"asinh",
"atan",
"atanh",
"cbrt",
"ceil",
"cos",
"cosh",
"exp",
"exp2",
"exp_m1",
"floor",
"fract",
"ln",
"ln_1p",
"log10",
"log2",
"recip",
"round",
"signum",
"sin",
"sinh",
"sqrt",
"tan",
"tanh",
"to_degrees",
"to_radians",
"trunc",
];
for _name in f64_unary_methods {
}
let f64_binary_methods = ["atan2", "copysign", "hypot", "log", "powf"];
for _name in f64_binary_methods {
}
let i64_unary_methods = ["abs", "signum"];
for _name in i64_unary_methods {
}
let i64_binary_methods = ["div_euclid", "rem_euclid", "pow"];
for _name in i64_binary_methods {
}
let i32_unary_methods = ["abs", "signum"];
for _name in i32_unary_methods {
}
let i32_binary_methods = ["div_euclid", "rem_euclid", "pow"];
for _name in i32_binary_methods {
}
let tensor_reshape_dims_type = void_ptr.fn_type(
&[
void_ptr.into(), context.ptr_type(inkwell::AddressSpace::default()).into(), context.i64_type().into(), ],
false,
);
module.add_function("tl_tensor_reshape_dims", tensor_reshape_dims_type, None);
let tensor_reshape_type = void_ptr.fn_type(&[void_ptr.into(), void_ptr.into()], false);
module.add_function("tl_tensor_reshape", tensor_reshape_type, None);
let varbuilder_get_type =
void_ptr.fn_type(&[i8_ptr.into(), i64_type.into(), usize_ptr.into()], false);
module.add_function("tl_varbuilder_get", varbuilder_get_type, None);
let varbuilder_get_tensor_type = void_ptr.fn_type(&[i8_ptr.into(), void_ptr.into()], false);
module.add_function(
"tl_varbuilder_get_from_tensor",
varbuilder_get_tensor_type,
None,
);
let update_params_type = void_type.fn_type(&[context.f32_type().into()], false);
module.add_function("tl_update_all_params", update_params_type, None);
let varbuilder_grad_type = void_ptr.fn_type(&[i8_ptr.into()], false);
module.add_function("tl_varbuilder_grad", varbuilder_grad_type, None);
let backward_type = void_type.fn_type(&[void_ptr.into()], false);
module.add_function("tl_tensor_backward", backward_type, None);
let grad_type = void_ptr.fn_type(&[void_ptr.into()], false);
module.add_function("tl_tensor_grad", grad_type, None);
let detach_type = void_ptr.fn_type(&[void_ptr.into(), context.bool_type().into()], false);
module.add_function("tl_tensor_detach", detach_type, None);
let softmax_type = void_ptr.fn_type(&[void_ptr.into(), i64_type.into()], false);
module.add_function("tl_tensor_softmax", softmax_type, None);
let ce_type = void_ptr.fn_type(&[void_ptr.into(), void_ptr.into()], false);
module.add_function("tl_tensor_cross_entropy", ce_type, None);
let save_type = void_type.fn_type(&[i8_ptr.into(), void_ptr.into()], false);
module.add_function("tl_tensor_save", save_type, None);
let load_type = void_ptr.fn_type(&[i8_ptr.into()], false);
module.add_function("tl_tensor_load", load_type, None);
let cast_type = void_ptr.fn_type(&[void_ptr.into()], false);
add_fn("tl_tensor_to_f32", cast_type);
if let Some(f) = module.get_function("tl_tensor_to_f32") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_to_f32 as *const () as usize); }
add_fn("tl_tensor_to_i64", cast_type);
if let Some(f) = module.get_function("tl_tensor_to_i64") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_to_i64 as *const () as usize); }
let save_all_type = void_type.fn_type(&[i8_ptr.into()], false);
module.add_function("tl_save_all_params", save_all_type, None);
let add_param_type = void_type.fn_type(&[void_ptr.into(), void_ptr.into()], false);
module.add_function("tl_add_parameter", add_param_type, None);
let argmax_type = void_ptr.fn_type(
&[void_ptr.into(), i64_type.into(), context.bool_type().into()],
false,
);
module.add_function("tl_tensor_argmax", argmax_type, None);
let item_type = f32_type.fn_type(&[void_ptr.into()], false);
module.add_function("tl_tensor_item", item_type, None);
if let Some(f) = module.get_function("tl_tensor_item") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_item as *const () as usize); }
let item_i64_type = i64_type.fn_type(&[void_ptr.into()], false);
module.add_function("tl_tensor_item_i64", item_i64_type, None);
if let Some(f) = module.get_function("tl_tensor_item_i64") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_item_i64 as *const () as usize); }
let to_i64_type = void_ptr.fn_type(&[void_ptr.into()], false);
module.add_function("tl_tensor_to_i64", to_i64_type, None);
let shape_type = void_ptr.fn_type(&[void_ptr.into()], false);
module.add_function("tl_tensor_shape", shape_type, None);
if let Some(f) = module.get_function("tl_tensor_shape") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_shape_vec as *const () as usize); }
let load_all_type = void_type.fn_type(&[i8_ptr.into()], false);
module.add_function("tl_load_all_params", load_all_type, None);
let sub_assign_type = void_type.fn_type(&[void_ptr.into(), void_ptr.into()], false);
module.add_function("tl_tensor_sub_assign", sub_assign_type, None);
let add_param_type = void_type.fn_type(&[i8_ptr.into(), void_ptr.into()], false);
module.add_function("tl_add_parameter", add_param_type, None);
let reg_param_type = void_ptr.fn_type(&[void_ptr.into()], false);
module.add_function("tl_register_parameter", reg_param_type, None);
let conv2d_type = void_ptr.fn_type(
&[
void_ptr.into(),
void_ptr.into(),
i64_type.into(),
i64_type.into(),
],
false,
);
module.add_function("tl_tensor_conv2d", conv2d_type, None);
if let Some(f) = module.get_function("tl_tensor_conv2d") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_conv2d_simple_wrapper as *const () as usize); }
let batch_norm_type = void_ptr.fn_type(
&[
void_ptr.into(), void_ptr.into(), void_ptr.into(), void_ptr.into(), void_ptr.into(), context.bool_type().into(), f64_type.into(), f64_type.into(), ],
false,
);
module.add_function("tl_tensor_batch_norm", batch_norm_type, None);
if let Some(f) = module.get_function("tl_tensor_batch_norm") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_batch_norm as *const () as usize); }
let layer_norm_type = void_ptr.fn_type(
&[void_ptr.into(), void_ptr.into(), void_ptr.into(), f64_type.into()],
false,
);
module.add_function("tl_tensor_layer_norm", layer_norm_type, None);
if let Some(f) = module.get_function("tl_tensor_layer_norm") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_layer_norm as *const () as usize); }
let dropout_type = void_ptr.fn_type(
&[void_ptr.into(), f64_type.into(), context.bool_type().into()],
false,
);
module.add_function("tl_tensor_dropout", dropout_type, None);
if let Some(f) = module.get_function("tl_tensor_dropout") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_dropout as *const () as usize); }
module.add_function("tl_tensor_dropout2d", dropout_type, None);
if let Some(f) = module.get_function("tl_tensor_dropout2d") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_dropout2d as *const () as usize); }
let pool2d_type = void_ptr.fn_type(
&[void_ptr.into(), i64_type.into(), i64_type.into(), i64_type.into()],
false,
);
module.add_function("tl_tensor_max_pool2d", pool2d_type, None);
if let Some(f) = module.get_function("tl_tensor_max_pool2d") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_max_pool2d as *const () as usize); }
module.add_function("tl_tensor_avg_pool2d", pool2d_type, None);
if let Some(f) = module.get_function("tl_tensor_avg_pool2d") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_avg_pool2d as *const () as usize); }
let clamp_type = void_ptr.fn_type(&[void_ptr.into(), f64_type.into(), f64_type.into()], false);
module.add_function("tl_tensor_clamp", clamp_type, None);
if let Some(f) = module.get_function("tl_tensor_clamp") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_clamp as *const () as usize); }
let ones_type = void_ptr.fn_type(
&[
i64_type.into(),
usize_ptr.into(),
context.bool_type().into(),
],
false,
);
module.add_function("tl_tensor_ones", ones_type, None);
let i8_ptr = context.ptr_type(AddressSpace::default());
let str_concat_type = i8_ptr.fn_type(&[i8_ptr.into(), i8_ptr.into()], false);
module.add_function("tl_string_concat", str_concat_type, None);
let file_open_type = void_ptr.fn_type(&[i8_ptr.into(), i8_ptr.into()], false);
module.add_function("tl_file_open", file_open_type, None);
let file_read_type = i8_ptr.fn_type(&[void_ptr.into()], false);
module.add_function("tl_file_read_string", file_read_type, None);
let file_write_type = void_type.fn_type(&[void_ptr.into(), i8_ptr.into()], false);
module.add_function("tl_file_write_string", file_write_type, None);
let file_close_type = void_type.fn_type(&[void_ptr.into()], false);
module.add_function("tl_file_close", file_close_type, None);
let path_new_type = void_ptr.fn_type(&[i8_ptr.into()], false);
module.add_function("tl_path_new", path_new_type, None);
let path_join_type = void_ptr.fn_type(&[void_ptr.into(), i8_ptr.into()], false);
module.add_function("tl_path_join", path_join_type, None);
let path_exists_type = context.bool_type().fn_type(&[void_ptr.into()], false);
module.add_function("tl_path_exists", path_exists_type, None);
let path_is_dir_type = context.bool_type().fn_type(&[void_ptr.into()], false);
module.add_function("tl_path_is_dir", path_is_dir_type, None);
let path_is_file_type = context.bool_type().fn_type(&[void_ptr.into()], false);
module.add_function("tl_path_is_file", path_is_file_type, None);
let path_to_str_type = i8_ptr.fn_type(&[void_ptr.into()], false);
module.add_function("tl_path_to_string", path_to_str_type, None);
let path_free_type = void_type.fn_type(&[void_ptr.into()], false);
module.add_function("tl_path_free", path_free_type, None);
let http_dl_type = context
.bool_type()
.fn_type(&[i8_ptr.into(), i8_ptr.into()], false);
module.add_function("tl_http_download", http_dl_type, None);
let http_get_type = i8_ptr.fn_type(&[i8_ptr.into()], false);
module.add_function("tl_http_get", http_get_type, None);
let env_get_type = i8_ptr.fn_type(&[i8_ptr.into()], false);
module.add_function("tl_env_get", env_get_type, None);
let env_set_type = void_type.fn_type(&[i8_ptr.into(), i8_ptr.into()], false);
module.add_function("tl_env_set", env_set_type, None);
let file_append_type = context.bool_type().fn_type(&[i8_ptr.into(), i8_ptr.into()], false);
module.add_function("tl_file_append", file_append_type, None);
let file_delete_type = context.bool_type().fn_type(&[i8_ptr.into()], false);
module.add_function("tl_file_delete", file_delete_type, None);
let file_create_dir_type = context.bool_type().fn_type(&[i8_ptr.into()], false);
module.add_function("tl_file_create_dir", file_create_dir_type, None);
let file_list_dir_type = void_ptr.fn_type(&[i8_ptr.into()], false);
module.add_function("tl_file_list_dir", file_list_dir_type, None);
let path_parent_type = i8_ptr.fn_type(&[void_ptr.into()], false);
module.add_function("tl_path_parent", path_parent_type, None);
let path_file_name_type = i8_ptr.fn_type(&[void_ptr.into()], false);
module.add_function("tl_path_file_name", path_file_name_type, None);
let path_extension_type = i8_ptr.fn_type(&[void_ptr.into()], false);
module.add_function("tl_path_extension", path_extension_type, None);
let system_exit_type = void_type.fn_type(&[context.i64_type().into()], false);
module.add_function("tl_system_exit", system_exit_type, None);
let system_platform_type = i8_ptr.fn_type(&[], false);
module.add_function("tl_system_platform", system_platform_type, None);
let system_command_type = i8_ptr.fn_type(&[void_ptr.into()], false);
module.add_function("tl_system_command", system_command_type, None);
let system_time_type = context.f32_type().fn_type(&[], false);
module.add_function("tl_system_time", system_time_type, None);
let system_sleep_type = void_type.fn_type(&[context.f32_type().into()], false);
module.add_function("tl_system_sleep", system_sleep_type, None);
if let Some(f) = module.get_function("tl_string_concat") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_string_concat as *const () as usize);
}
if let Some(f) = module.get_function("tl_string_from_int") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_string_from_int as *const () as usize);
}
if let Some(f) = module.get_function("tl_file_open") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_file_open as *const () as usize);
}
if let Some(f) = module.get_function("tl_file_read_string") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_file_read_string as *const () as usize);
}
if let Some(f) = module.get_function("tl_file_write_string") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_file_write_string as *const () as usize);
}
if let Some(f) = module.get_function("tl_file_close") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_file_close as *const () as usize);
}
if let Some(f) = module.get_function("tl_path_new") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_path_new as *const () as usize);
}
if let Some(f) = module.get_function("tl_path_join") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_path_join as *const () as usize);
}
if let Some(f) = module.get_function("tl_path_exists") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_path_exists as *const () as usize);
}
if let Some(f) = module.get_function("tl_path_is_dir") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_path_is_dir as *const () as usize);
}
if let Some(f) = module.get_function("tl_path_is_file") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_path_is_file as *const () as usize);
}
if let Some(f) = module.get_function("tl_path_to_string") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_path_to_string as *const () as usize);
}
if let Some(f) = module.get_function("tl_path_free") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_path_free as *const () as usize);
}
if let Some(f) = module.get_function("tl_http_download") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_http_download as *const () as usize);
}
if let Some(f) = module.get_function("tl_http_get") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_http_get as *const () as usize);
}
if let Some(f) = module.get_function("tl_env_get") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_env_get as *const () as usize);
}
if let Some(f) = module.get_function("tl_env_set") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_env_set as *const () as usize);
}
if let Some(f) = module.get_function("tl_system_time") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_system_time as *const () as usize);
}
if let Some(f) = module.get_function("tl_system_sleep") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_system_sleep as *const () as usize);
}
if let Some(f) = module.get_function("tl_file_append") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_file_append as *const () as usize);
}
if let Some(f) = module.get_function("tl_file_delete") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_file_delete as *const () as usize);
}
if let Some(f) = module.get_function("tl_file_create_dir") {
execution_engine.add_global_mapping(&f, runtime::file_io::tl_file_create_dir as *const () as usize);
}
if let Some(f) = module.get_function("tl_file_list_dir") {
execution_engine.add_global_mapping(&f, runtime::file_io::tl_file_list_dir as *const () as usize);
}
if let Some(f) = module.get_function("tl_path_parent") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_path_parent as *const () as usize);
}
if let Some(f) = module.get_function("tl_path_file_name") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_path_file_name as *const () as usize);
}
if let Some(f) = module.get_function("tl_path_extension") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_path_extension as *const () as usize);
}
if let Some(f) = module.get_function("tl_system_exit") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_system_exit as *const () as usize);
}
if let Some(f) = module.get_function("tl_system_platform") {
execution_engine.add_global_mapping(&f, runtime::system::tl_system_platform as *const () as usize);
}
if let Some(f) = module.get_function("tl_system_command") {
execution_engine.add_global_mapping(&f, runtime::system::tl_system_command as *const () as usize);
}
if let Some(f) = module.get_function("tl_read_line") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_read_line as *const () as usize);
}
if let Some(f) = module.get_function("tl_mem_enter_scope") {
execution_engine
.add_global_mapping(&f, runtime::memory_manager::tl_mem_enter_scope as *const () as usize);
}
if let Some(f) = module.get_function("tl_mem_exit_scope") {
execution_engine
.add_global_mapping(&f, runtime::memory_manager::tl_mem_exit_scope as *const () as usize);
}
if let Some(f) = module.get_function("tl_mem_register_struct") {
execution_engine
.add_global_mapping(&f, runtime::memory_manager::tl_mem_register_struct as *const () as usize);
}
if let Some(f) = module.get_function("tl_mem_register_tensor") {
execution_engine
.add_global_mapping(&f, runtime::memory_manager::tl_mem_register_tensor as *const () as usize);
}
if let Some(f) = module.get_function("tl_mem_unregister") {
execution_engine
.add_global_mapping(&f, runtime::memory_manager::tl_mem_unregister as *const () as usize);
}
if let Some(f) = module.get_function("tl_query") {
execution_engine.add_global_mapping(&f, runtime::logic::tl_query as *const () as usize);
}
let kb_entity_name_type = i8_ptr.fn_type(&[i64_type.into()], false);
add_fn_typed("tl_kb_entity_name", kb_entity_name_type, Type::String("String".to_string()), ret_types);
if let Some(f) = module.get_function("tl_kb_entity_name") {
execution_engine.add_global_mapping(&f, runtime::logic::tl_kb_entity_name as *const () as usize);
}
let get_memory_type = i64_type.fn_type(&[], false);
module.add_function("tl_get_memory_mb", get_memory_type, None);
let get_metal_pool_bytes_type = i64_type.fn_type(&[], false);
module.add_function("tl_get_metal_pool_bytes", get_metal_pool_bytes_type, None);
let get_metal_pool_mb_type = i64_type.fn_type(&[], false);
module.add_function("tl_get_metal_pool_mb", get_metal_pool_mb_type, None);
let get_metal_pool_count_type = i64_type.fn_type(&[], false);
module.add_function("tl_get_metal_pool_count", get_metal_pool_count_type, None);
let metal_sync_type = context.void_type().fn_type(&[], false);
module.add_function("tl_metal_sync", metal_sync_type, None);
let trace_type = context.void_type().fn_type(
&[
i8_ptr.into(),
context.i32_type().into(),
context.i32_type().into(),
i8_ptr.into(),
],
false,
);
module.add_function("tl_trace_mem", trace_type, None);
module.add_function("tl_get_pool_count", get_memory_type, None);
module.add_function("tl_get_refcount_count", get_memory_type, None);
module.add_function("tl_get_scope_depth", get_memory_type, None);
let void_type = context.void_type();
let ptr_type = context.ptr_type(inkwell::AddressSpace::default());
let mem_enter_type = void_type.fn_type(&[], false);
module.add_function("tl_mem_enter_scope", mem_enter_type, None);
let mem_exit_type = void_type.fn_type(&[], false);
module.add_function("tl_mem_exit_scope", mem_exit_type, None);
let mem_register_struct_type = void_type.fn_type(&[ptr_type.into()], false);
module.add_function("tl_mem_register_struct", mem_register_struct_type, None);
let mem_register_tensor_type = void_type.fn_type(&[ptr_type.into()], false);
module.add_function("tl_mem_register_tensor", mem_register_tensor_type, None);
let mem_unregister_type = void_type.fn_type(&[ptr_type.into()], false);
module.add_function("tl_mem_unregister", mem_unregister_type, None);
let reg_struct_named_type = void_type.fn_type(&[ptr_type.into(), ptr_type.into()], false);
module.add_function("tl_mem_register_struct_named", reg_struct_named_type, None);
let ptr_acquire_type = void_type.fn_type(&[ptr_type.into()], false);
module.add_function("tl_ptr_acquire", ptr_acquire_type, None);
let pool_acquire_type = ptr_type.fn_type(&[i64_type.into()], false);
module.add_function("tl_pool_acquire", pool_acquire_type, None);
let pool_release_type = void_type.fn_type(&[ptr_type.into(), i64_type.into()], false);
module.add_function("tl_pool_release", pool_release_type, None);
let kv_new_type = void_type.fn_type(&[ptr_type.into(), i64_type.into()], false);
add_fn("tl_kvcache_new", kv_new_type);
if let Some(f) = module.get_function("tl_kvcache_new") {
execution_engine.add_global_mapping(&f, runtime::llm::tl_kvcache_new as *const () as usize);
}
let kv_free_type = void_type.fn_type(&[ptr_type.into()], false);
add_fn("tl_kvcache_free", kv_free_type);
if let Some(f) = module.get_function("tl_kvcache_free") {
execution_engine.add_global_mapping(&f, runtime::llm::tl_kvcache_free as *const () as usize);
}
let kv_clear_type = void_type.fn_type(&[ptr_type.into()], false);
add_fn("tl_kvcache_clear", kv_clear_type);
if let Some(f) = module.get_function("tl_kvcache_clear") {
execution_engine.add_global_mapping(&f, runtime::llm::tl_kvcache_clear as *const () as usize);
}
let kv_len_type = i64_type.fn_type(&[ptr_type.into()], false);
add_fn("tl_kvcache_len", kv_len_type);
if let Some(f) = module.get_function("tl_kvcache_len") {
execution_engine.add_global_mapping(&f, runtime::llm::tl_kvcache_len as *const () as usize);
}
let kv_resize_type = void_type.fn_type(&[ptr_type.into(), i64_type.into()], false);
add_fn("tl_kvcache_resize", kv_resize_type);
if let Some(f) = module.get_function("tl_kvcache_resize") {
execution_engine.add_global_mapping(&f, runtime::llm::tl_kvcache_resize as *const () as usize);
}
let kv_get_type = ptr_type.fn_type(&[ptr_type.into(), i64_type.into()], false);
add_fn("tl_kvcache_get_k", kv_get_type);
if let Some(f) = module.get_function("tl_kvcache_get_k") {
execution_engine.add_global_mapping(&f, runtime::llm::tl_kvcache_get_k as *const () as usize);
}
add_fn("tl_kvcache_get_v", kv_get_type);
if let Some(f) = module.get_function("tl_kvcache_get_v") {
execution_engine.add_global_mapping(&f, runtime::llm::tl_kvcache_get_v as *const () as usize);
}
let kv_update_type = void_type.fn_type(
&[
ptr_type.into(),
i64_type.into(),
ptr_type.into(),
ptr_type.into(),
],
false,
);
add_fn("tl_kvcache_update", kv_update_type);
if let Some(f) = module.get_function("tl_kvcache_update") {
execution_engine.add_global_mapping(&f, runtime::llm::tl_kvcache_update as *const () as usize);
}
let alloc_tmp_type = ptr_type.fn_type(&[i64_type.into()], false);
module.add_function("tl_alloc_tmp", alloc_tmp_type, None);
let free_tmp_type = void_type.fn_type(&[ptr_type.into()], false);
module.add_function("tl_free_tmp", free_tmp_type, None);
let query_type = void_ptr.fn_type(
&[i8_ptr.into(), i64_type.into(), void_ptr.into(), i8_ptr.into()],
false,
);
module.add_function("tl_query", query_type, None);
let i8_ptr = context.ptr_type(inkwell::AddressSpace::default());
let file_read_binary_type = ptr_type.fn_type(&[i8_ptr.into()], false);
module.add_function("tl_file_read_binary_all", file_read_binary_type, None);
let file_write_binary_type = context
.bool_type()
.fn_type(&[i8_ptr.into(), ptr_type.into()], false);
module.add_function("tl_file_write_binary", file_write_binary_type, None);
let image_load_type = ptr_type.fn_type(&[i8_ptr.into()], false);
module.add_function("tl_image_load_grayscale", image_load_type, None);
let image_dim_type = i64_type.fn_type(&[i8_ptr.into()], false);
module.add_function("tl_image_width", image_dim_type, None);
module.add_function("tl_image_height", image_dim_type, None);
let qt_get_type = void_ptr.fn_type(&[void_ptr.into(), i8_ptr.into()], false);
add_fn("tl_tensor_map_get_quantized", qt_get_type);
if let Some(f) = module.get_function("tl_tensor_map_get_quantized") {
execution_engine.add_global_mapping(&f, runtime::tl_tensor_map_get_quantized as *const () as usize);
}
let qmatmul_type = void_ptr.fn_type(&[void_ptr.into(), void_ptr.into()], false);
add_fn("tl_qtensor_matmul", qmatmul_type);
if let Some(f) = module.get_function("tl_qtensor_matmul") {
execution_engine.add_global_mapping(&f, runtime::tl_qtensor_matmul as *const () as usize);
}
let qfree_type = void_type.fn_type(&[i64_type.into()], false);
add_fn("tl_qtensor_free", qfree_type);
if let Some(f) = module.get_function("tl_qtensor_free") {
execution_engine.add_global_mapping(&f, runtime::tl_qtensor_free as *const () as usize);
}
let str_contains_type = context
.bool_type()
.fn_type(&[i8_ptr.into(), i8_ptr.into()], false);
add_fn("tl_string_contains", str_contains_type);
if let Some(f) = module.get_function("tl_string_contains") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_string_contains as *const () as usize);
}
let str_from_int_type = i8_ptr.fn_type(&[i64_type.into()], false);
add_fn_typed("tl_string_from_int", str_from_int_type, Type::String("String".to_string()), ret_types);
if let Some(f) = module.get_function("tl_string_from_int") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_string_from_int as *const () as usize);
}
let str_unary_type = i8_ptr.fn_type(&[i8_ptr.into()], false);
add_fn("tl_string_trim", str_unary_type);
if let Some(f) = module.get_function("tl_string_trim") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_string_trim as *const () as usize);
}
let str_bool_binary_type = context.bool_type().fn_type(&[i8_ptr.into(), i8_ptr.into()], false);
add_fn("tl_string_starts_with", str_bool_binary_type);
if let Some(f) = module.get_function("tl_string_starts_with") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_string_starts_with as *const () as usize);
}
add_fn("tl_string_ends_with", str_bool_binary_type);
if let Some(f) = module.get_function("tl_string_ends_with") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_string_ends_with as *const () as usize);
}
let str_replace_type = i8_ptr.fn_type(&[i8_ptr.into(), i8_ptr.into(), i8_ptr.into()], false);
add_fn("tl_string_replace", str_replace_type);
if let Some(f) = module.get_function("tl_string_replace") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_string_replace as *const () as usize);
}
let str_substring_type = i8_ptr.fn_type(&[i8_ptr.into(), i64_type.into(), i64_type.into()], false);
add_fn("tl_string_substring", str_substring_type);
if let Some(f) = module.get_function("tl_string_substring") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_string_substring as *const () as usize);
}
let str_is_empty_type = context.bool_type().fn_type(&[i8_ptr.into()], false);
add_fn("tl_string_is_empty", str_is_empty_type);
if let Some(f) = module.get_function("tl_string_is_empty") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_string_is_empty as *const () as usize);
}
add_fn("tl_string_to_uppercase", str_unary_type);
if let Some(f) = module.get_function("tl_string_to_uppercase") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_string_to_uppercase as *const () as usize);
}
add_fn("tl_string_to_lowercase", str_unary_type);
if let Some(f) = module.get_function("tl_string_to_lowercase") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_string_to_lowercase as *const () as usize);
}
let str_index_of_type = i64_type.fn_type(&[i8_ptr.into(), i8_ptr.into()], false);
add_fn("tl_string_index_of", str_index_of_type);
if let Some(f) = module.get_function("tl_string_index_of") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_string_index_of as *const () as usize);
}
let str_split_type = i8_ptr.fn_type(&[i8_ptr.into(), i8_ptr.into()], false);
add_fn("tl_string_split", str_split_type);
if let Some(f) = module.get_function("tl_string_split") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_string_split as *const () as usize);
}
let str_to_f64_type = f64_type.fn_type(&[i8_ptr.into()], false);
add_fn("tl_string_to_f64", str_to_f64_type);
if let Some(f) = module.get_function("tl_string_to_f64") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_string_to_f64 as *const () as usize);
}
let str_repeat_type = i8_ptr.fn_type(&[i8_ptr.into(), i64_type.into()], false);
add_fn("tl_string_repeat", str_repeat_type);
if let Some(f) = module.get_function("tl_string_repeat") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_string_repeat as *const () as usize);
}
let str_chars_type = i8_ptr.fn_type(&[i8_ptr.into()], false);
add_fn("tl_string_chars", str_chars_type);
if let Some(f) = module.get_function("tl_string_chars") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_string_chars as *const () as usize);
}
let str_from_chars_type = i8_ptr.fn_type(&[i8_ptr.into()], false);
add_fn("tl_string_from_chars", str_from_chars_type);
if let Some(f) = module.get_function("tl_string_from_chars") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_string_from_chars as *const () as usize);
}
let str_to_bytes_type = i8_ptr.fn_type(&[i8_ptr.into()], false);
add_fn("tl_string_to_bytes", str_to_bytes_type);
if let Some(f) = module.get_function("tl_string_to_bytes") {
execution_engine.add_global_mapping(&f, runtime::string_ffi::tl_string_to_bytes as *const () as usize);
}
let str_from_utf8_type = i8_ptr.fn_type(&[i8_ptr.into()], false);
add_fn("tl_string_from_utf8", str_from_utf8_type);
if let Some(f) = module.get_function("tl_string_from_utf8") {
execution_engine.add_global_mapping(&f, runtime::string_ffi::tl_string_from_utf8 as *const () as usize);
}
let fn_regex_new_type = i64_type.fn_type(&[i8_ptr.into()], false);
add_fn("tl_regex_new", fn_regex_new_type);
if let Some(f) = module.get_function("tl_regex_new") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_regex_new as *const () as usize);
}
let fn_regex_is_match_type = context.bool_type().fn_type(&[i64_type.into(), i8_ptr.into()], false);
add_fn("tl_regex_is_match", fn_regex_is_match_type);
if let Some(f) = module.get_function("tl_regex_is_match") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_regex_is_match as *const () as usize);
}
let fn_regex_replace_type = i8_ptr.fn_type(&[i64_type.into(), i8_ptr.into(), i8_ptr.into()], false);
add_fn("tl_regex_replace", fn_regex_replace_type);
if let Some(f) = module.get_function("tl_regex_replace") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_regex_replace as *const () as usize);
}
let fn_regex_release_type = void_type.fn_type(&[i64_type.into()], false);
add_fn("tl_regex_release", fn_regex_release_type);
if let Some(f) = module.get_function("tl_regex_release") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_regex_release as *const () as usize);
}
let fn_thread_spawn_type = i64_type.fn_type(&[usize_ptr.into(), void_ptr.into()], false);
add_fn("tl_thread_spawn", fn_thread_spawn_type);
if let Some(f) = module.get_function("tl_thread_spawn") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_thread_spawn as *const () as usize);
}
let fn_thread_join_type = ptr_type.fn_type(&[i64_type.into()], false);
add_fn("tl_thread_join", fn_thread_join_type);
if let Some(f) = module.get_function("tl_thread_join") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_thread_join as *const () as usize);
}
let fn_mutex_new_type = i64_type.fn_type(&[i64_type.into(), void_ptr.into()], false);
add_fn("tl_mutex_new", fn_mutex_new_type);
if let Some(f) = module.get_function("tl_mutex_new") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_mutex_new as *const () as usize);
}
let fn_mutex_modify_type = void_type.fn_type(&[i64_type.into(), usize_ptr.into(), void_ptr.into()], false);
add_fn("tl_mutex_modify", fn_mutex_modify_type);
if let Some(f) = module.get_function("tl_mutex_modify") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_mutex_modify as *const () as usize);
}
let fn_mutex_read_type = void_type.fn_type(&[i64_type.into(), usize_ptr.into(), void_ptr.into(), void_ptr.into()], false);
add_fn("tl_mutex_read", fn_mutex_read_type);
if let Some(f) = module.get_function("tl_mutex_read") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_mutex_read as *const () as usize);
}
let fn_mutex_release_type = void_type.fn_type(&[i64_type.into()], false);
add_fn("tl_mutex_release", fn_mutex_release_type);
if let Some(f) = module.get_function("tl_mutex_release") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_mutex_release as *const () as usize);
}
let str_from_f64_type = i8_ptr.fn_type(&[f64_type.into()], false);
add_fn("tl_string_from_f64", str_from_f64_type);
if let Some(f) = module.get_function("tl_string_from_f64") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_string_from_f64 as *const () as usize);
}
let str_from_bool_type = i8_ptr.fn_type(&[context.bool_type().into()], false);
add_fn("tl_string_from_bool", str_from_bool_type);
if let Some(f) = module.get_function("tl_string_from_bool") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_string_from_bool as *const () as usize);
}
let assert_type = context.void_type().fn_type(&[context.bool_type().into(), i8_ptr.into()], false);
add_fn("tl_assert", assert_type);
if let Some(f) = module.get_function("tl_assert") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_assert as *const () as usize);
}
let random_type = f64_type.fn_type(&[], false);
add_fn("tl_random", random_type);
if let Some(f) = module.get_function("tl_random") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_random as *const () as usize);
}
let random_int_type = i64_type.fn_type(&[i64_type.into(), i64_type.into()], false);
add_fn("tl_random_int", random_int_type);
if let Some(f) = module.get_function("tl_random_int") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_random_int as *const () as usize);
}
let min_max_i64_type = i64_type.fn_type(&[i64_type.into(), i64_type.into()], false);
add_fn("tl_min_i64", min_max_i64_type);
if let Some(f) = module.get_function("tl_min_i64") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_min_i64 as *const () as usize);
}
add_fn("tl_max_i64", min_max_i64_type);
if let Some(f) = module.get_function("tl_max_i64") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_max_i64 as *const () as usize);
}
let min_max_f64_type = f64_type.fn_type(&[f64_type.into(), f64_type.into()], false);
add_fn("tl_min_f64", min_max_f64_type);
if let Some(f) = module.get_function("tl_min_f64") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_min_f64 as *const () as usize);
}
add_fn("tl_max_f64", min_max_f64_type);
if let Some(f) = module.get_function("tl_max_f64") {
execution_engine.add_global_mapping(&f, runtime::stdlib::tl_max_f64 as *const () as usize);
}
let argmax_type = c_tensor_result_type.fn_type(
&[void_ptr.into(), i64_type.into(), context.bool_type().into()],
false,
);
add_fn("tl_tensor_argmax", argmax_type);
if let Some(f) = module.get_function("tl_tensor_argmax") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_argmax as *const () as usize);
}
let item_i64_type = i64_type.fn_type(&[void_ptr.into()], false);
add_fn("tl_tensor_item_i64", item_i64_type);
if let Some(f) = module.get_function("tl_tensor_cat_i64") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_cat_i64 as *const () as usize);
}
let void_ptr_local = context.ptr_type(AddressSpace::default());
let reshape_type =
void_ptr_local.fn_type(&[void_ptr_local.into(), void_ptr_local.into()], false);
if module.get_function("tl_tensor_reshape").is_none() {
module.add_function("tl_tensor_reshape", reshape_type, None);
}
let _tensor_type_local = Type::Tensor(Box::new(Type::F32), 1);
if let Some(f) = module.get_function("tl_tensor_reshape") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_reshape_new as *const () as usize);
}
let sample_type = void_ptr.fn_type(&[void_ptr.into(), f32_type.into(), f32_type.into()], false);
add_fn("tl_tensor_sample", sample_type);
if let Some(f) = module.get_function("tl_tensor_sample") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_sample as *const () as usize); }
add_fn("tl_tensor_shallow_clone", clone_type);
if let Some(f) = module.get_function("tl_tensor_shallow_clone") {
execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_shallow_clone as *const () as usize);
}
let i8_ptr = context.ptr_type(AddressSpace::default());
let void_type = context.void_type();
let debug_print_type = void_type.fn_type(&[i8_ptr.into(), i8_ptr.into()], false);
module.add_function("tl_debug_print_ptr", debug_print_type, None);
if let Some(f) = module.get_function("tl_debug_print_ptr") {
execution_engine.add_global_mapping(&f, tl_debug_print_ptr as *const () as usize);
}
let chunk_type = void_ptr.fn_type(&[void_ptr.into(), i64_type.into(), i64_type.into(), i64_type.into()], false);
add_fn("tl_device_tensor_chunk", chunk_type);
add_fn("tl_device_tensor_split", chunk_type);
if let Some(f) = module.get_function("tl_device_tensor_chunk") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_chunk as *const () as usize); }
if let Some(f) = module.get_function("tl_device_tensor_split") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_device_tensor_split as *const () as usize); }
let unary_linalg = void_ptr.fn_type(&[void_ptr.into()], false);
add_fn("tl_tensor_inverse", unary_linalg);
add_fn("tl_tensor_det", unary_linalg);
add_fn("tl_tensor_svd_u", unary_linalg);
add_fn("tl_tensor_svd_s", unary_linalg);
add_fn("tl_tensor_svd_v", unary_linalg);
add_fn("tl_tensor_eig_values", unary_linalg);
add_fn("tl_tensor_eig_vectors", unary_linalg);
let binary_linalg = void_ptr.fn_type(&[void_ptr.into(), void_ptr.into()], false);
add_fn("tl_tensor_solve", binary_linalg);
if let Some(f) = module.get_function("tl_tensor_inverse") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_tensor_inverse as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_det") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_tensor_det as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_svd_u") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_tensor_svd_u as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_svd_s") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_tensor_svd_s as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_svd_v") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_tensor_svd_v as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_eig_values") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_tensor_eig_values as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_eig_vectors") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_tensor_eig_vectors as *const () as usize); }
if let Some(f) = module.get_function("tl_tensor_solve") { execution_engine.add_global_mapping(&f, runtime::device_ffi::tl_tensor_solve as *const () as usize); }
let adam_type = void_type.fn_type(&[
void_ptr.into(), void_ptr.into(), void_ptr.into(), void_ptr.into(),
i64_type.into(), f32_type.into(), f32_type.into(), f32_type.into(),
f32_type.into(), f32_type.into(),
], false);
add_fn("tl_adam_step", adam_type);
if let Some(f) = module.get_function("tl_adam_step") { execution_engine.add_global_mapping(&f, runtime::tl_adam_step as *const () as usize); }
let sgd_type = void_type.fn_type(&[
void_ptr.into(), void_ptr.into(), void_ptr.into(),
f32_type.into(), f32_type.into(), f32_type.into(), f32_type.into(),
context.bool_type().into(),
], false);
add_fn("tl_sgd_step", sgd_type);
if let Some(f) = module.get_function("tl_sgd_step") { execution_engine.add_global_mapping(&f, runtime::tl_sgd_step as *const () as usize); }
let lr_sched_type = f32_type.fn_type(&[f32_type.into(), i64_type.into(), i64_type.into(), f32_type.into()], false);
add_fn("tl_lr_cosine_annealing", lr_sched_type);
add_fn("tl_lr_step", lr_sched_type);
if let Some(f) = module.get_function("tl_lr_cosine_annealing") { execution_engine.add_global_mapping(&f, runtime::tl_lr_cosine_annealing as *const () as usize); }
if let Some(f) = module.get_function("tl_lr_step") { execution_engine.add_global_mapping(&f, runtime::tl_lr_step as *const () as usize); }
let img_load_type = void_ptr.fn_type(&[void_ptr.into()], false);
add_fn("tl_image_load_rgb", img_load_type);
let img_resize_type = void_ptr.fn_type(&[void_ptr.into(), i64_type.into(), i64_type.into()], false);
add_fn("tl_image_resize", img_resize_type);
let img_save_type = void_type.fn_type(&[void_ptr.into(), void_ptr.into()], false);
add_fn("tl_image_save", img_save_type);
let img_norm_type = void_ptr.fn_type(&[void_ptr.into(), void_ptr.into(), void_ptr.into()], false);
add_fn("tl_image_normalize", img_norm_type);
let img_crop_type = void_ptr.fn_type(&[void_ptr.into(), i64_type.into(), i64_type.into(), i64_type.into(), i64_type.into()], false);
add_fn("tl_image_crop", img_crop_type);
if let Some(f) = module.get_function("tl_image_load_rgb") { execution_engine.add_global_mapping(&f, runtime::tl_image_load_rgb as *const () as usize); }
if let Some(f) = module.get_function("tl_image_resize") { execution_engine.add_global_mapping(&f, runtime::tl_image_resize as *const () as usize); }
if let Some(f) = module.get_function("tl_image_save") { execution_engine.add_global_mapping(&f, runtime::tl_image_save as *const () as usize); }
if let Some(f) = module.get_function("tl_image_normalize") { execution_engine.add_global_mapping(&f, runtime::tl_image_normalize as *const () as usize); }
if let Some(f) = module.get_function("tl_image_crop") { execution_engine.add_global_mapping(&f, runtime::tl_image_crop as *const () as usize); }
let csv_load_type = void_ptr.fn_type(&[void_ptr.into()], false);
add_fn("tl_csv_load", csv_load_type);
let json_load_type = void_ptr.fn_type(&[void_ptr.into()], false);
add_fn("tl_json_load", json_load_type);
let dl_new_type = i64_type.fn_type(&[void_ptr.into(), void_ptr.into(), i64_type.into(), context.bool_type().into()], false);
add_fn("tl_dataloader_new", dl_new_type);
let dl_len_type = i64_type.fn_type(&[i64_type.into()], false);
add_fn("tl_dataloader_len", dl_len_type);
let dl_reset_type = void_type.fn_type(&[i64_type.into()], false);
add_fn("tl_dataloader_reset", dl_reset_type);
add_fn("tl_dataloader_free", dl_reset_type);
if let Some(f) = module.get_function("tl_csv_load") { execution_engine.add_global_mapping(&f, runtime::tl_csv_load as *const () as usize); }
if let Some(f) = module.get_function("tl_json_load") { execution_engine.add_global_mapping(&f, runtime::tl_json_load as *const () as usize); }
if let Some(f) = module.get_function("tl_dataloader_new") { execution_engine.add_global_mapping(&f, runtime::tl_dataloader_new as *const () as usize); }
if let Some(f) = module.get_function("tl_dataloader_len") { execution_engine.add_global_mapping(&f, runtime::tl_dataloader_len as *const () as usize); }
if let Some(f) = module.get_function("tl_dataloader_reset") { execution_engine.add_global_mapping(&f, runtime::tl_dataloader_reset as *const () as usize); }
if let Some(f) = module.get_function("tl_dataloader_free") { execution_engine.add_global_mapping(&f, runtime::tl_dataloader_free as *const () as usize); }
}