Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
value = Value(param_node, Expr(param, []), param_type)
if types.allows_var_binding(param_type):
value = StackReference(param_node, Expr(param, []), types.StackReference(param_type))
cx.env.insert(param_node.name, value)
task_body = trans_node(task.block, cx)
task_cleanup = trans_cleanup(0, cx)
task_definition = Expr(
task_name,
['%s %s(%s)' % (
ll_return_type,
task_name,
task_inputs),
'{',
Block(task_header + [task_body] + task_cleanup),
'}'])
return task_definition
def trans_params_serialize(task, params, cx):
struct_name = mangle_task_params_struct(task)
return [
'void %s::legion_serialize(void *buffer) const {' % struct_name,
Block(['char *ptr = reinterpret_cast(buffer);'] +
[line
for param_type, param in params
for line in trans_param_type_serialize(task, 'ptr', param, param_type, cx)]),
'}']
def trans_reduction_op_impl(op, element_type, cx):
ll_name = mangle_reduction_op(op, element_type, cx)
ll_element_type = trans_type(element_type, cx)
assert op in reduction_op_table
identity = reduction_op_table[op]['identity']
apply_op = op
fold_op = reduction_op_table[op]['fold']
reduction_class_impl = [
'const %s::RHS %s::identity = %s;' % (ll_name, ll_name, identity),
'',
'template <> void %s::apply(LHS &lhs, RHS rhs) { lhs %s= rhs; }' % (
ll_name, apply_op),
'template <> void %s::apply(LHS &lhs, RHS rhs) {' % ll_name,
Block(trans_reduction_op_atomic(op, element_type, 'LHS', 'RHS', 'lhs', 'rhs', apply_op, cx)),
'}',
'',
'template <> void %s::fold(RHS &rhs1, RHS rhs2) { rhs1 %s= rhs2; }' % (
ll_name, fold_op),
'template <> void %s::fold(RHS &rhs1, RHS rhs2) {' % ll_name,
Block(trans_reduction_op_atomic(op, element_type, 'RHS', 'RHS', 'rhs1', 'rhs2', fold_op, cx)),
'}']
return ReductionOp(
node = None,
expr = Expr(ll_name, reduction_class_impl),
type = None,
op = op,
element_type = element_type)
@trans_node.register(ast.Block)
def _(node, cx):
cx = cx.new_block_scope()
block = [trans_node(statement, cx) for statement in node.block]
cleanup = trans_cleanup(-1, cx)
return Statement(['{', Block(block + cleanup), '}'])
if cx.opts.gcc_atomics:
if types.is_floating_point(element_type):
if types.is_float(element_type):
ll_int_type = 'uint32_t'
elif types.is_double(element_type):
ll_int_type = 'uint64_t'
else:
assert False
actions = [
'%s *target = reinterpret_cast<%s *>(&%s);' % (
ll_int_type, ll_int_type, ll_lhs),
'union { %s as_int; %s as_float; } oldval, newval;' % (
ll_int_type, ll_lhs_type),
'do {',
Block(['oldval.as_int = *target;',
'newval.as_float = oldval.as_float %s %s;' % (
ll_op, ll_rhs)]),
'} while (!__sync_bool_compare_and_swap(target, oldval.as_int, newval.as_int));']
else:
actions = [
'%s *target = &%s;' % (
ll_lhs_type, ll_lhs),
'do {',
Block(['val = *target;']),
'} while (!__sync_bool_compare_and_swap(target, val, val %s %s));' % (
ll_op, ll_rhs)]
return actions
# C++11 atomics:
if types.is_floating_point(element_type):
if types.is_float(element_type):
def trans_reduction_op_class(redop, cx):
ll_name = redop.read(cx).value
ll_element_type = trans_type(redop.element_type, cx)
reduction_class = [
'class %s {' % ll_name,
'public:',
Block(['typedef %s LHS;' % ll_element_type,
'typedef %s RHS;' % ll_element_type,
'static const RHS identity;',
'template static void apply(LHS &lhs, RHS rhs);',
'template static void fold(RHS &rhs1, RHS rhs2);']),
'};']
return reduction_class
def trans_params_prototype(task, params, cx):
struct_name = mangle_task_params_struct(task)
struct_def = (
['struct %s' % struct_name,
'{',
Block(['%s %s;' % (
trans_type(param_type, cx),
param)
for param_type, param in params] +
['size_t legion_buffer_size() const;',
'void legion_serialize(void *buffer) const;',
'size_t legion_deserialize(const void *buffer);']),
'};'])
return Expr(struct_name, struct_def)