codon/stdlib/openmp.codon

895 lines
25 KiB
Python
Raw Normal View History

# Copyright (C) 2022-2024 Exaloop Inc. <https://exaloop.io>
2021-09-28 02:02:44 +08:00
# OpenMP interface
# Ref: https://github.com/llvm/llvm-project/tree/main/openmp
Dynamic Polymorphism (#58) * Use Static[] for static inheritance * Support .seq extension * Fix #36 * Polymorphic typechecking; vtables [wip] * v-table dispatch [wip] * vtable routing [wip; bug] * vtable routing [MVP] * Fix texts * Add union type support * Update FAQs * Clarify * Add BSL license * Add makeUnion * Add IR UnionType * Update union representation in LLVM * Update README * Update README.md * Update README * Update README.md * Add benchmarks * Add more benchmarks and README * Add primes benchmark * Update benchmarks * Fix cpp * Clean up list * Update faq.md * Add binary trees benchmark * Add fannkuch benchmark * Fix paths * Add PyPy * Abort on fail * More benchmarks * Add cpp word_count * Update set_partition cpp * Add nbody cpp * Add TAQ cpp; fix word_count timing * Update CODEOWNERS * Update README * Update README.md * Update CODEOWNERS * Fix bench script * Update binary_trees.cpp * Update taq.cpp * Fix primes benchmark * Add mandelbrot benchmark * Fix OpenMP init * Add Module::unsafeGetUnionType * UnionType [wip] [skip ci] * Integrate IR unions and Union * UnionType refactor [skip ci] * Update README.md * Update docs * UnionType [wip] [skip ci] * UnionType and automatic unions * Add Slack * Update faq.md * Refactor types * New error reporting [wip] * New error reporting [wip] * peglib updates [wip] [skip_ci] * Fix parsing issues * Fix parsing issues * Fix error reporting issues * Make sure random module matches Python * Update releases.md * Fix tests * Fix #59 * Fix #57 * Fix #50 * Fix #49 * Fix #26; Fix #51; Fix #47; Fix #49 * Fix collection extension methods * Fix #62 * Handle *args/**kwargs with Callable[]; Fix #43 * Fix #43 * Fix Ptr.__sub__; Fix polymorphism issues * Add typeinfo * clang-format * Upgrade fmtlib to v9; Use CPM for fmtlib; format spec support; __format__ support * Use CPM for semver and toml++ * Remove extension check * Revamp str methods * Update str.zfill * Fix thunk crashes [wip] [skip_ci] * Fix str.__reversed__ * Fix count_with_max * Fix vtable memory allocation issues * Add poly AST tests * Use PDQsort when stability does not matter * Fix dotted imports; Fix issues * Fix kwargs passing to Python * Fix #61 * Fix #37 * Add isinstance support for unions; Union methods return Union type if different * clang-format * Nicely format error tracebacks * Fix build issues; clang-format * Fix OpenMP init * Fix OpenMP init * Update README.md * Fix tests * Update license [skip ci] * Update license [ci skip] * Add copyright header to all source files * Fix super(); Fix error recovery in ClassStmt * Clean up whitespace [ci skip] * Use Python 3.9 on CI * Print info in random test * Fix single unions * Update random_test.codon * Fix polymorhic thunk instantiation * Fix random test * Add operator.attrgetter and operator.methodcaller * Add code documentation * Update documentation * Update README.md * Fix tests * Fix random init Co-authored-by: A. R. Shajii <ars@ars.me>
2022-12-05 08:45:21 +08:00
2021-09-28 02:02:44 +08:00
Routine = Function[[i32, cobj], i32]
_KMP_IDENT_IMB = 0x01
_KMP_IDENT_KMPC = 0x02
_KMP_IDENT_AUTOPAR = 0x08
_KMP_IDENT_ATOMIC_REDUCE = 0x10
_KMP_IDENT_BARRIER_EXPL = 0x20
_KMP_IDENT_BARRIER_IMPL = 0x0040
_KMP_IDENT_BARRIER_IMPL_MASK = 0x01C0
_KMP_IDENT_BARRIER_IMPL_FOR = 0x0040
_KMP_IDENT_BARRIER_IMPL_SECTIONS = 0x00C0
_KMP_IDENT_BARRIER_IMPL_SINGLE = 0x0140
_KMP_IDENT_BARRIER_IMPL_WORKSHARE = 0x01C0
_KMP_IDENT_WORK_LOOP = 0x200
_KMP_IDENT_WORK_SECTIONS = 0x400
_KMP_IDENT_WORK_DISTRIBUTE = 0x800
_KMP_IDENT_ATOMIC_HINT_MASK = 0xFF0000
_KMP_IDENT_ATOMIC_HINT_UNCONTENDED = 0x010000
_KMP_IDENT_ATOMIC_HINT_CONTENDED = 0x020000
_KMP_IDENT_ATOMIC_HINT_NONSPECULATIVE = 0x040000
_KMP_IDENT_ATOMIC_HINT_SPECULATIVE = 0x080000
_KMP_IDENT_OPENMP_SPEC_VERSION_MASK = 0xFF000000
@tuple
class Lock:
a1: i32
a2: i32
a3: i32
a4: i32
a5: i32
a6: i32
a7: i32
a8: i32
2022-01-24 17:57:12 +08:00
def __new__() -> Lock:
2021-09-28 02:02:44 +08:00
z = i32(0)
return Lock(z, z, z, z, z, z, z, z)
@tuple
class Ident:
reserved_1: i32
flags: i32
reserved_2: i32
reserved_3: i32
psource: cobj
2022-01-24 17:57:12 +08:00
def __new__(flags: int = 0, source: str = ";unknown;unknown;0;0;;") -> Ident:
2021-09-28 02:02:44 +08:00
return Ident(i32(0), i32(flags | _KMP_IDENT_KMPC), i32(0), i32(0), source.ptr)
@tuple
class LRData:
routine: Routine
@tuple
class Task:
shareds: cobj
routine: Routine
flags: i32
x: LRData
y: LRData
@tuple
2022-01-24 17:57:12 +08:00
class TaskWithPrivates:
2021-09-28 02:02:44 +08:00
task: Task
data: T
2022-02-16 23:51:16 +08:00
T: type
2021-09-28 02:02:44 +08:00
@tuple
class TaskReductionInput:
reduce_shar: cobj
reduce_orig: cobj
reduce_size: int
reduce_init: cobj
reduce_fini: cobj
reduce_comb: cobj
flags: u32
def __new__(reduce_shar, reduce_orig, reduce_size: int,
reduce_init: cobj, reduce_comb: cobj):
return TaskReductionInput(reduce_shar.as_byte(), reduce_orig.as_byte(), reduce_size,
reduce_init, cobj(), reduce_comb, u32(0))
@tuple
class TaskReductionInputArray:
len: int
ptr: Ptr[TaskReductionInput]
def __setitem__(self, idx: int, x: TaskReductionInput):
self.ptr[idx] = x
2021-09-28 02:02:44 +08:00
_DEFAULT_IDENT = Ident()
_STATIC_LOOP_IDENT = Ident(_KMP_IDENT_WORK_LOOP)
_REDUCTION_IDENT = Ident(_KMP_IDENT_ATOMIC_REDUCE)
def _default_loc():
return __ptr__(_DEFAULT_IDENT)
2022-01-24 17:57:12 +08:00
2021-09-28 02:02:44 +08:00
_default_loc()
def _static_loop_loc():
return __ptr__(_STATIC_LOOP_IDENT)
2022-01-24 17:57:12 +08:00
2021-09-28 02:02:44 +08:00
_static_loop_loc()
def _reduction_loc():
return __ptr__(_REDUCTION_IDENT)
2022-01-24 17:57:12 +08:00
2021-09-28 02:02:44 +08:00
_reduction_loc()
def _critical_begin(loc_ref: Ptr[Ident], gtid: int, lck: Ptr[Lock]):
from C import __kmpc_critical(Ptr[Ident], i32, Ptr[Lock])
2021-09-28 02:02:44 +08:00
__kmpc_critical(loc_ref, i32(gtid), lck)
def _critical_end(loc_ref: Ptr[Ident], gtid: int, lck: Ptr[Lock]):
from C import __kmpc_end_critical(Ptr[Ident], i32, Ptr[Lock])
2021-09-28 02:02:44 +08:00
__kmpc_end_critical(loc_ref, i32(gtid), lck)
def _single_begin(loc_ref: Ptr[Ident], gtid: int):
from C import __kmpc_single(Ptr[Ident], i32) -> i32
return int(__kmpc_single(loc_ref, i32(gtid)))
def _single_end(loc_ref: Ptr[Ident], gtid: int):
from C import __kmpc_end_single(Ptr[Ident], i32)
__kmpc_end_single(loc_ref, i32(gtid))
def _master_begin(loc_ref: Ptr[Ident], gtid: int):
from C import __kmpc_master(Ptr[Ident], i32) -> i32
return int(__kmpc_master(loc_ref, i32(gtid)))
def _master_end(loc_ref: Ptr[Ident], gtid: int):
from C import __kmpc_end_master(Ptr[Ident], i32)
__kmpc_end_master(loc_ref, i32(gtid))
def _ordered_begin(loc_ref: Ptr[Ident], gtid: int):
from C import __kmpc_ordered(Ptr[Ident], i32)
__kmpc_ordered(loc_ref, i32(gtid))
2021-09-28 02:02:44 +08:00
def _ordered_end(loc_ref: Ptr[Ident], gtid: int):
from C import __kmpc_end_ordered(Ptr[Ident], i32)
__kmpc_end_ordered(loc_ref, i32(gtid))
def _taskwait(loc_ref: Ptr[Ident], gtid: int):
from C import __kmpc_omp_taskwait(Ptr[Ident], i32)
__kmpc_omp_taskwait(loc_ref, i32(gtid))
def _taskgroup_begin(loc_ref: Ptr[Ident], gtid: int):
from C import __kmpc_taskgroup(Ptr[Ident], i32)
__kmpc_taskgroup(loc_ref, i32(gtid))
def _taskgroup_end(loc_ref: Ptr[Ident], gtid: int):
from C import __kmpc_end_taskgroup(Ptr[Ident], i32)
__kmpc_end_taskgroup(loc_ref, i32(gtid))
def _task_alloc_size(
size_of_task: int,
size_of_shareds: int,
):
from C import __kmpc_omp_task_alloc_size(int, int) -> int
return __kmpc_omp_task_alloc_size(size_of_task, size_of_shareds)
2022-01-24 17:57:12 +08:00
def _task_alloc(
loc_ref: Ptr[Ident],
gtid: int,
flags: int,
size_of_task: int,
size_of_shareds: int,
task_entry: Routine,
):
from internal.gc import alloc
from C import __kmpc_omp_task_alloc(Ptr[Ident], i32, i32, int, int, Routine, cobj) -> cobj
taskdata = alloc(_task_alloc_size(size_of_task, size_of_shareds))
2022-01-24 17:57:12 +08:00
return __kmpc_omp_task_alloc(
loc_ref, i32(gtid), i32(flags), size_of_task, size_of_shareds, task_entry, taskdata
2022-01-24 17:57:12 +08:00
)
2021-09-28 02:02:44 +08:00
def _task_run(loc_ref: Ptr[Ident], gtid: int, new_task: cobj):
from C import __kmpc_omp_task(Ptr[Ident], i32, cobj) -> i32
return int(__kmpc_omp_task(loc_ref, i32(gtid), new_task))
def _barrier(loc_ref: Ptr[Ident], gtid: int):
from C import __kmpc_barrier(Ptr[Ident], i32)
__kmpc_barrier(loc_ref, i32(gtid))
def _flush(loc_ref: Ptr[Ident]):
from C import __kmpc_flush(Ptr[Ident])
__kmpc_flush(loc_ref)
def flush():
_flush(_default_loc())
2022-01-24 17:57:12 +08:00
def _static_init(
loc_ref: Ptr[Ident], gtid: int, schedtype: int, loop: range, incr: int, chunk: int
):
2021-09-28 02:02:44 +08:00
from C import __kmpc_for_static_init_8(Ptr[Ident], i32, i32, Ptr[i32], Ptr[int], Ptr[int], Ptr[int], int, int)
last = i32(0)
lower = 0
upper = len(loop) - 1
stride = 1
2022-01-24 17:57:12 +08:00
__kmpc_for_static_init_8(
loc_ref,
i32(gtid),
i32(schedtype),
__ptr__(last),
__ptr__(lower),
__ptr__(upper),
__ptr__(stride),
incr,
chunk,
)
2021-09-28 02:02:44 +08:00
return bool(last), range(loop._get(lower), loop._get(upper + 1), loop.step), stride
def _static_fini(loc_ref: Ptr[Ident], gtid: int):
from C import __kmpc_for_static_fini(Ptr[Ident], i32)
__kmpc_for_static_fini(loc_ref, i32(gtid))
2022-01-24 17:57:12 +08:00
def _dynamic_init(
loc_ref: Ptr[Ident], gtid: int, schedtype: int, loop: range, chunk: int
):
2021-09-28 02:02:44 +08:00
from C import __kmpc_dispatch_init_8(Ptr[Ident], i32, i32, int, int, int, int)
lower = 0
upper = len(loop) - 1
stride = 1
2022-01-24 17:57:12 +08:00
__kmpc_dispatch_init_8(
loc_ref, i32(gtid), i32(schedtype), lower, upper, stride, chunk
)
2021-09-28 02:02:44 +08:00
def _dynamic_next(loc_ref: Ptr[Ident], gtid: int, loop: range):
from C import __kmpc_dispatch_next_8(Ptr[Ident], i32, Ptr[i32], Ptr[int], Ptr[int], Ptr[int]) -> i32
last = i32(0)
lower = 0
upper = 0
stride = 0
2022-01-24 17:57:12 +08:00
more = __kmpc_dispatch_next_8(
loc_ref,
i32(gtid),
__ptr__(last),
__ptr__(lower),
__ptr__(upper),
__ptr__(stride),
)
return (
bool(more),
bool(last),
range(loop._get(lower), loop._get(upper + 1), loop.step),
)
2021-09-28 02:02:44 +08:00
def _dynamic_fini(loc_ref: Ptr[Ident], gtid: int):
from C import __kmpc_dispatch_fini_8(Ptr[Ident], i32)
__kmpc_dispatch_fini_8(loc_ref, i32(gtid))
2022-01-24 17:57:12 +08:00
def _reduce(
loc_ref: Ptr[Ident],
gtid: int,
reduce_data: T,
reduce_func: cobj,
lck: cobj,
T: type,
):
2021-09-28 02:02:44 +08:00
from internal.gc import sizeof
2022-01-24 17:57:12 +08:00
2021-09-28 02:02:44 +08:00
from C import __kmpc_reduce(Ptr[Ident], i32, i32, int, cobj, cobj, cobj) -> i32
num_vars = staticlen(reduce_data)
reduce_size = sizeof(T)
2022-01-24 17:57:12 +08:00
return int(
__kmpc_reduce(
loc_ref,
i32(gtid),
i32(num_vars),
reduce_size,
__ptr__(reduce_data).as_byte(),
reduce_func,
lck,
)
)
2021-09-28 02:02:44 +08:00
def _end_reduce(loc_ref: Ptr[Ident], gtid: int, lck: cobj):
from C import __kmpc_end_reduce(Ptr[Ident], i32, cobj)
__kmpc_end_reduce(loc_ref, i32(gtid), lck)
2022-01-24 17:57:12 +08:00
def _reduce_nowait(
loc_ref: Ptr[Ident],
gtid: int,
reduce_data: T,
reduce_func: cobj,
lck: Ptr[Lock],
2022-01-24 17:57:12 +08:00
T: type,
):
2021-09-28 02:02:44 +08:00
from internal.gc import sizeof
2022-01-24 17:57:12 +08:00
from C import __kmpc_reduce_nowait(Ptr[Ident], i32, i32, int, cobj, cobj, Ptr[Lock]) -> i32
2021-09-28 02:02:44 +08:00
num_vars = staticlen(reduce_data)
reduce_size = sizeof(T)
2022-01-24 17:57:12 +08:00
return int(
__kmpc_reduce_nowait(
loc_ref,
i32(gtid),
i32(num_vars),
reduce_size,
__ptr__(reduce_data).as_byte(),
reduce_func,
lck,
)
)
def _end_reduce_nowait(loc_ref: Ptr[Ident], gtid: int, lck: Ptr[Lock]):
from C import __kmpc_end_reduce_nowait(Ptr[Ident], i32, Ptr[Lock])
2021-09-28 02:02:44 +08:00
__kmpc_end_reduce_nowait(loc_ref, i32(gtid), lck)
def _taskred_init(loc_ref: Ptr[Ident], gtid: int, num: int, data):
from C import __kmpc_taskred_modifier_init(Ptr[Ident], i32, i32, i32, cobj) -> cobj
return __kmpc_taskred_modifier_init(loc_ref, i32(gtid), i32(0), i32(num), data.as_byte())
def _taskred_fini(loc_ref: Ptr[Ident], gtid: int):
from C import __kmpc_task_reduction_modifier_fini(Ptr[Ident], i32, i32)
__kmpc_task_reduction_modifier_fini(loc_ref, i32(gtid), i32(0))
# add tskgrp arg?
def _taskred_data(gtid: int, data):
from C import __kmpc_task_reduction_get_th_data(i32, cobj, cobj) -> cobj
T = type(data)
return T(__kmpc_task_reduction_get_th_data(i32(gtid), cobj(), data.as_byte()))
2021-09-28 02:02:44 +08:00
def _fork_call(microtask: cobj, args):
from C import __kmpc_fork_call(Ptr[Ident], i32, cobj, ...)
loc_ref = _default_loc() # TODO: pass real loc?
__kmpc_fork_call(loc_ref, i32(1), microtask, __ptr__(args))
def _static_loop_outline_template(gtid_ptr: Ptr[i32], btid_ptr: Ptr[i32], args):
@nonpure
2021-09-28 02:02:44 +08:00
def _loop_step():
return 1
@nonpure
2022-01-24 17:57:12 +08:00
def _loop_loc_and_gtid(
loc_ref: Ptr[Ident], reduction_loc_ref: Ptr[Ident], gtid: int
):
2021-09-28 02:02:44 +08:00
pass
@nonpure
2021-09-28 02:02:44 +08:00
def _loop_body_stub(i, args):
pass
@nonpure
2021-09-28 02:02:44 +08:00
def _loop_schedule():
return (1 << 30) | 35 # nonmonotonic, dynamic chunked
@nonpure
2021-09-28 02:02:44 +08:00
def _loop_shared_updates(args):
pass
@nonpure
2021-09-28 02:02:44 +08:00
def _loop_reductions(args):
pass
chunk, start, stop, extra = args[0]
step = _loop_step()
gtid = int(gtid_ptr[0])
loc_ref = _default_loc()
static_loop_loc_ref = _static_loop_loc()
reduction_loc_ref = _reduction_loc()
_loop_loc_and_gtid(loc_ref, reduction_loc_ref, gtid)
loop = range(start, stop, step)
schedule = _loop_schedule()
2022-01-24 17:57:12 +08:00
last, subloop, stride = _static_init(
static_loop_loc_ref, gtid, schedtype=schedule, loop=loop, incr=1, chunk=1
)
2021-09-28 02:02:44 +08:00
i = subloop.start
stop = min(subloop.stop, loop.stop) if step >= 0 else max(subloop.stop, loop.stop)
while (step >= 0 and i < stop) or (step < 0 and i > stop):
_loop_body_stub(i, extra)
i += step
_static_fini(static_loop_loc_ref, gtid)
if last:
_loop_shared_updates(extra)
_loop_reductions(extra)
def _static_chunked_loop_outline_template(gtid_ptr: Ptr[i32], btid_ptr: Ptr[i32], args):
@nonpure
2021-09-28 02:02:44 +08:00
def _loop_step():
return 1
@nonpure
2022-01-24 17:57:12 +08:00
def _loop_loc_and_gtid(
loc_ref: Ptr[Ident], reduction_loc_ref: Ptr[Ident], gtid: int
):
2021-09-28 02:02:44 +08:00
pass
@nonpure
2021-09-28 02:02:44 +08:00
def _loop_body_stub(i, args):
pass
@nonpure
2021-09-28 02:02:44 +08:00
def _loop_schedule():
return (1 << 30) | 35 # nonmonotonic, dynamic chunked
@nonpure
2021-09-28 02:02:44 +08:00
def _loop_shared_updates(args):
pass
@nonpure
2021-09-28 02:02:44 +08:00
def _loop_reductions(args):
pass
chunk, start, stop, extra = args[0]
step = _loop_step()
gtid = int(gtid_ptr[0])
loc_ref = _default_loc()
static_loop_loc_ref = _static_loop_loc()
reduction_loc_ref = _reduction_loc()
_loop_loc_and_gtid(loc_ref, reduction_loc_ref, gtid)
loop = range(start, stop, step)
schedule = _loop_schedule()
2022-01-24 17:57:12 +08:00
last, subloop, stride = _static_init(
static_loop_loc_ref, gtid, schedtype=schedule, loop=loop, incr=1, chunk=chunk
)
2021-09-28 02:02:44 +08:00
start = subloop.start
stop = min(subloop.stop, loop.stop) if step >= 0 else max(subloop.stop, loop.stop)
while (step >= 0 and start < loop.stop) or (step < 0 and start > loop.stop):
i = start
while (step >= 0 and i < stop) or (step < 0 and i > stop):
_loop_body_stub(i, extra)
i += step
start += stride * step
stop += stride * step
stop = min(stop, loop.stop) if step >= 0 else max(stop, loop.stop)
_static_fini(static_loop_loc_ref, gtid)
if last:
_loop_shared_updates(extra)
_loop_reductions(extra)
def _dynamic_loop_outline_template(gtid_ptr: Ptr[i32], btid_ptr: Ptr[i32], args):
@nonpure
2021-09-28 02:02:44 +08:00
def _loop_step():
return 1
@nonpure
2022-01-24 17:57:12 +08:00
def _loop_loc_and_gtid(
loc_ref: Ptr[Ident], reduction_loc_ref: Ptr[Ident], gtid: int
):
2021-09-28 02:02:44 +08:00
pass
@nonpure
2021-09-28 02:02:44 +08:00
def _loop_body_stub(i, args):
pass
@nonpure
2021-09-28 02:02:44 +08:00
def _loop_schedule():
return (1 << 30) | 35 # nonmonotonic, dynamic chunked
@nonpure
2021-09-28 02:02:44 +08:00
def _loop_shared_updates(args):
pass
@nonpure
2021-09-28 02:02:44 +08:00
def _loop_reductions(args):
pass
@nonpure
2021-09-28 02:02:44 +08:00
def _loop_ordered():
return False
chunk, start, stop, extra = args[0]
step = _loop_step()
gtid = int(gtid_ptr[0])
loc_ref = _default_loc()
reduction_loc_ref = _reduction_loc()
_loop_loc_and_gtid(loc_ref, reduction_loc_ref, gtid)
loop = range(start, stop, step)
schedule = _loop_schedule()
ordered = _loop_ordered()
_dynamic_init(loc_ref, gtid, schedtype=schedule, loop=loop, chunk=chunk)
while True:
more, last, subloop = _dynamic_next(loc_ref, gtid, loop)
if not more:
break
i = subloop.start
while (step >= 0 and i < subloop.stop) or (step < 0 and i > subloop.stop):
_loop_body_stub(i, extra)
i += step
if ordered:
_dynamic_fini(loc_ref, gtid)
if last:
_loop_shared_updates(extra)
_loop_reductions(extra)
# P = privates; tuple of types
# S = shareds; tuple of pointers
2022-01-24 17:57:12 +08:00
def _spawn_and_run_task(
loc_ref: Ptr[Ident], gtid: int, routine: cobj, priv: P, shared: S, P: type, S: type
):
from internal.gc import sizeof
2021-09-28 02:02:44 +08:00
TaskThunk = TaskWithPrivates[P]
flags = 1
size_of_kmp_task_t = sizeof(TaskThunk)
size_of_privs = sizeof(P)
size_of_shareds = sizeof(S)
loc_ref = _default_loc()
2022-01-24 17:57:12 +08:00
task = Ptr[TaskThunk](
_task_alloc(
loc_ref, gtid, flags, size_of_kmp_task_t, size_of_shareds, Routine(routine)
)
)
2021-09-28 02:02:44 +08:00
if staticlen(shared) != 0:
shared_ptr = task[0].task.shareds
str.memcpy(shared_ptr, __ptr__(shared).as_byte(), size_of_shareds)
if staticlen(priv) != 0:
priv_ptr = task.as_byte() + sizeof(Task)
str.memcpy(priv_ptr, __ptr__(priv).as_byte(), size_of_privs)
_task_run(loc_ref, gtid, task.as_byte())
# Note: this is different than OpenMP's "taskloop" -- this template simply
# spawns a new task for each loop iteration.
def _task_loop_outline_template(gtid_ptr: Ptr[i32], btid_ptr: Ptr[i32], args):
2022-01-24 17:57:12 +08:00
def _routine_stub(gtid: i32, data: cobj, P: type, S: type):
@nonpure
def _task_loop_body_stub(gtid: int, priv, shared):
2021-09-28 02:02:44 +08:00
pass
task = Ptr[TaskWithPrivates[P]](data)[0]
priv = task.data
gtid64 = int(gtid)
if staticlen(S) != 0:
2021-09-28 02:02:44 +08:00
shared = Ptr[S](task.task.shareds)[0]
_task_loop_body_stub(gtid64, priv, shared)
2021-09-28 02:02:44 +08:00
else:
shared = ()
_task_loop_body_stub(gtid64, priv, shared)
2021-09-28 02:02:44 +08:00
return i32(0)
@nonpure
def _loop_loc_and_gtid(
loc_ref: Ptr[Ident], reduction_loc_ref: Ptr[Ident], gtid: int
):
pass
@nonpure
def _fix_privates_and_shareds(i, priv, shared):
2021-09-28 02:02:44 +08:00
return priv, shared
@nonpure
def _taskred_setup(args):
pass
@nonpure
def _taskred_finish():
pass
@nonpure
def _loop_reductions(args):
pass
2021-09-28 02:02:44 +08:00
iterable, priv, shared = args[0]
P = type(priv)
S = type(shared)
gtid = int(gtid_ptr[0])
loc_ref = _default_loc()
reduction_loc_ref = _reduction_loc()
_loop_loc_and_gtid(loc_ref, reduction_loc_ref, gtid)
_taskred_setup(shared)
2021-09-28 02:02:44 +08:00
if _single_begin(loc_ref, gtid) != 0:
_taskgroup_begin(loc_ref, gtid)
try:
for i in iterable:
priv_fixed, shared_fixed = _fix_privates_and_shareds(i, priv, shared)
2022-01-24 17:57:12 +08:00
_spawn_and_run_task(
loc_ref, gtid, _routine_stub(P=P, S=S, ...).__raw__(), priv_fixed, shared_fixed
2022-01-24 17:57:12 +08:00
)
2021-09-28 02:02:44 +08:00
finally:
_taskgroup_end(loc_ref, gtid)
_single_end(loc_ref, gtid)
_taskred_finish()
_loop_reductions(shared)
_barrier(loc_ref, gtid)
2022-01-24 17:57:12 +08:00
2021-09-28 02:02:44 +08:00
@pure
def get_num_threads():
from C import omp_get_num_threads() -> i32
return int(omp_get_num_threads())
@pure
def get_thread_num():
from C import omp_get_thread_num() -> i32
return int(omp_get_thread_num())
@pure
def get_max_threads():
from C import omp_get_max_threads() -> i32
return int(omp_get_max_threads())
@pure
def get_num_procs():
from C import omp_get_num_procs() -> i32
return int(omp_get_num_procs())
def set_num_threads(num_threads: int):
from C import omp_set_num_threads(i32)
omp_set_num_threads(i32(num_threads))
@pure
def in_parallel():
from C import omp_in_parallel() -> i32
return bool(omp_in_parallel())
def set_dynamic(dynamic_threads: bool = True):
from C import omp_set_dynamic(i32)
omp_set_dynamic(i32(1 if dynamic_threads else 0))
@pure
def get_dynamic():
from C import omp_get_dynamic() -> i32
return bool(omp_get_dynamic())
@pure
def get_cancellation():
from C import omp_get_cancellation() -> i32
return bool(omp_get_cancellation())
def set_schedule(kind: str, chunk_size: int = 0):
from C import omp_set_schedule(i32, i32)
2022-01-24 17:57:12 +08:00
if kind == "static":
2021-09-28 02:02:44 +08:00
omp_set_schedule(i32(1), i32(chunk_size))
2022-01-24 17:57:12 +08:00
elif kind == "dynamic":
2021-09-28 02:02:44 +08:00
omp_set_schedule(i32(2), i32(chunk_size))
2022-01-24 17:57:12 +08:00
elif kind == "guided":
2021-09-28 02:02:44 +08:00
omp_set_schedule(i32(3), i32(chunk_size))
2022-01-24 17:57:12 +08:00
elif kind == "auto":
2021-09-28 02:02:44 +08:00
if chunk_size != 0:
2022-01-24 17:57:12 +08:00
raise ValueError("cannot specify chunk size for auto schedule")
2021-09-28 02:02:44 +08:00
omp_set_schedule(i32(4), i32(chunk_size))
else:
2022-01-24 17:57:12 +08:00
raise ValueError(
"invalid schedule kind; valid ones are: 'static', 'dynamic', 'guided', 'auto'"
)
2021-09-28 02:02:44 +08:00
@pure
def get_schedule():
from C import omp_get_schedule(Ptr[i32], Ptr[i32])
kind_code = i32(0)
chunk_size = i32(0)
omp_get_schedule(__ptr__(kind_code), __ptr__(chunk_size))
idx = int(kind_code)
2022-01-24 17:57:12 +08:00
kind = (
("static", "dynamic", "guided", "auto")[idx - 1] if 1 < idx <= 4 else "unknown"
)
2021-09-28 02:02:44 +08:00
return kind, int(chunk_size)
@pure
def get_thread_limit():
from C import omp_get_thread_limit() -> i32
return int(omp_get_thread_limit())
def set_max_active_levels(max_levels: int):
from C import omp_set_max_active_levels(i32)
omp_set_max_active_levels(i32(max_levels))
@pure
def get_max_active_levels():
from C import omp_get_max_active_levels() -> i32
return int(omp_get_max_active_levels())
@pure
def get_level():
from C import omp_get_level() -> i32
return int(omp_get_level())
@pure
def get_ancestor_thread_num(level: int):
from C import omp_get_ancestor_thread_num(i32) -> i32
return int(omp_get_ancestor_thread_num(i32(level)))
@pure
def get_team_size(level: int):
from C import omp_get_team_size(i32) -> i32
return int(omp_get_team_size(i32(level)))
@pure
def get_active_level():
from C import omp_get_active_level() -> i32
return int(omp_get_active_level())
@pure
def in_final():
from C import omp_in_final() -> i32
return bool(omp_in_final())
@pure
def get_proc_bind():
from C import omp_get_proc_bind() -> i32
result = int(omp_get_proc_bind())
if result < 0 or result > 4:
2022-01-24 17:57:12 +08:00
return "unknown"
return ("false", "true", "master", "close", "spread")[result]
2021-09-28 02:02:44 +08:00
def set_default_device(device_num: int):
from C import omp_set_default_device(i32)
omp_set_default_device(i32(device_num))
@pure
def get_default_device():
from C import omp_get_default_device() -> i32
return int(omp_get_default_device())
@pure
def get_num_devices():
from C import omp_get_num_devices() -> i32
return int(omp_get_num_devices())
@pure
def get_num_teams():
from C import omp_get_num_teams() -> i32
return int(omp_get_num_teams())
@pure
def get_team_num():
from C import omp_get_team_num() -> i32
return int(omp_get_team_num())
@pure
def is_initial_device():
from C import omp_is_initial_device() -> i32
return bool(omp_is_initial_device())
@pure
def get_wtime():
from C import omp_get_wtime() -> float
return omp_get_wtime()
@pure
def get_wtick():
from C import omp_get_wtick() -> float
return omp_get_wtick()
def single(func):
def _wrapper(*args, **kwargs):
gtid = get_thread_num()
loc = _default_loc()
if _single_begin(loc, gtid) != 0:
try:
func(*args, **kwargs)
finally:
_single_end(loc, gtid)
2022-01-24 17:57:12 +08:00
2021-09-28 02:02:44 +08:00
return _wrapper
def master(func):
def _wrapper(*args, **kwargs):
gtid = get_thread_num()
loc = _default_loc()
if _master_begin(loc, gtid) != 0:
try:
func(*args, **kwargs)
finally:
_master_end(loc, gtid)
2022-01-24 17:57:12 +08:00
2021-09-28 02:02:44 +08:00
return _wrapper
def ordered(func):
def _wrapper(*args, **kwargs):
gtid = get_thread_num()
loc = _default_loc()
_ordered_begin(loc, gtid)
try:
func(*args, **kwargs)
finally:
_ordered_end(loc, gtid)
2022-01-24 17:57:12 +08:00
2021-09-28 02:02:44 +08:00
return _wrapper
_default_lock = Lock()
2022-01-24 17:57:12 +08:00
2021-09-28 02:02:44 +08:00
def critical(func):
def _wrapper(*args, **kwargs):
gtid = get_thread_num()
loc = _default_loc()
_critical_begin(loc, gtid, __ptr__(_default_lock))
2021-09-28 02:02:44 +08:00
try:
func(*args, **kwargs)
finally:
_critical_end(loc, gtid, __ptr__(_default_lock))
2022-01-24 17:57:12 +08:00
2021-09-28 02:02:44 +08:00
return _wrapper
def _push_num_threads(num_threads: int):
from C import __kmpc_push_num_threads(Ptr[Ident], i32, i32)
gtid = get_thread_num()
loc = _default_loc()
__kmpc_push_num_threads(loc, i32(gtid), i32(num_threads))
@llvm
Typechecker refactoring (#20) * Initial refactor commit * Support external vars * Simplify refactor; Python scoping [wip] * Python scoping [wip] * Python scoping [fix loops; wip] * Fix lambdas * Python scoping [test fixes; wip] * Fix scoping [wip] * Fix basic tests [no-ci] * Fix tests * CallExpr refactoring [wip] * CallExpr refactoring [wip] * Remove activeUnbounds tracking * Add core.codon * Move Function and other core types to core.codon; Revamp Function and Callable types * Refactor IntExpr, FloatExpr and CallExpr * Refactor ClassStmt * Refactor context, IdExpr and DotExpr * Refactor DotExpr and AssignStmt * Refactor ImportStmt * Refactor FunctionStmt * Refactor * Remove UpdateStmt * Refactor AssignReplacementVisitor * Make SimplifyVisitor in-place * Fix new scoping * Fix import type alias handling * Add docstrings; Complete Simplify refactoring * Fixes for seqtest * Refactor typecheck [wip] * Refactor typecheck [wip] * Refactor typecheck/access; Remove void anduse NoneType; Fix #18 * Refactor typecheck/assign * clang-format and cmake-format * Fix none types in IR * Multi-error support in simplify * Fix IR tests for new void * Simplify ClassStmt * Refactor cond.cpp * Refactor error.cpp * Refactor function.cpp and simplify unbounds * Refactor op.cpp * Refactor call.cpp [wip] [no-ci] * seqassertn updates [noci] * Refactor call.cpp * Refactor call.cpp * Refactor call.cpp * Refactor typecheck * clang-tidy updates [noci] * Refactor infer.cpp [wip] * Refactor infer.cpp * Refactor wrapExpr * Remove visitedAsts * Remove old base logic * Refactor typecheck ctx * Fix JIT bug * Fix JIT tests * Scoping fixes [wip] [noci] * Fix ImperativeForFlow var store * Add newlines [noci] * Dump IR module with log flag * Fix scoping bugs; Add &, ^ and | static operations; Address stylistic review issues * Fix side effect analysis for for-loops * Add support for class variables and ClassVar * Refactor special dot-member cases * Add codon app tests * Fix class variables; clang-tidy * Fix __argv__ * Add datetime constants and update tests * Fix #25; Add Py_None, Py_True and Py_False; External var support [wip] * External var support [wip] * Dump LLVM IR when debug flags are active * clang-format * Fix arg var construction * Extern var fixes * Undo extern var changes related to stdout etc. * Fix tuple magics * Fix extern vars and tuple magics * Fix duplicate var name error * Fix extern vars * Fix #16 * Fix side-effect analysis for try-catch * Move test C var to test executable * Add staticmethod * Fix var status for try-catch * Fix tests * Fix shell var name * Fix test * Fix app test * Fix scoping issue (remove dominated identifier from stack) * Fix no-pie issue * Use PIC when building library object * Don't use -no-pie when building library [noci] * Use -relocation-model=pic in test * Fix lib build on Linux * Fix lib build * Update exceptions to use subclasses vs. header * Fix __repr__ * Fix tests * Fix exceptions test * Don't build docs Co-authored-by: A. R. Shajii <ars@ars.me>
2022-07-27 04:06:00 +08:00
def _atomic_int_add(a: Ptr[int], b: int) -> None:
%old = atomicrmw add ptr %a, i64 %b monotonic
Typechecker refactoring (#20) * Initial refactor commit * Support external vars * Simplify refactor; Python scoping [wip] * Python scoping [wip] * Python scoping [fix loops; wip] * Fix lambdas * Python scoping [test fixes; wip] * Fix scoping [wip] * Fix basic tests [no-ci] * Fix tests * CallExpr refactoring [wip] * CallExpr refactoring [wip] * Remove activeUnbounds tracking * Add core.codon * Move Function and other core types to core.codon; Revamp Function and Callable types * Refactor IntExpr, FloatExpr and CallExpr * Refactor ClassStmt * Refactor context, IdExpr and DotExpr * Refactor DotExpr and AssignStmt * Refactor ImportStmt * Refactor FunctionStmt * Refactor * Remove UpdateStmt * Refactor AssignReplacementVisitor * Make SimplifyVisitor in-place * Fix new scoping * Fix import type alias handling * Add docstrings; Complete Simplify refactoring * Fixes for seqtest * Refactor typecheck [wip] * Refactor typecheck [wip] * Refactor typecheck/access; Remove void anduse NoneType; Fix #18 * Refactor typecheck/assign * clang-format and cmake-format * Fix none types in IR * Multi-error support in simplify * Fix IR tests for new void * Simplify ClassStmt * Refactor cond.cpp * Refactor error.cpp * Refactor function.cpp and simplify unbounds * Refactor op.cpp * Refactor call.cpp [wip] [no-ci] * seqassertn updates [noci] * Refactor call.cpp * Refactor call.cpp * Refactor call.cpp * Refactor typecheck * clang-tidy updates [noci] * Refactor infer.cpp [wip] * Refactor infer.cpp * Refactor wrapExpr * Remove visitedAsts * Remove old base logic * Refactor typecheck ctx * Fix JIT bug * Fix JIT tests * Scoping fixes [wip] [noci] * Fix ImperativeForFlow var store * Add newlines [noci] * Dump IR module with log flag * Fix scoping bugs; Add &, ^ and | static operations; Address stylistic review issues * Fix side effect analysis for for-loops * Add support for class variables and ClassVar * Refactor special dot-member cases * Add codon app tests * Fix class variables; clang-tidy * Fix __argv__ * Add datetime constants and update tests * Fix #25; Add Py_None, Py_True and Py_False; External var support [wip] * External var support [wip] * Dump LLVM IR when debug flags are active * clang-format * Fix arg var construction * Extern var fixes * Undo extern var changes related to stdout etc. * Fix tuple magics * Fix extern vars and tuple magics * Fix duplicate var name error * Fix extern vars * Fix #16 * Fix side-effect analysis for try-catch * Move test C var to test executable * Add staticmethod * Fix var status for try-catch * Fix tests * Fix shell var name * Fix test * Fix app test * Fix scoping issue (remove dominated identifier from stack) * Fix no-pie issue * Use PIC when building library object * Don't use -no-pie when building library [noci] * Use -relocation-model=pic in test * Fix lib build on Linux * Fix lib build * Update exceptions to use subclasses vs. header * Fix __repr__ * Fix tests * Fix exceptions test * Don't build docs Co-authored-by: A. R. Shajii <ars@ars.me>
2022-07-27 04:06:00 +08:00
ret {} {}
2021-09-28 02:02:44 +08:00
def _atomic_int_mul(a: Ptr[int], b: int):
from C import __kmpc_atomic_fixed8_mul(Ptr[Ident], i32, Ptr[int], int)
__kmpc_atomic_fixed8_mul(_default_loc(), i32(0), a, b)
@llvm
Typechecker refactoring (#20) * Initial refactor commit * Support external vars * Simplify refactor; Python scoping [wip] * Python scoping [wip] * Python scoping [fix loops; wip] * Fix lambdas * Python scoping [test fixes; wip] * Fix scoping [wip] * Fix basic tests [no-ci] * Fix tests * CallExpr refactoring [wip] * CallExpr refactoring [wip] * Remove activeUnbounds tracking * Add core.codon * Move Function and other core types to core.codon; Revamp Function and Callable types * Refactor IntExpr, FloatExpr and CallExpr * Refactor ClassStmt * Refactor context, IdExpr and DotExpr * Refactor DotExpr and AssignStmt * Refactor ImportStmt * Refactor FunctionStmt * Refactor * Remove UpdateStmt * Refactor AssignReplacementVisitor * Make SimplifyVisitor in-place * Fix new scoping * Fix import type alias handling * Add docstrings; Complete Simplify refactoring * Fixes for seqtest * Refactor typecheck [wip] * Refactor typecheck [wip] * Refactor typecheck/access; Remove void anduse NoneType; Fix #18 * Refactor typecheck/assign * clang-format and cmake-format * Fix none types in IR * Multi-error support in simplify * Fix IR tests for new void * Simplify ClassStmt * Refactor cond.cpp * Refactor error.cpp * Refactor function.cpp and simplify unbounds * Refactor op.cpp * Refactor call.cpp [wip] [no-ci] * seqassertn updates [noci] * Refactor call.cpp * Refactor call.cpp * Refactor call.cpp * Refactor typecheck * clang-tidy updates [noci] * Refactor infer.cpp [wip] * Refactor infer.cpp * Refactor wrapExpr * Remove visitedAsts * Remove old base logic * Refactor typecheck ctx * Fix JIT bug * Fix JIT tests * Scoping fixes [wip] [noci] * Fix ImperativeForFlow var store * Add newlines [noci] * Dump IR module with log flag * Fix scoping bugs; Add &, ^ and | static operations; Address stylistic review issues * Fix side effect analysis for for-loops * Add support for class variables and ClassVar * Refactor special dot-member cases * Add codon app tests * Fix class variables; clang-tidy * Fix __argv__ * Add datetime constants and update tests * Fix #25; Add Py_None, Py_True and Py_False; External var support [wip] * External var support [wip] * Dump LLVM IR when debug flags are active * clang-format * Fix arg var construction * Extern var fixes * Undo extern var changes related to stdout etc. * Fix tuple magics * Fix extern vars and tuple magics * Fix duplicate var name error * Fix extern vars * Fix #16 * Fix side-effect analysis for try-catch * Move test C var to test executable * Add staticmethod * Fix var status for try-catch * Fix tests * Fix shell var name * Fix test * Fix app test * Fix scoping issue (remove dominated identifier from stack) * Fix no-pie issue * Use PIC when building library object * Don't use -no-pie when building library [noci] * Use -relocation-model=pic in test * Fix lib build on Linux * Fix lib build * Update exceptions to use subclasses vs. header * Fix __repr__ * Fix tests * Fix exceptions test * Don't build docs Co-authored-by: A. R. Shajii <ars@ars.me>
2022-07-27 04:06:00 +08:00
def _atomic_int_and(a: Ptr[int], b: int) -> None:
%old = atomicrmw and ptr %a, i64 %b monotonic
Typechecker refactoring (#20) * Initial refactor commit * Support external vars * Simplify refactor; Python scoping [wip] * Python scoping [wip] * Python scoping [fix loops; wip] * Fix lambdas * Python scoping [test fixes; wip] * Fix scoping [wip] * Fix basic tests [no-ci] * Fix tests * CallExpr refactoring [wip] * CallExpr refactoring [wip] * Remove activeUnbounds tracking * Add core.codon * Move Function and other core types to core.codon; Revamp Function and Callable types * Refactor IntExpr, FloatExpr and CallExpr * Refactor ClassStmt * Refactor context, IdExpr and DotExpr * Refactor DotExpr and AssignStmt * Refactor ImportStmt * Refactor FunctionStmt * Refactor * Remove UpdateStmt * Refactor AssignReplacementVisitor * Make SimplifyVisitor in-place * Fix new scoping * Fix import type alias handling * Add docstrings; Complete Simplify refactoring * Fixes for seqtest * Refactor typecheck [wip] * Refactor typecheck [wip] * Refactor typecheck/access; Remove void anduse NoneType; Fix #18 * Refactor typecheck/assign * clang-format and cmake-format * Fix none types in IR * Multi-error support in simplify * Fix IR tests for new void * Simplify ClassStmt * Refactor cond.cpp * Refactor error.cpp * Refactor function.cpp and simplify unbounds * Refactor op.cpp * Refactor call.cpp [wip] [no-ci] * seqassertn updates [noci] * Refactor call.cpp * Refactor call.cpp * Refactor call.cpp * Refactor typecheck * clang-tidy updates [noci] * Refactor infer.cpp [wip] * Refactor infer.cpp * Refactor wrapExpr * Remove visitedAsts * Remove old base logic * Refactor typecheck ctx * Fix JIT bug * Fix JIT tests * Scoping fixes [wip] [noci] * Fix ImperativeForFlow var store * Add newlines [noci] * Dump IR module with log flag * Fix scoping bugs; Add &, ^ and | static operations; Address stylistic review issues * Fix side effect analysis for for-loops * Add support for class variables and ClassVar * Refactor special dot-member cases * Add codon app tests * Fix class variables; clang-tidy * Fix __argv__ * Add datetime constants and update tests * Fix #25; Add Py_None, Py_True and Py_False; External var support [wip] * External var support [wip] * Dump LLVM IR when debug flags are active * clang-format * Fix arg var construction * Extern var fixes * Undo extern var changes related to stdout etc. * Fix tuple magics * Fix extern vars and tuple magics * Fix duplicate var name error * Fix extern vars * Fix #16 * Fix side-effect analysis for try-catch * Move test C var to test executable * Add staticmethod * Fix var status for try-catch * Fix tests * Fix shell var name * Fix test * Fix app test * Fix scoping issue (remove dominated identifier from stack) * Fix no-pie issue * Use PIC when building library object * Don't use -no-pie when building library [noci] * Use -relocation-model=pic in test * Fix lib build on Linux * Fix lib build * Update exceptions to use subclasses vs. header * Fix __repr__ * Fix tests * Fix exceptions test * Don't build docs Co-authored-by: A. R. Shajii <ars@ars.me>
2022-07-27 04:06:00 +08:00
ret {} {}
2021-09-28 02:02:44 +08:00
@llvm
Typechecker refactoring (#20) * Initial refactor commit * Support external vars * Simplify refactor; Python scoping [wip] * Python scoping [wip] * Python scoping [fix loops; wip] * Fix lambdas * Python scoping [test fixes; wip] * Fix scoping [wip] * Fix basic tests [no-ci] * Fix tests * CallExpr refactoring [wip] * CallExpr refactoring [wip] * Remove activeUnbounds tracking * Add core.codon * Move Function and other core types to core.codon; Revamp Function and Callable types * Refactor IntExpr, FloatExpr and CallExpr * Refactor ClassStmt * Refactor context, IdExpr and DotExpr * Refactor DotExpr and AssignStmt * Refactor ImportStmt * Refactor FunctionStmt * Refactor * Remove UpdateStmt * Refactor AssignReplacementVisitor * Make SimplifyVisitor in-place * Fix new scoping * Fix import type alias handling * Add docstrings; Complete Simplify refactoring * Fixes for seqtest * Refactor typecheck [wip] * Refactor typecheck [wip] * Refactor typecheck/access; Remove void anduse NoneType; Fix #18 * Refactor typecheck/assign * clang-format and cmake-format * Fix none types in IR * Multi-error support in simplify * Fix IR tests for new void * Simplify ClassStmt * Refactor cond.cpp * Refactor error.cpp * Refactor function.cpp and simplify unbounds * Refactor op.cpp * Refactor call.cpp [wip] [no-ci] * seqassertn updates [noci] * Refactor call.cpp * Refactor call.cpp * Refactor call.cpp * Refactor typecheck * clang-tidy updates [noci] * Refactor infer.cpp [wip] * Refactor infer.cpp * Refactor wrapExpr * Remove visitedAsts * Remove old base logic * Refactor typecheck ctx * Fix JIT bug * Fix JIT tests * Scoping fixes [wip] [noci] * Fix ImperativeForFlow var store * Add newlines [noci] * Dump IR module with log flag * Fix scoping bugs; Add &, ^ and | static operations; Address stylistic review issues * Fix side effect analysis for for-loops * Add support for class variables and ClassVar * Refactor special dot-member cases * Add codon app tests * Fix class variables; clang-tidy * Fix __argv__ * Add datetime constants and update tests * Fix #25; Add Py_None, Py_True and Py_False; External var support [wip] * External var support [wip] * Dump LLVM IR when debug flags are active * clang-format * Fix arg var construction * Extern var fixes * Undo extern var changes related to stdout etc. * Fix tuple magics * Fix extern vars and tuple magics * Fix duplicate var name error * Fix extern vars * Fix #16 * Fix side-effect analysis for try-catch * Move test C var to test executable * Add staticmethod * Fix var status for try-catch * Fix tests * Fix shell var name * Fix test * Fix app test * Fix scoping issue (remove dominated identifier from stack) * Fix no-pie issue * Use PIC when building library object * Don't use -no-pie when building library [noci] * Use -relocation-model=pic in test * Fix lib build on Linux * Fix lib build * Update exceptions to use subclasses vs. header * Fix __repr__ * Fix tests * Fix exceptions test * Don't build docs Co-authored-by: A. R. Shajii <ars@ars.me>
2022-07-27 04:06:00 +08:00
def _atomic_int_or(a: Ptr[int], b: int) -> None:
%old = atomicrmw or ptr %a, i64 %b monotonic
Typechecker refactoring (#20) * Initial refactor commit * Support external vars * Simplify refactor; Python scoping [wip] * Python scoping [wip] * Python scoping [fix loops; wip] * Fix lambdas * Python scoping [test fixes; wip] * Fix scoping [wip] * Fix basic tests [no-ci] * Fix tests * CallExpr refactoring [wip] * CallExpr refactoring [wip] * Remove activeUnbounds tracking * Add core.codon * Move Function and other core types to core.codon; Revamp Function and Callable types * Refactor IntExpr, FloatExpr and CallExpr * Refactor ClassStmt * Refactor context, IdExpr and DotExpr * Refactor DotExpr and AssignStmt * Refactor ImportStmt * Refactor FunctionStmt * Refactor * Remove UpdateStmt * Refactor AssignReplacementVisitor * Make SimplifyVisitor in-place * Fix new scoping * Fix import type alias handling * Add docstrings; Complete Simplify refactoring * Fixes for seqtest * Refactor typecheck [wip] * Refactor typecheck [wip] * Refactor typecheck/access; Remove void anduse NoneType; Fix #18 * Refactor typecheck/assign * clang-format and cmake-format * Fix none types in IR * Multi-error support in simplify * Fix IR tests for new void * Simplify ClassStmt * Refactor cond.cpp * Refactor error.cpp * Refactor function.cpp and simplify unbounds * Refactor op.cpp * Refactor call.cpp [wip] [no-ci] * seqassertn updates [noci] * Refactor call.cpp * Refactor call.cpp * Refactor call.cpp * Refactor typecheck * clang-tidy updates [noci] * Refactor infer.cpp [wip] * Refactor infer.cpp * Refactor wrapExpr * Remove visitedAsts * Remove old base logic * Refactor typecheck ctx * Fix JIT bug * Fix JIT tests * Scoping fixes [wip] [noci] * Fix ImperativeForFlow var store * Add newlines [noci] * Dump IR module with log flag * Fix scoping bugs; Add &, ^ and | static operations; Address stylistic review issues * Fix side effect analysis for for-loops * Add support for class variables and ClassVar * Refactor special dot-member cases * Add codon app tests * Fix class variables; clang-tidy * Fix __argv__ * Add datetime constants and update tests * Fix #25; Add Py_None, Py_True and Py_False; External var support [wip] * External var support [wip] * Dump LLVM IR when debug flags are active * clang-format * Fix arg var construction * Extern var fixes * Undo extern var changes related to stdout etc. * Fix tuple magics * Fix extern vars and tuple magics * Fix duplicate var name error * Fix extern vars * Fix #16 * Fix side-effect analysis for try-catch * Move test C var to test executable * Add staticmethod * Fix var status for try-catch * Fix tests * Fix shell var name * Fix test * Fix app test * Fix scoping issue (remove dominated identifier from stack) * Fix no-pie issue * Use PIC when building library object * Don't use -no-pie when building library [noci] * Use -relocation-model=pic in test * Fix lib build on Linux * Fix lib build * Update exceptions to use subclasses vs. header * Fix __repr__ * Fix tests * Fix exceptions test * Don't build docs Co-authored-by: A. R. Shajii <ars@ars.me>
2022-07-27 04:06:00 +08:00
ret {} {}
2021-09-28 02:02:44 +08:00
@llvm
Typechecker refactoring (#20) * Initial refactor commit * Support external vars * Simplify refactor; Python scoping [wip] * Python scoping [wip] * Python scoping [fix loops; wip] * Fix lambdas * Python scoping [test fixes; wip] * Fix scoping [wip] * Fix basic tests [no-ci] * Fix tests * CallExpr refactoring [wip] * CallExpr refactoring [wip] * Remove activeUnbounds tracking * Add core.codon * Move Function and other core types to core.codon; Revamp Function and Callable types * Refactor IntExpr, FloatExpr and CallExpr * Refactor ClassStmt * Refactor context, IdExpr and DotExpr * Refactor DotExpr and AssignStmt * Refactor ImportStmt * Refactor FunctionStmt * Refactor * Remove UpdateStmt * Refactor AssignReplacementVisitor * Make SimplifyVisitor in-place * Fix new scoping * Fix import type alias handling * Add docstrings; Complete Simplify refactoring * Fixes for seqtest * Refactor typecheck [wip] * Refactor typecheck [wip] * Refactor typecheck/access; Remove void anduse NoneType; Fix #18 * Refactor typecheck/assign * clang-format and cmake-format * Fix none types in IR * Multi-error support in simplify * Fix IR tests for new void * Simplify ClassStmt * Refactor cond.cpp * Refactor error.cpp * Refactor function.cpp and simplify unbounds * Refactor op.cpp * Refactor call.cpp [wip] [no-ci] * seqassertn updates [noci] * Refactor call.cpp * Refactor call.cpp * Refactor call.cpp * Refactor typecheck * clang-tidy updates [noci] * Refactor infer.cpp [wip] * Refactor infer.cpp * Refactor wrapExpr * Remove visitedAsts * Remove old base logic * Refactor typecheck ctx * Fix JIT bug * Fix JIT tests * Scoping fixes [wip] [noci] * Fix ImperativeForFlow var store * Add newlines [noci] * Dump IR module with log flag * Fix scoping bugs; Add &, ^ and | static operations; Address stylistic review issues * Fix side effect analysis for for-loops * Add support for class variables and ClassVar * Refactor special dot-member cases * Add codon app tests * Fix class variables; clang-tidy * Fix __argv__ * Add datetime constants and update tests * Fix #25; Add Py_None, Py_True and Py_False; External var support [wip] * External var support [wip] * Dump LLVM IR when debug flags are active * clang-format * Fix arg var construction * Extern var fixes * Undo extern var changes related to stdout etc. * Fix tuple magics * Fix extern vars and tuple magics * Fix duplicate var name error * Fix extern vars * Fix #16 * Fix side-effect analysis for try-catch * Move test C var to test executable * Add staticmethod * Fix var status for try-catch * Fix tests * Fix shell var name * Fix test * Fix app test * Fix scoping issue (remove dominated identifier from stack) * Fix no-pie issue * Use PIC when building library object * Don't use -no-pie when building library [noci] * Use -relocation-model=pic in test * Fix lib build on Linux * Fix lib build * Update exceptions to use subclasses vs. header * Fix __repr__ * Fix tests * Fix exceptions test * Don't build docs Co-authored-by: A. R. Shajii <ars@ars.me>
2022-07-27 04:06:00 +08:00
def _atomic_int_xor(a: Ptr[int], b: int) -> None:
%old = atomicrmw xor ptr %a, i64 %b monotonic
Typechecker refactoring (#20) * Initial refactor commit * Support external vars * Simplify refactor; Python scoping [wip] * Python scoping [wip] * Python scoping [fix loops; wip] * Fix lambdas * Python scoping [test fixes; wip] * Fix scoping [wip] * Fix basic tests [no-ci] * Fix tests * CallExpr refactoring [wip] * CallExpr refactoring [wip] * Remove activeUnbounds tracking * Add core.codon * Move Function and other core types to core.codon; Revamp Function and Callable types * Refactor IntExpr, FloatExpr and CallExpr * Refactor ClassStmt * Refactor context, IdExpr and DotExpr * Refactor DotExpr and AssignStmt * Refactor ImportStmt * Refactor FunctionStmt * Refactor * Remove UpdateStmt * Refactor AssignReplacementVisitor * Make SimplifyVisitor in-place * Fix new scoping * Fix import type alias handling * Add docstrings; Complete Simplify refactoring * Fixes for seqtest * Refactor typecheck [wip] * Refactor typecheck [wip] * Refactor typecheck/access; Remove void anduse NoneType; Fix #18 * Refactor typecheck/assign * clang-format and cmake-format * Fix none types in IR * Multi-error support in simplify * Fix IR tests for new void * Simplify ClassStmt * Refactor cond.cpp * Refactor error.cpp * Refactor function.cpp and simplify unbounds * Refactor op.cpp * Refactor call.cpp [wip] [no-ci] * seqassertn updates [noci] * Refactor call.cpp * Refactor call.cpp * Refactor call.cpp * Refactor typecheck * clang-tidy updates [noci] * Refactor infer.cpp [wip] * Refactor infer.cpp * Refactor wrapExpr * Remove visitedAsts * Remove old base logic * Refactor typecheck ctx * Fix JIT bug * Fix JIT tests * Scoping fixes [wip] [noci] * Fix ImperativeForFlow var store * Add newlines [noci] * Dump IR module with log flag * Fix scoping bugs; Add &, ^ and | static operations; Address stylistic review issues * Fix side effect analysis for for-loops * Add support for class variables and ClassVar * Refactor special dot-member cases * Add codon app tests * Fix class variables; clang-tidy * Fix __argv__ * Add datetime constants and update tests * Fix #25; Add Py_None, Py_True and Py_False; External var support [wip] * External var support [wip] * Dump LLVM IR when debug flags are active * clang-format * Fix arg var construction * Extern var fixes * Undo extern var changes related to stdout etc. * Fix tuple magics * Fix extern vars and tuple magics * Fix duplicate var name error * Fix extern vars * Fix #16 * Fix side-effect analysis for try-catch * Move test C var to test executable * Add staticmethod * Fix var status for try-catch * Fix tests * Fix shell var name * Fix test * Fix app test * Fix scoping issue (remove dominated identifier from stack) * Fix no-pie issue * Use PIC when building library object * Don't use -no-pie when building library [noci] * Use -relocation-model=pic in test * Fix lib build on Linux * Fix lib build * Update exceptions to use subclasses vs. header * Fix __repr__ * Fix tests * Fix exceptions test * Don't build docs Co-authored-by: A. R. Shajii <ars@ars.me>
2022-07-27 04:06:00 +08:00
ret {} {}
2021-09-28 02:02:44 +08:00
@llvm
Typechecker refactoring (#20) * Initial refactor commit * Support external vars * Simplify refactor; Python scoping [wip] * Python scoping [wip] * Python scoping [fix loops; wip] * Fix lambdas * Python scoping [test fixes; wip] * Fix scoping [wip] * Fix basic tests [no-ci] * Fix tests * CallExpr refactoring [wip] * CallExpr refactoring [wip] * Remove activeUnbounds tracking * Add core.codon * Move Function and other core types to core.codon; Revamp Function and Callable types * Refactor IntExpr, FloatExpr and CallExpr * Refactor ClassStmt * Refactor context, IdExpr and DotExpr * Refactor DotExpr and AssignStmt * Refactor ImportStmt * Refactor FunctionStmt * Refactor * Remove UpdateStmt * Refactor AssignReplacementVisitor * Make SimplifyVisitor in-place * Fix new scoping * Fix import type alias handling * Add docstrings; Complete Simplify refactoring * Fixes for seqtest * Refactor typecheck [wip] * Refactor typecheck [wip] * Refactor typecheck/access; Remove void anduse NoneType; Fix #18 * Refactor typecheck/assign * clang-format and cmake-format * Fix none types in IR * Multi-error support in simplify * Fix IR tests for new void * Simplify ClassStmt * Refactor cond.cpp * Refactor error.cpp * Refactor function.cpp and simplify unbounds * Refactor op.cpp * Refactor call.cpp [wip] [no-ci] * seqassertn updates [noci] * Refactor call.cpp * Refactor call.cpp * Refactor call.cpp * Refactor typecheck * clang-tidy updates [noci] * Refactor infer.cpp [wip] * Refactor infer.cpp * Refactor wrapExpr * Remove visitedAsts * Remove old base logic * Refactor typecheck ctx * Fix JIT bug * Fix JIT tests * Scoping fixes [wip] [noci] * Fix ImperativeForFlow var store * Add newlines [noci] * Dump IR module with log flag * Fix scoping bugs; Add &, ^ and | static operations; Address stylistic review issues * Fix side effect analysis for for-loops * Add support for class variables and ClassVar * Refactor special dot-member cases * Add codon app tests * Fix class variables; clang-tidy * Fix __argv__ * Add datetime constants and update tests * Fix #25; Add Py_None, Py_True and Py_False; External var support [wip] * External var support [wip] * Dump LLVM IR when debug flags are active * clang-format * Fix arg var construction * Extern var fixes * Undo extern var changes related to stdout etc. * Fix tuple magics * Fix extern vars and tuple magics * Fix duplicate var name error * Fix extern vars * Fix #16 * Fix side-effect analysis for try-catch * Move test C var to test executable * Add staticmethod * Fix var status for try-catch * Fix tests * Fix shell var name * Fix test * Fix app test * Fix scoping issue (remove dominated identifier from stack) * Fix no-pie issue * Use PIC when building library object * Don't use -no-pie when building library [noci] * Use -relocation-model=pic in test * Fix lib build on Linux * Fix lib build * Update exceptions to use subclasses vs. header * Fix __repr__ * Fix tests * Fix exceptions test * Don't build docs Co-authored-by: A. R. Shajii <ars@ars.me>
2022-07-27 04:06:00 +08:00
def _atomic_int_min(a: Ptr[int], b: int) -> None:
%old = atomicrmw min ptr %a, i64 %b monotonic
Typechecker refactoring (#20) * Initial refactor commit * Support external vars * Simplify refactor; Python scoping [wip] * Python scoping [wip] * Python scoping [fix loops; wip] * Fix lambdas * Python scoping [test fixes; wip] * Fix scoping [wip] * Fix basic tests [no-ci] * Fix tests * CallExpr refactoring [wip] * CallExpr refactoring [wip] * Remove activeUnbounds tracking * Add core.codon * Move Function and other core types to core.codon; Revamp Function and Callable types * Refactor IntExpr, FloatExpr and CallExpr * Refactor ClassStmt * Refactor context, IdExpr and DotExpr * Refactor DotExpr and AssignStmt * Refactor ImportStmt * Refactor FunctionStmt * Refactor * Remove UpdateStmt * Refactor AssignReplacementVisitor * Make SimplifyVisitor in-place * Fix new scoping * Fix import type alias handling * Add docstrings; Complete Simplify refactoring * Fixes for seqtest * Refactor typecheck [wip] * Refactor typecheck [wip] * Refactor typecheck/access; Remove void anduse NoneType; Fix #18 * Refactor typecheck/assign * clang-format and cmake-format * Fix none types in IR * Multi-error support in simplify * Fix IR tests for new void * Simplify ClassStmt * Refactor cond.cpp * Refactor error.cpp * Refactor function.cpp and simplify unbounds * Refactor op.cpp * Refactor call.cpp [wip] [no-ci] * seqassertn updates [noci] * Refactor call.cpp * Refactor call.cpp * Refactor call.cpp * Refactor typecheck * clang-tidy updates [noci] * Refactor infer.cpp [wip] * Refactor infer.cpp * Refactor wrapExpr * Remove visitedAsts * Remove old base logic * Refactor typecheck ctx * Fix JIT bug * Fix JIT tests * Scoping fixes [wip] [noci] * Fix ImperativeForFlow var store * Add newlines [noci] * Dump IR module with log flag * Fix scoping bugs; Add &, ^ and | static operations; Address stylistic review issues * Fix side effect analysis for for-loops * Add support for class variables and ClassVar * Refactor special dot-member cases * Add codon app tests * Fix class variables; clang-tidy * Fix __argv__ * Add datetime constants and update tests * Fix #25; Add Py_None, Py_True and Py_False; External var support [wip] * External var support [wip] * Dump LLVM IR when debug flags are active * clang-format * Fix arg var construction * Extern var fixes * Undo extern var changes related to stdout etc. * Fix tuple magics * Fix extern vars and tuple magics * Fix duplicate var name error * Fix extern vars * Fix #16 * Fix side-effect analysis for try-catch * Move test C var to test executable * Add staticmethod * Fix var status for try-catch * Fix tests * Fix shell var name * Fix test * Fix app test * Fix scoping issue (remove dominated identifier from stack) * Fix no-pie issue * Use PIC when building library object * Don't use -no-pie when building library [noci] * Use -relocation-model=pic in test * Fix lib build on Linux * Fix lib build * Update exceptions to use subclasses vs. header * Fix __repr__ * Fix tests * Fix exceptions test * Don't build docs Co-authored-by: A. R. Shajii <ars@ars.me>
2022-07-27 04:06:00 +08:00
ret {} {}
2021-09-28 02:02:44 +08:00
@llvm
Typechecker refactoring (#20) * Initial refactor commit * Support external vars * Simplify refactor; Python scoping [wip] * Python scoping [wip] * Python scoping [fix loops; wip] * Fix lambdas * Python scoping [test fixes; wip] * Fix scoping [wip] * Fix basic tests [no-ci] * Fix tests * CallExpr refactoring [wip] * CallExpr refactoring [wip] * Remove activeUnbounds tracking * Add core.codon * Move Function and other core types to core.codon; Revamp Function and Callable types * Refactor IntExpr, FloatExpr and CallExpr * Refactor ClassStmt * Refactor context, IdExpr and DotExpr * Refactor DotExpr and AssignStmt * Refactor ImportStmt * Refactor FunctionStmt * Refactor * Remove UpdateStmt * Refactor AssignReplacementVisitor * Make SimplifyVisitor in-place * Fix new scoping * Fix import type alias handling * Add docstrings; Complete Simplify refactoring * Fixes for seqtest * Refactor typecheck [wip] * Refactor typecheck [wip] * Refactor typecheck/access; Remove void anduse NoneType; Fix #18 * Refactor typecheck/assign * clang-format and cmake-format * Fix none types in IR * Multi-error support in simplify * Fix IR tests for new void * Simplify ClassStmt * Refactor cond.cpp * Refactor error.cpp * Refactor function.cpp and simplify unbounds * Refactor op.cpp * Refactor call.cpp [wip] [no-ci] * seqassertn updates [noci] * Refactor call.cpp * Refactor call.cpp * Refactor call.cpp * Refactor typecheck * clang-tidy updates [noci] * Refactor infer.cpp [wip] * Refactor infer.cpp * Refactor wrapExpr * Remove visitedAsts * Remove old base logic * Refactor typecheck ctx * Fix JIT bug * Fix JIT tests * Scoping fixes [wip] [noci] * Fix ImperativeForFlow var store * Add newlines [noci] * Dump IR module with log flag * Fix scoping bugs; Add &, ^ and | static operations; Address stylistic review issues * Fix side effect analysis for for-loops * Add support for class variables and ClassVar * Refactor special dot-member cases * Add codon app tests * Fix class variables; clang-tidy * Fix __argv__ * Add datetime constants and update tests * Fix #25; Add Py_None, Py_True and Py_False; External var support [wip] * External var support [wip] * Dump LLVM IR when debug flags are active * clang-format * Fix arg var construction * Extern var fixes * Undo extern var changes related to stdout etc. * Fix tuple magics * Fix extern vars and tuple magics * Fix duplicate var name error * Fix extern vars * Fix #16 * Fix side-effect analysis for try-catch * Move test C var to test executable * Add staticmethod * Fix var status for try-catch * Fix tests * Fix shell var name * Fix test * Fix app test * Fix scoping issue (remove dominated identifier from stack) * Fix no-pie issue * Use PIC when building library object * Don't use -no-pie when building library [noci] * Use -relocation-model=pic in test * Fix lib build on Linux * Fix lib build * Update exceptions to use subclasses vs. header * Fix __repr__ * Fix tests * Fix exceptions test * Don't build docs Co-authored-by: A. R. Shajii <ars@ars.me>
2022-07-27 04:06:00 +08:00
def _atomic_int_max(a: Ptr[int], b: int) -> None:
%old = atomicrmw max ptr %a, i64 %b monotonic
Typechecker refactoring (#20) * Initial refactor commit * Support external vars * Simplify refactor; Python scoping [wip] * Python scoping [wip] * Python scoping [fix loops; wip] * Fix lambdas * Python scoping [test fixes; wip] * Fix scoping [wip] * Fix basic tests [no-ci] * Fix tests * CallExpr refactoring [wip] * CallExpr refactoring [wip] * Remove activeUnbounds tracking * Add core.codon * Move Function and other core types to core.codon; Revamp Function and Callable types * Refactor IntExpr, FloatExpr and CallExpr * Refactor ClassStmt * Refactor context, IdExpr and DotExpr * Refactor DotExpr and AssignStmt * Refactor ImportStmt * Refactor FunctionStmt * Refactor * Remove UpdateStmt * Refactor AssignReplacementVisitor * Make SimplifyVisitor in-place * Fix new scoping * Fix import type alias handling * Add docstrings; Complete Simplify refactoring * Fixes for seqtest * Refactor typecheck [wip] * Refactor typecheck [wip] * Refactor typecheck/access; Remove void anduse NoneType; Fix #18 * Refactor typecheck/assign * clang-format and cmake-format * Fix none types in IR * Multi-error support in simplify * Fix IR tests for new void * Simplify ClassStmt * Refactor cond.cpp * Refactor error.cpp * Refactor function.cpp and simplify unbounds * Refactor op.cpp * Refactor call.cpp [wip] [no-ci] * seqassertn updates [noci] * Refactor call.cpp * Refactor call.cpp * Refactor call.cpp * Refactor typecheck * clang-tidy updates [noci] * Refactor infer.cpp [wip] * Refactor infer.cpp * Refactor wrapExpr * Remove visitedAsts * Remove old base logic * Refactor typecheck ctx * Fix JIT bug * Fix JIT tests * Scoping fixes [wip] [noci] * Fix ImperativeForFlow var store * Add newlines [noci] * Dump IR module with log flag * Fix scoping bugs; Add &, ^ and | static operations; Address stylistic review issues * Fix side effect analysis for for-loops * Add support for class variables and ClassVar * Refactor special dot-member cases * Add codon app tests * Fix class variables; clang-tidy * Fix __argv__ * Add datetime constants and update tests * Fix #25; Add Py_None, Py_True and Py_False; External var support [wip] * External var support [wip] * Dump LLVM IR when debug flags are active * clang-format * Fix arg var construction * Extern var fixes * Undo extern var changes related to stdout etc. * Fix tuple magics * Fix extern vars and tuple magics * Fix duplicate var name error * Fix extern vars * Fix #16 * Fix side-effect analysis for try-catch * Move test C var to test executable * Add staticmethod * Fix var status for try-catch * Fix tests * Fix shell var name * Fix test * Fix app test * Fix scoping issue (remove dominated identifier from stack) * Fix no-pie issue * Use PIC when building library object * Don't use -no-pie when building library [noci] * Use -relocation-model=pic in test * Fix lib build on Linux * Fix lib build * Update exceptions to use subclasses vs. header * Fix __repr__ * Fix tests * Fix exceptions test * Don't build docs Co-authored-by: A. R. Shajii <ars@ars.me>
2022-07-27 04:06:00 +08:00
ret {} {}
2021-09-28 02:02:44 +08:00
Typechecker refactoring (#20) * Initial refactor commit * Support external vars * Simplify refactor; Python scoping [wip] * Python scoping [wip] * Python scoping [fix loops; wip] * Fix lambdas * Python scoping [test fixes; wip] * Fix scoping [wip] * Fix basic tests [no-ci] * Fix tests * CallExpr refactoring [wip] * CallExpr refactoring [wip] * Remove activeUnbounds tracking * Add core.codon * Move Function and other core types to core.codon; Revamp Function and Callable types * Refactor IntExpr, FloatExpr and CallExpr * Refactor ClassStmt * Refactor context, IdExpr and DotExpr * Refactor DotExpr and AssignStmt * Refactor ImportStmt * Refactor FunctionStmt * Refactor * Remove UpdateStmt * Refactor AssignReplacementVisitor * Make SimplifyVisitor in-place * Fix new scoping * Fix import type alias handling * Add docstrings; Complete Simplify refactoring * Fixes for seqtest * Refactor typecheck [wip] * Refactor typecheck [wip] * Refactor typecheck/access; Remove void anduse NoneType; Fix #18 * Refactor typecheck/assign * clang-format and cmake-format * Fix none types in IR * Multi-error support in simplify * Fix IR tests for new void * Simplify ClassStmt * Refactor cond.cpp * Refactor error.cpp * Refactor function.cpp and simplify unbounds * Refactor op.cpp * Refactor call.cpp [wip] [no-ci] * seqassertn updates [noci] * Refactor call.cpp * Refactor call.cpp * Refactor call.cpp * Refactor typecheck * clang-tidy updates [noci] * Refactor infer.cpp [wip] * Refactor infer.cpp * Refactor wrapExpr * Remove visitedAsts * Remove old base logic * Refactor typecheck ctx * Fix JIT bug * Fix JIT tests * Scoping fixes [wip] [noci] * Fix ImperativeForFlow var store * Add newlines [noci] * Dump IR module with log flag * Fix scoping bugs; Add &, ^ and | static operations; Address stylistic review issues * Fix side effect analysis for for-loops * Add support for class variables and ClassVar * Refactor special dot-member cases * Add codon app tests * Fix class variables; clang-tidy * Fix __argv__ * Add datetime constants and update tests * Fix #25; Add Py_None, Py_True and Py_False; External var support [wip] * External var support [wip] * Dump LLVM IR when debug flags are active * clang-format * Fix arg var construction * Extern var fixes * Undo extern var changes related to stdout etc. * Fix tuple magics * Fix extern vars and tuple magics * Fix duplicate var name error * Fix extern vars * Fix #16 * Fix side-effect analysis for try-catch * Move test C var to test executable * Add staticmethod * Fix var status for try-catch * Fix tests * Fix shell var name * Fix test * Fix app test * Fix scoping issue (remove dominated identifier from stack) * Fix no-pie issue * Use PIC when building library object * Don't use -no-pie when building library [noci] * Use -relocation-model=pic in test * Fix lib build on Linux * Fix lib build * Update exceptions to use subclasses vs. header * Fix __repr__ * Fix tests * Fix exceptions test * Don't build docs Co-authored-by: A. R. Shajii <ars@ars.me>
2022-07-27 04:06:00 +08:00
def _atomic_float_add(a: Ptr[float], b: float) -> None:
from C import __kmpc_atomic_float8_add(Ptr[Ident], i32, Ptr[float], float)
__kmpc_atomic_float8_add(_default_loc(), i32(0), a, b)
2021-09-28 02:02:44 +08:00
def _atomic_float_mul(a: Ptr[float], b: float):
from C import __kmpc_atomic_float8_mul(Ptr[Ident], i32, Ptr[float], float)
__kmpc_atomic_float8_mul(_default_loc(), i32(0), a, b)
2021-09-28 02:02:44 +08:00
def _atomic_float_min(a: Ptr[float], b: float):
from C import __kmpc_atomic_float8_min(Ptr[Ident], i32, Ptr[float], float)
__kmpc_atomic_float8_min(_default_loc(), i32(0), a, b)
2021-09-28 02:02:44 +08:00
2022-02-16 23:51:16 +08:00
def _atomic_float_max(a: Ptr[float], b: float):
2021-09-28 02:02:44 +08:00
from C import __kmpc_atomic_float8_max(Ptr[Ident], i32, Ptr[float], float)
__kmpc_atomic_float8_max(_default_loc(), i32(0), a, b)
2021-09-28 02:02:44 +08:00
GPU and other updates (#52) * Add nvptx pass * Fix spaces * Don't change name * Add runtime support * Add init call * Add more runtime functions * Add launch function * Add intrinsics * Fix codegen * Run GPU pass between general opt passes * Set data layout * Create context * Link libdevice * Add function remapping * Fix linkage * Fix libdevice link * Fix linking * Fix personality * Fix linking * Fix linking * Fix linking * Add internalize pass * Add more math conversions * Add more re-mappings * Fix conversions * Fix __str__ * Add decorator attribute for any decorator * Update kernel decorator * Fix kernel decorator * Fix kernel decorator * Fix kernel decorator * Fix kernel decorator * Remove old decorator * Fix pointer calc * Fix fill-in codegen * Fix linkage * Add comment * Update list conversion * Add more conversions * Add dict and set conversions * Add float32 type to IR/LLVM * Add float32 * Add float32 stdlib * Keep required global values in PTX module * Fix PTX module pruning * Fix malloc * Set will-return * Fix name cleanup * Fix access * Fix name cleanup * Fix function renaming * Update dimension API * Fix args * Clean up API * Move GPU transformations to end of opt pipeline * Fix alloc replacements * Fix naming * Target PTX 4.2 * Fix global renaming * Fix early return in static blocks; Add __realized__ function * Format * Add __llvm_name__ for functions * Add vector type to IR * SIMD support [wip] * Update kernel naming * Fix early returns; Fix SIMD calls * Fix kernel naming * Fix IR matcher * Remove module print * Update realloc * Add overloads for 32-bit float math ops * Add gpu.Pointer type for working with raw pointers * Add float32 conversion * Add to_gpu and from_gpu * clang-format * Add f32 reduction support to OpenMP * Fix automatic GPU class conversions * Fix conversion functions * Fix conversions * Rename self * Fix tuple conversion * Fix conversions * Fix conversions * Update PTX filename * Fix filename * Add raw function * Add GPU docs * Allow nested object conversions * Add tests (WIP) * Update SIMD * Add staticrange and statictuple loop support * SIMD updates * Add new Vec constructors * Fix UInt conversion * Fix size-0 allocs * Add more tests * Add matmul test * Rename gpu test file * Add more tests * Add alloc cache * Fix object_to_gpu * Fix frees * Fix str conversion * Fix set conversion * Fix conversions * Fix class conversion * Fix str conversion * Fix byte conversion * Fix list conversion * Fix pointer conversions * Fix conversions * Fix conversions * Update tests * Fix conversions * Fix tuple conversion * Fix tuple conversion * Fix auto conversions * Fix conversion * Fix magics * Update tests * Support GPU in JIT mode * Fix GPU+JIT * Fix kernel filename in JIT mode * Add __static_print__; Add earlyDefines; Various domination bugfixes; SimplifyContext RAII base handling * Fix global static handling * Fix float32 tests * FIx gpu module * Support OpenMP "collapse" option * Add more collapse tests * Capture generics and statics * TraitVar handling * Python exceptions / isinstance [wip; no_ci] * clang-format * Add list comparison operators * Support empty raise in IR * Add dict 'or' operator * Fix repr * Add copy module * Fix spacing * Use sm_30 * Python exceptions * TypeTrait support; Fix defaultDict * Fix earlyDefines * Add defaultdict * clang-format * Fix invalid canonicalizations * Fix empty raise * Fix copyright * Add Python numerics option * Support py-numerics in math module * Update docs * Add static Python division / modulus * Add static py numerics tests * Fix staticrange/tuple; Add KwTuple.__getitem__ * clang-format * Add gpu parameter to par * Fix globals * Don't init loop vars on loop collapse * Add par-gpu tests * Update gpu docs * Fix isinstance check * Remove invalid test * Add -libdevice to set custom path [skip ci] * Add release notes; bump version [skip ci] * Add libdevice docs [skip ci] Co-authored-by: Ibrahim Numanagić <ibrahimpasa@gmail.com>
2022-09-16 03:40:00 +08:00
def _atomic_float32_add(a: Ptr[float32], b: float32) -> None:
from C import __kmpc_atomic_float4_add(Ptr[Ident], i32, Ptr[float32], float32)
__kmpc_atomic_float4_add(_default_loc(), i32(0), a, b)
def _atomic_float32_mul(a: Ptr[float32], b: float32):
from C import __kmpc_atomic_float4_mul(Ptr[Ident], i32, Ptr[float32], float32)
__kmpc_atomic_float4_mul(_default_loc(), i32(0), a, b)
def _atomic_float32_min(a: Ptr[float32], b: float32) -> None:
from C import __kmpc_atomic_float4_min(Ptr[Ident], i32, Ptr[float32], float32)
__kmpc_atomic_float4_min(_default_loc(), i32(0), a, b)
def _atomic_float32_max(a: Ptr[float32], b: float32) -> None:
from C import __kmpc_atomic_float4_max(Ptr[Ident], i32, Ptr[float32], float32)
__kmpc_atomic_float4_max(_default_loc(), i32(0), a, b)
def _range_len(start: int, stop: int, step: int):
if step > 0 and start < stop:
return 1 + (stop - 1 - start) // step
elif step < 0 and start > stop:
return 1 + (start - 1 - stop) // (-step)
else:
return 0
2021-09-28 02:02:44 +08:00
def for_par(
num_threads: int = -1,
chunk_size: int = -1,
schedule: Static[str] = "static",
2022-01-24 17:57:12 +08:00
ordered: Static[int] = False,
GPU and other updates (#52) * Add nvptx pass * Fix spaces * Don't change name * Add runtime support * Add init call * Add more runtime functions * Add launch function * Add intrinsics * Fix codegen * Run GPU pass between general opt passes * Set data layout * Create context * Link libdevice * Add function remapping * Fix linkage * Fix libdevice link * Fix linking * Fix personality * Fix linking * Fix linking * Fix linking * Add internalize pass * Add more math conversions * Add more re-mappings * Fix conversions * Fix __str__ * Add decorator attribute for any decorator * Update kernel decorator * Fix kernel decorator * Fix kernel decorator * Fix kernel decorator * Fix kernel decorator * Remove old decorator * Fix pointer calc * Fix fill-in codegen * Fix linkage * Add comment * Update list conversion * Add more conversions * Add dict and set conversions * Add float32 type to IR/LLVM * Add float32 * Add float32 stdlib * Keep required global values in PTX module * Fix PTX module pruning * Fix malloc * Set will-return * Fix name cleanup * Fix access * Fix name cleanup * Fix function renaming * Update dimension API * Fix args * Clean up API * Move GPU transformations to end of opt pipeline * Fix alloc replacements * Fix naming * Target PTX 4.2 * Fix global renaming * Fix early return in static blocks; Add __realized__ function * Format * Add __llvm_name__ for functions * Add vector type to IR * SIMD support [wip] * Update kernel naming * Fix early returns; Fix SIMD calls * Fix kernel naming * Fix IR matcher * Remove module print * Update realloc * Add overloads for 32-bit float math ops * Add gpu.Pointer type for working with raw pointers * Add float32 conversion * Add to_gpu and from_gpu * clang-format * Add f32 reduction support to OpenMP * Fix automatic GPU class conversions * Fix conversion functions * Fix conversions * Rename self * Fix tuple conversion * Fix conversions * Fix conversions * Update PTX filename * Fix filename * Add raw function * Add GPU docs * Allow nested object conversions * Add tests (WIP) * Update SIMD * Add staticrange and statictuple loop support * SIMD updates * Add new Vec constructors * Fix UInt conversion * Fix size-0 allocs * Add more tests * Add matmul test * Rename gpu test file * Add more tests * Add alloc cache * Fix object_to_gpu * Fix frees * Fix str conversion * Fix set conversion * Fix conversions * Fix class conversion * Fix str conversion * Fix byte conversion * Fix list conversion * Fix pointer conversions * Fix conversions * Fix conversions * Update tests * Fix conversions * Fix tuple conversion * Fix tuple conversion * Fix auto conversions * Fix conversion * Fix magics * Update tests * Support GPU in JIT mode * Fix GPU+JIT * Fix kernel filename in JIT mode * Add __static_print__; Add earlyDefines; Various domination bugfixes; SimplifyContext RAII base handling * Fix global static handling * Fix float32 tests * FIx gpu module * Support OpenMP "collapse" option * Add more collapse tests * Capture generics and statics * TraitVar handling * Python exceptions / isinstance [wip; no_ci] * clang-format * Add list comparison operators * Support empty raise in IR * Add dict 'or' operator * Fix repr * Add copy module * Fix spacing * Use sm_30 * Python exceptions * TypeTrait support; Fix defaultDict * Fix earlyDefines * Add defaultdict * clang-format * Fix invalid canonicalizations * Fix empty raise * Fix copyright * Add Python numerics option * Support py-numerics in math module * Update docs * Add static Python division / modulus * Add static py numerics tests * Fix staticrange/tuple; Add KwTuple.__getitem__ * clang-format * Add gpu parameter to par * Fix globals * Don't init loop vars on loop collapse * Add par-gpu tests * Update gpu docs * Fix isinstance check * Remove invalid test * Add -libdevice to set custom path [skip ci] * Add release notes; bump version [skip ci] * Add libdevice docs [skip ci] Co-authored-by: Ibrahim Numanagić <ibrahimpasa@gmail.com>
2022-09-16 03:40:00 +08:00
collapse: Static[int] = 0,
gpu: Static[int] = False,
2021-09-28 02:02:44 +08:00
):
pass