Make vector allocation aligned to 64-bytes (#1909)

* Make vector allocation aligned to 64-bytes as that is the same alignement requirement used by State data.

* Add release note.

---------

Co-authored-by: Jun Doi <doichan@jp.ibm.com>
This commit is contained in:
Samuel F Antao 2023-08-31 03:17:29 +01:00 committed by GitHub
parent ada56a3b6c
commit 0cca1e3220
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -0,0 +1,10 @@
---
fixes:
- |
Change ``AER::Vector`` object alignement to 64-byte. In some cases, it is used to
initialize ``AER:QV::QubitVector`` objects by moving storage ownership to these
objects. As the code assumes that ``AER:QV::QubitVector`` storage is at least
32-byte aligned for AVX2 load instructions, this change enforces the same alignement
requirements for both ``AER::Vector`` and ``AER:QV::QubitVector`` objects so that
one doesn't get into segmentation faults.

View File

@ -31,7 +31,15 @@ namespace AER {
template <class T>
T *malloc_data(size_t size) {
#if !defined(_WIN64) && !defined(_WIN32)
// Data allocated here may need to be properly aligned to be compliant with
// AVX2.
void *data = nullptr;
posix_memalign(&data, 64, sizeof(T) * size);
return reinterpret_cast<T *>(data);
#else
return reinterpret_cast<T *>(malloc(sizeof(T) * size));
#endif
}
template <class T>