[SYCL] Non-templated aligned_alloc_xxx functions return non-null when the alignment argument is not a power of 2 on GPU
- Dominant language
- LLVM
- Stars
- 1.5k
- Forks
- 854
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 137
Description
**Describe the bug**
When the given alignment argument is not a power of 2, the non-templated aligned_alloc_xxx functions does not return nullptr as expected on GPU. (Expecting them to return nullptr as per the SYCL2020 specification [4.8.3 USM allocations](https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html#_usm_allocations): Some of the allocation functions take an explicit alignment parameter. Like std::aligned_alloc, these functions return nullptr if the alignment is not supported by the implementation.)
Notice that the cause to this problem seems to be `void *alignedAlloc()` in `sycl/source/detail/usm/usm_impl.cpp`, which is called by these non-templated aligned_alloc_xxx functions, is not returning nullptr under such scenario.
Also notice that certain values of the alignment argument (which is not a power of 2) will cause these aligned_alloc_xxx functions to return a non-NULL pointer that may cause errors when trying to free it with free() as shown in the test file below.
These functions seems to be working correctly on CPU though. Also notice that in the original script (https://github.com/intel/llvm/issues/11642, under the source code section), the author commented that this problem may be relevant to GPU runtime).
**To Reproduce**
1. Include code snippet as short as possible:
[align_reproduce.zip](https://github.com/intel/llvm/files/14187249/align_reproduce.zip)
2. Specify the command which should be used to compile the program
Unzip and place the test file above under /sycl/test-e2e/USM/, and then run `clang++ -fsycl -fsycl-targets=spir64 align_reproduce.cpp -o align_reproduce.cpp.tmp.out`
3. Specify the comment which should be used to launch the program
Then run `env ONEAPI_DEVICE_SELECTOR=level_zero:gpu UR_L0_DEBUG=1 ./align_reproduce.cpp.tmp.out` (on a machine with GPU).
4. Indicate what is wrong and what was expected
Test result shows that the non-templated aligned_alloc_xxx test cases are returning non-nullptr when the alignment argument is not a power of 2 on GPU. They are expected to return nullptr as explained above under such scenario.
**Environment:**
- OS: Linux
- Target device and vendor: Intel GPU
- DPC++ version: clang version 19.0.0
- Dependencies version: N/A
Contributor guide
Assessment
This issue has not been assessed yet.