This commit is contained in:
Dun Liang 2023-12-29 03:55:56 +08:00
parent 2a995d6cc4
commit 4b9d777570
1 changed files with 22 additions and 0 deletions

View File

@ -652,6 +652,28 @@ def add_backend(mod):
from . import lock
@lock.lock_scope()
def compile_module(source, flags):
"""
quick c extension:
Example:
import jittor as jt
import jittor_utils
import jittor.compiler as compiler
mod = jittor_utils.compile_module('''
#include "common.h"
namespace jittor {
// @pyjt(hello)
string hello(const string& src) {
LOGir << "hello" << src;
}
}''', compiler.cc_flags)
mod.hello("aaa")
"""
tmp_path = os.path.join(cache_path, "tmp")
os.makedirs(tmp_path, exist_ok=True)
hash = "hash_" + get_str_hash(source)