Fix invalid alignment value for _aligned_malloc in Windows (#2671)
Some checks failed
Presubmit / Build ubuntu-22.04 gl (push) Failing after 1s
Presubmit / Build ubuntu-22.04 aarch64 debug (push) Failing after 1s
Presubmit / Build ubuntu-22.04 android-aarch64 (push) Failing after 1s
Presubmit / Check code format (push) Failing after 1s
Presubmit / Build macos-latest (push) Has been cancelled
Presubmit / Build windows-11-arm (push) Has been cancelled
Presubmit / Build windows-latest (push) Has been cancelled

The Device Maximum Alignment is set up to zero when using the USM
wrapper to allocate a System type allocation.
This value is used for the `alignment` param in the `_aligned_malloc`
function if the test is run on Windows. In this case, `alignment` must
be a power of 2
[_aligned_malloc](https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/aligned-malloc?view=msvc-170)
:

> If alignment isn't a power of 2 or size is zero, this function invokes
the invalid parameter handler, as described in [Parameter
validation](https://learn.microsoft.com/en-us/cpp/c-runtime-library/parameter-validation?view=msvc-170).
This commit is contained in:
Jose Lopez 2026-06-16 17:29:03 +01:00 committed by GitHub
parent b9444c733b
commit 2a9317f600
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -94,8 +94,10 @@ public:
else
{
// For now, just unconditionally align to the device maximum
data = static_cast<T*>(
align_malloc(count * sizeof(T), deviceMaxAlignment));
const auto alignment =
deviceMaxAlignment ? deviceMaxAlignment : 1;
data =
static_cast<T*>(align_malloc(count * sizeof(T), alignment));
test_assert_error_ret(data != nullptr,
"Failed to allocate memory",
CL_OUT_OF_RESOURCES);