Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instead of compiler specific align hint use C++ standard aligned alloc #1744

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions dace/codegen/targets/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ def allocate_array(self, sdfg: SDFG, cfg: ControlFlowRegion, dfg: StateSubgraphV
if not declared:
declaration_stream.write(f'{nodedesc.dtype.ctype} *{name};\n', cfg, state_id, node)
allocation_stream.write(
"%s = new %s DACE_ALIGN(64)[%s];\n" % (alloc_name, nodedesc.dtype.ctype, cpp.sym2cpp(arrsize)), cfg,
"%s = static_cast<%s*>(std::aligned_alloc(64, %s * sizeof(%s)));\n" % (nodedesc.dtype.ctype, alloc_name, cpp.sym2cpp(arrsize), nodedesc.dtype.ctype), cfg,
state_id, node)
define_var(name, DefinedType.Pointer, ctypedef)

Expand All @@ -512,15 +512,15 @@ def allocate_array(self, sdfg: SDFG, cfg: ControlFlowRegion, dfg: StateSubgraphV
raise NotImplementedError('Start offset unsupported for registers')
if node.setzero:
declaration_stream.write(
"%s %s[%s] DACE_ALIGN(64) = {0};\n" % (nodedesc.dtype.ctype, name, cpp.sym2cpp(arrsize)),
"%s alignas(64) %s[%s]{0};\n" % (nodedesc.dtype.ctype, name, cpp.sym2cpp(arrsize)),
cfg,
state_id,
node,
)
define_var(name, DefinedType.Pointer, ctypedef)
return
declaration_stream.write(
"%s %s[%s] DACE_ALIGN(64);\n" % (nodedesc.dtype.ctype, name, cpp.sym2cpp(arrsize)),
"%s alignas(64) %s[%s];\n" % (nodedesc.dtype.ctype, name, cpp.sym2cpp(arrsize)),
cfg,
state_id,
node,
Expand All @@ -544,7 +544,7 @@ def allocate_array(self, sdfg: SDFG, cfg: ControlFlowRegion, dfg: StateSubgraphV
"""
#pragma omp parallel
{{
{name} = new {ctype} DACE_ALIGN(64)[{arrsize}];""".format(ctype=nodedesc.dtype.ctype,
{name} = static_cast<{ctype}*>(std::aligned_alloc(64, {arrsize} * sizeof({ctype})));""".format(ctype=nodedesc.dtype.ctype,
name=alloc_name,
arrsize=cpp.sym2cpp(arrsize)),
cfg,
Expand Down Expand Up @@ -581,13 +581,13 @@ def deallocate_array(self, sdfg: SDFG, cfg: ControlFlowRegion, dfg: StateSubgrap
return
elif (nodedesc.storage == dtypes.StorageType.CPU_Heap
or (nodedesc.storage == dtypes.StorageType.Register and symbolic.issymbolic(arrsize, sdfg.constants))):
callsite_stream.write("delete[] %s;\n" % alloc_name, cfg, state_id, node)
callsite_stream.write("std::free(%s);\n" % alloc_name, cfg, state_id, node)
elif nodedesc.storage is dtypes.StorageType.CPU_ThreadLocal:
# Deallocate in each OpenMP thread
callsite_stream.write(
"""#pragma omp parallel
{{
delete[] {name};
std::free({name});
}}""".format(name=alloc_name),
cfg,
state_id,
Expand Down
1 change: 1 addition & 0 deletions dace/runtime/include/dace/dace.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <numeric>
#include <tuple>
#include <cstring>
#include <cstdlib>

// The order in which these are included matters - sorting them
// alphabetically causes compilation to fail.
Expand Down
Loading