FIAS . Impressum . Privacy

test if a type can be vectorized

Kay F. Jahnke [please enable javascript to see the address]
Mon Oct 2 19:17:03 CEST 2017


Am 29.09.2017 um 14:37 schrieb Matthias Kretz:
> Hi Kay,
> 
> AFAIK, there is no way to do it with Vc 1.3. I'm pretty certain because I implemented the ability to query for is_destructible/constructible in current master (to become Vc 2.0).
> There's probably one workaround, and that's too enumerate all types that are valid, returning true. Return false otherwise. That's not really what you've asked for, though.

Hi Matthias!

I've thought about it some more.
Consider this change to .../Vc/avx/types.h and .../vc/sse/types.h,
towards the end, to have (given for .../Vc/avx/types.h):

namespace Traits
{
template<typename T> struct
is_simd_mask_internal<Mask<T, VectorAbi::Avx>>
  : public std::true_type {};

// instead of the blanket statement:

// template<typename T> struct
// is_simd_vector_internal<Vector<T, VectorAbi::Avx>>
//  : public std::true_type {};

// partial specialization only for vectorizable types,
// which is a bit like an 'enumeration'

template<> struct
is_simd_vector_internal<Vector<double, VectorAbi::Avx>>
  : public std::true_type {};

template<> struct
is_simd_vector_internal<Vector<float, VectorAbi::Avx>>
  : public std::true_type {};

template<> struct
is_simd_vector_internal<Vector<int, VectorAbi::Avx>>
  : public std::true_type {};

template<> struct
is_simd_vector_internal<Vector<uint, VectorAbi::Avx>>
  : public std::true_type {};

template<> struct
is_simd_vector_internal<Vector<short, VectorAbi::Avx>>
  : public std::true_type {};

template<> struct
is_simd_vector_internal<Vector<ushort, VectorAbi::Avx>>
: public std::true_type {};

}  // namespace Traits

Then coding is_vectorizable is easy:

////////////////////////////////

#include <Vc/Vc>

template < class T > using is_vectorizable =
typename Vc::is_simd_vector < Vc::Vector < T > > :: type ;

int main ( int argc , char * argv[] )
{
   std::cout << Vc::is_simd_vector<Vc::Vector<float>>::type()
             << std::endl ;
   std::cout << is_vectorizable<float>()
             << std::endl ;
   std::cout << Vc::is_simd_vector<Vc::Vector<long double>>::type()
             << std::endl ;
   std::cout << is_vectorizable<long double>()
             << std::endl ;
}

/////////////////////////////////

Coding the traits like this makes is_simd_vector<U> yield false_type, 
for non-vectorizable U. for acceptable T, is_simd_vector<T> yields 
true_type, as it should.

What do you say?

Kay

> 
>[please enable javascript to see the address]>:
>> Dear group!
>>
>> I'd like to perform a test on some type T which tells me whether Vc can
>>
>> form a Vc::Vector from it. I'd like something like
>>
>> is_simdizable<T>::value
>>
>> to yield true if Vc::Vector<T> can be formed, false otherwise, so that
>> I
>> can use the result to dispatch to fall-back code if there is no
>> Vc:Vector<T>.
>>
>> Help appreciated.
>>
>> With regards
>>
>> Kay F. Jahnke
>>
>>
>> .
>>
>> _______________________________________________
>> Vc mailing list
>>[please enable javascript to see the address]
>> https://compeng.uni-frankfurt.de/mailman/listinfo/vc
> 


.



More information about the Vc mailing list
FIAS . Impressum . Privacy