CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
55 lines
1.8 KiB
ReStructuredText
55 lines
1.8 KiB
ReStructuredText
.. title:: clang-tidy - altera-struct-pack-align
|
|
|
|
altera-struct-pack-align
|
|
========================
|
|
|
|
Finds structs that are inefficiently packed or aligned, and recommends
|
|
packing and/or aligning of said structs as needed.
|
|
|
|
Structs that are not packed take up more space than they should, and accessing
|
|
structs that are not well aligned is inefficient.
|
|
|
|
Fix-its are provided to fix both of these issues by inserting and/or amending
|
|
relevant struct attributes.
|
|
|
|
Based on the `Altera SDK for OpenCL: Best Practices Guide
|
|
<https://www.altera.com/en_US/pdfs/literature/hb/opencl-sdk/aocl_optimization_guide.pdf>`_.
|
|
|
|
.. code-block:: c++
|
|
|
|
// The following struct is originally aligned to 4 bytes, and thus takes up
|
|
// 12 bytes of memory instead of 10. Packing the struct will make it use
|
|
// only 10 bytes of memory, and aligning it to 16 bytes will make it
|
|
// efficient to access.
|
|
struct example {
|
|
char a; // 1 byte
|
|
double b; // 8 bytes
|
|
char c; // 1 byte
|
|
};
|
|
|
|
// The following struct is arranged in such a way that packing is not needed.
|
|
// However, it is aligned to 4 bytes instead of 8, and thus needs to be
|
|
// explicitly aligned.
|
|
struct implicitly_packed_example {
|
|
char a; // 1 byte
|
|
char b; // 1 byte
|
|
char c; // 1 byte
|
|
char d; // 1 byte
|
|
int e; // 4 bytes
|
|
};
|
|
|
|
// The following struct is explicitly aligned and packed.
|
|
struct good_example {
|
|
char a; // 1 byte
|
|
double b; // 8 bytes
|
|
char c; // 1 byte
|
|
} __attribute__((packed)) __attribute__((aligned(16));
|
|
|
|
// Explicitly aligning a struct to the wrong value will result in a warning.
|
|
// The following example should be aligned to 16 bytes, not 32.
|
|
struct badly_aligned_example {
|
|
char a; // 1 byte
|
|
double b; // 8 bytes
|
|
char c; // 1 byte
|
|
} __attribute__((packed)) __attribute__((aligned(32)));
|