taichi-dev / taichi

Productive, portable, and performant GPU programming in Python.
https://taichi-lang.org
Apache License 2.0
25.07k stars 2.26k forks source link

Call external function with llvm bitcode #2879

Open squarefk opened 2 years ago

squarefk commented 2 years ago

We would like to support more functions from third-party libraries to make taichi more powerful in practice. To achieve this goal, we are trying to include common math libraries like LAPACK, BLAS, Eigen,...

squarefk commented 2 years ago
import ctypes
import os

import taichi as ti

ti.init(dynamic_index=True)

source = '''
void foo(int* a, int b[2][2]) {
    a[0] = 11;
    b[0][0] = 10;
}
'''

ces = ti.CompileExternalSource(source)

@ti.kernel
def call_ext():
    b = 0
    a = ti.Vector([[0, 0], [0, 0]], ti.i32)
    print(a, b)
    ti.call_cpp(ces, "foo", b, a)
    print(a, b)

call_ext()