High-Performance Tensor Transposition (HPTT) C++ Library
A C++ library for high-performance multi-threaded tensor transpositions.
utils.h
1
5#pragma once
6
7#include <list>
8#include <vector>
9#include <iostream>
10
11#include "hptt_types.h"
12
13namespace hptt {
14
15template<typename floatType>
16static floatType conj(floatType x){
17 return std::conj(x);
18}
19template<>
20float conj(float x){
21 return x;
22}
23template<>
24double conj(double x){
25 return x;
26}
27
28template<typename floatType>
29static double getZeroThreshold();
30template<>
31double getZeroThreshold<double>() { return 1e-16;}
32template<>
33double getZeroThreshold<DoubleComplex>() { return 1e-16;}
34template<>
35double getZeroThreshold<float>() { return 1e-6;}
36template<>
37double getZeroThreshold<FloatComplex>() { return 1e-6;}
38
39void trashCache(double *A, double *B, int n);
40
41template<typename t>
42int hasItem(const std::vector<t> &vec, t value)
43{
44 return ( std::find(vec.begin(), vec.end(), value) != vec.end() );
45}
46
47template<typename t>
48void printVector(const std::vector<t> &vec, const char* label){
49 std::cout << label <<": ";
50 for( auto a : vec )
51 std::cout << a << ", ";
52 std::cout << "\n";
53}
54
55template<typename t>
56void printVector(const std::list<t> &vec, const char* label){
57 std::cout << label <<": ";
58 for( auto a : vec )
59 std::cout << a << ", ";
60 std::cout << "\n";
61}
62
63
64void getPrimeFactors( int n, std::list<int> &primeFactors );
65
66template<typename t>
67int findPos(t value, const std::vector<t> &array)
68{
69 for(int i=0;i < array.size() ; ++i)
70 if( array[i] == value )
71 return i;
72 return -1;
73}
74
75int findPos(int value, const int *array, int n);
76
77int factorial(int n);
78
79void accountForRowMajor(const int *sizeA, const int *outerSizeA, const int *outerSizeB, const int *perm,
80 int *tmpSizeA, int *tmpOuterSizeA, int *tmpouterSizeB, int *tmpPerm, const int dim, const bool useRowMajor);
81}
82
83
Definition: compute_node.h:3