Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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:

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.).

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).

  1. Is there a good way of getting rid of these warnings?
  2. Do I have to worry about this?
  3. What is the worst that can happen if I ignore this warning?

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);
}