Implication of GCC warning: ignoring attributes on template argument (-Wignored-attributes)

Implication of GCC warning: ignoring attributes on template argument (-Wignored-attributes)



I'm using __m256 as an argument for a template class (see code below). When compiling with g++ version 6.2 on Ubuntu 16.10 (Yakkety Yak), it warns me about attributes being ignored on the template argument:


__m256



warning: ignoring attributes on template argument ‘__m256 aka __vector(8) float’ [-Wignored-attributes] typedef vec_array<__m256> vec256



The __m256 type seems to have some attributes concerning alignment (and maybe some others?). The sole purpose of this primitive container class shown below (and which generates the warning) is to handle memory alignment on the heap for these special Intel variables (__m256, __m128, etc.).


__m256


__m256


__m128



When I use this container class in my overall program, it seems to be working fine. However, my question is what the implications are when GCC is ignoring these attributes (I have already read what the GCC manual has to say on the issue).



For reference, the code below produces this warning.


///////////////////////////////////////////////////////////////////////////////
// System includes:

#include <x86intrin.h>
#include <cstdint>

static const size_t AVX_alignment = 32;

template<typename VecT>
class vec_array

protected:
VecT* m_pdata;
size_t m_num_vector_elements;

public:
vec_array();
vec_array(size_t num_vector_elements);

virtual ~vec_array();

void allocate(size_t num_vector_elements);
void free();

;

template<typename VecT>
vec_array<VecT>::vec_array() : m_pdata(nullptr), m_num_vector_elements(0)


template<typename VecT>
vec_array<VecT>::vec_array(size_t num_vector_elements) : m_pdata(nullptr),
m_num_vector_elements(num_vector_elements)

allocate(num_vector_elements);


template<typename VecT>
vec_array<VecT>::~vec_array()

free();


template<typename VecT>
void vec_array<VecT>::allocate(size_t num_vector_elements)

if( m_num_vector_elements == num_vector_elements)
return;

m_num_vector_elements = num_vector_elements;

free();

m_pdata = reinterpret_cast<VecT*>(_mm_malloc(m_num_vector_elements*sizeof(VecT), AVX_alignment));


template<typename VecT>
void vec_array<VecT>::free()

if(m_pdata != nullptr)
_mm_free(m_pdata);



typedef vec_array<__m256> vec256;

int main()

vec256 test_vec(10);




1 Answer
1



I came across the same warning but in some OpenCL code and ended up here, without looking at the code first. You can see how some people try to avoid this warning in Making std::vector allocate aligned memory, but in my opinion it just isn't worth it.



The short answer is that you don't have to worry about this, apart from CPUs that only support 128 bit AVX instructions. If the warning were serious, then the CPU would generate an exception on unaligned access.



The this warning appears is because the type __m256 is probably declared with an alignment specifier of probably 16 bytes. That is to say that the CPU would expect the alignment of each of the elements of the vector to be 16 bytes. However, the template for vector doesn't honor the alignment attribute.


__m256



I think that you would have to do something stupid, like a


struct stupidStruct __attribute__(packed)
unsigned short padding;
std::vector<__m256> vect;
;



to force the compiler to produce code that would cause an error.





So if something bad were to happen it would be a bus error.
– T Wrist
Mar 12 at 23:08






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế