-
Notifications
You must be signed in to change notification settings - Fork 11
/
utils.hpp
79 lines (68 loc) · 1.49 KB
/
utils.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#pragma once
#include <complex>
#include <type_traits>
#include <cuda_runtime.h>
#include <cutlass/util/util.h>
namespace gemm {
namespace detail {
template <typename ValueT, typename AccumT>
static const char* implementation_name();
template <>
const char* implementation_name<half, float>() {
return "WGEMM";
}
template <>
const char* implementation_name<__half, __half>() {
return "HGEMM";
}
template <>
const char* implementation_name<float, float>() {
return "SGEMM";
}
template <>
const char* implementation_name<double, double>() {
return "DGEMM";
}
template <>
const char* implementation_name<std::complex<float>, std::complex<float>>() {
return "CGEMM";
}
template <>
const char* implementation_name<std::complex<double>, std::complex<double>>() {
return "ZGEMM";
}
template <typename T>
static T one() {
return T{1};
};
template <>
__half one<__half>() {
unsigned short x{1};
__half res;
memcpy(&res, &x, sizeof(res));
return res;
};
template <typename T>
static T zero() {
return T{0};
};
template <>
__half zero<__half>() {
__half res;
memset(&res, 0, sizeof(res));
return res;
};
template <typename T>
struct cuda_type {
using type = T;
};
template <>
struct cuda_type<std::complex<float>> {
using type = cuComplex;
};
template <>
struct cuda_type<std::complex<double>> {
using type = cuDoubleComplex;
};
} // namespace detail
} // namespace gemm