Skip to content

Commit b516254

Browse files
committed
add mtl log type
1 parent b15b5b4 commit b516254

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/device/intrinsics/output.jl

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
const MTLLOG_SUBSYSTEM = "com.juliagpu.metal.jl"
2+
const MTLLOG_CATEGRORY = "mtlprintf"
3+
4+
const __METAL_OS_LOG_TYPE_DEBUG__ = Int32(2)
5+
const __METAL_OS_LOG_TYPE_INFO__ = Int32(1)
6+
const __METAL_OS_LOG_TYPE_DEFAULT__ = Int32(0)
7+
const __METAL_OS_LOG_TYPE_ERROR__ = Int32(16)
8+
const __METAL_OS_LOG_TYPE_FAULT__ = Int32(17)
9+
110
export @mtlprintf
211

312
@generated function promote_c_argument(arg)
@@ -72,18 +81,18 @@ end
7281
end
7382

7483
# invoke @air.os_log and return
75-
subsystem_str = LLVM.PointerNull(T_pint8a2)
76-
intptr = LLVM.ConstantInt(T_int64, Int64(-1))
77-
category_str = const_inttoptr(intptr, T_pint8a2)
78-
log_type_default = LLVM.ConstantInt(T_int32, Int32(0))
79-
log_type_debug = LLVM.ConstantInt(T_int32, Int32(2))
80-
log_type_error = LLVM.ConstantInt(T_int32, Int32(16))
84+
subsystem_str = globalstring_ptr!(builder, MTLLOG_SUBSYSTEM, addrspace=2)
85+
# subsystem_str = LLVM.PointerNull(T_pint8a2)
86+
# intptr = LLVM.ConstantInt(T_int64, Int64(-1))
87+
# category_str = const_inttoptr(intptr, T_pint8a2)
88+
category_str = globalstring_ptr!(builder, MTLLOG_CATEGRORY, addrspace=2)
89+
log_type = LLVM.ConstantInt(T_int32, __METAL_OS_LOG_TYPE_DEBUG__)
8190
arg_size = LLVM.ConstantInt(T_int64, Int64(argsize))
8291

8392
# declare void @air.os_log(i8 addrspace(2)*, i8 addrspace(2)*, i32, i8 addrspace(2)*, i8*, i64) local_unnamed_addr #4
8493
os_log_fty = LLVM.FunctionType(T_void, [T_pint8a2, T_pint8a2, T_int32, T_pint8a2, T_pint8, T_int64])
8594
os_log = LLVM.Function(mod, "air.os_log", os_log_fty)
86-
call!(builder, os_log_fty, os_log, [subsystem_str, category_str, log_type_error, str, buffer, arg_size])
95+
call!(builder, os_log_fty, os_log, [subsystem_str, category_str, log_type, str, buffer, arg_size])
8796
ret!(builder)
8897
end
8998

0 commit comments

Comments
 (0)