spcl / spcl/dace

Aligned Allocation

Open
#2,437 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
593
Forks
163
Avg merge
2d 23h
Merged PRs (30d)
60

Description

While working on the `nanobind` interface my friend found an error related to `gcc16` that is now a hard error.

The error is related to the following construct:
```cpp
mid_deg = new double DACE_ALIGN(64)[2];
```
(`dace/codegen/targets/cpu.py:492` and `:541`), where `DACE_ALIGN(N)` expands to `__attribute__((aligned(N)))` on GCC/Clang (`dace/runtime/include/dace/types.h`).

A small test program:
```cpp
int main() {
double *p = new double __attribute__((aligned(64)))[2]; // error on GCC 16
delete[] p;
}
```
fails with the error:
```
test.cpp: In function »int main()«:
test.cpp:2:58: error: Ausrichtung der Arrayelemente ist größer als die Elementgröße
2 | double *p = new double __attribute__((aligned(64)))[2]; // error on GCC 16
| ^
```

However, it only affects allocations of known small size.

According to my friend the annotation also does not have an effect.
If the alignment of the allocation should be controlled then [`std::align_val_t` `new` expressions](https://cppreference.com/cpp/memory/new/operator_new) a `C++17` feature must be used.

Contributor guide

Open the contributing guide

Research direction

The affected allocations are emitted from dace/codegen/targets/cpu.py at lines 492 and 541; inspect DACE_ALIGN in dace/runtime/include/dace/types.h first and reproduce the GCC 16 diagnostic with the minimal C++ program in the report. Trace both allocation sites and verify that generated CPU code compiles for the reported case while retaining the intended allocation behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
backend, compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.