Make CUTLASS compileable with Clang.

Requires a recent clang build (r359248 or newer).

Enable compilation with clang with these options:
cmake -DCUDA_COMPILER=clang -DCMAKE_CXX_COMPILER=/path/to/clang++
This commit is contained in:
Artem Belevich
2019-05-02 11:00:22 -07:00
parent fe3438a3c1
commit e18292db46
17 changed files with 102 additions and 38 deletions
@@ -142,12 +142,17 @@ int Layout::operator()(Layout::Coordinate const &_coord) const {
}
// test::Layout::Coordinate is actually a std::vector<>, so for ADL lookup to
// work, the operator<< must be in std::. GCC does look it up in global
// namespace, but that's a bug.
namespace std {
std::ostream & operator<<(std::ostream &out, test::Layout::Coordinate const &coord) {
for (int i = 0; i < coord.size(); ++i) {
out << (i ? ", " : "") << coord.at(i);
}
return out;
}
} // namespace std
///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -94,7 +94,9 @@ class Layout {
}
/// Implemented in layout_verification.cu
namespace std {
std::ostream& operator<<(std::ostream& out, test::Layout::Coordinate const& coord);
}
namespace test {
+1 -3
View File
@@ -42,9 +42,7 @@ __global__ void load_store_global(
typename cutlass::TileStoreIterator<Traits, Scalar, cutlass::IteratorAdvance::kH,
cutlass::MemorySpace::kGlobal>::Scalar *output,
int kW,
int kH,
typename cutlass::TileStoreIterator<Traits, Scalar, cutlass::IteratorAdvance::kH,
cutlass::MemorySpace::kGlobal>::Scalar identity = 0
int kH
) {
/// Load iterator
+16 -4
View File
@@ -86,7 +86,7 @@ class half_t {
half_t operator+(half_t const&) const;
half_t operator-() const;
half_t operator-(half_t const&) const;
half_t operator*(half_t const&)const;
half_t operator*(half_t const&) const;
half_t operator/(half_t const&) const;
half_t& operator+=(half_t const&);
@@ -107,6 +107,12 @@ class half_t {
uint16_t& raw() { return x; }
uint16_t raw() const { return x; }
#if defined(__clang__)
__device__ half_t operator+(half_t const&) const;
__device__ half_t operator*(half_t const&) const;
__device__ operator float() const; /// conversion to fp32
#endif
//
// Stream interactions
//
@@ -209,7 +215,7 @@ std::string lexical_cast<std::string>(cutlass::half_t const& arg);
#define HLF_MANT_DIG 10
namespace std {
namespace cutlass {
cutlass::half_t abs(cutlass::half_t const&); /// absolute value
@@ -229,7 +235,10 @@ int fpclassify(cutlass::half_t const&); /// returns a flag classifying floating
bool signbit(cutlass::half_t const&); /// returns true if negative, false if positive
cutlass::half_t sqrt(cutlass::half_t const&); /// square root of half_t
cutlass::half_t copysign(cutlass::half_t const&, cutlass::half_t const&);
}
namespace std {
/// Numeric limits
template <>
struct numeric_limits<cutlass::half_t> {
@@ -696,8 +705,7 @@ std::string lexical_cast<std::string>(cutlass::half_t const& arg) {
// Standard Library Operations
//
// std
namespace std {
namespace cutlass {
inline cutlass::half_t abs(cutlass::half_t const& h) {
return cutlass::half_t::bitcast(h.x & 0x7fff);
@@ -737,4 +745,8 @@ inline bool signbit(cutlass::half_t const& h) { return h.signbit(); }
inline cutlass::half_t sqrt(cutlass::half_t const& h) {
return cutlass::half_t(std::sqrt(float(h)));
}
inline cutlass::half_t copysign(cutlass::half_t const& a,
cutlass::half_t const& b) {
return cutlass::half_t(std::copysign(float(a), float(b)));
}
} // namespace std
+6 -1
View File
@@ -45,6 +45,12 @@ Ctype inner_product(Atype a, Btype b, Ctype c) {
return Ctype(a) * Ctype(b) + c;
}
#if defined(__clang__) && defined(__CUDA__)
__device__ __forceinline__ __half inner_product(__half a, __half b, __half c) {
return a * b + c;
}
#endif
/// Specialization for matrix multiplication with binary operands
template <>
CUTLASS_HOST_DEVICE
@@ -124,4 +130,3 @@ struct Cast<float, uint8_t> {
} // namespace detail
} // namespace reference
} // namespace cutlass
+1 -1
View File
@@ -142,7 +142,7 @@ struct Gemm {
}
/// Performs linear scaling of matrix product and updates output tensor
CUTLASS_HOST_DEVICE
__device__
Gemm & epilogue(
gemm::GemmCoord problem_size,
ScalarType alpha,
+1 -1
View File
@@ -140,7 +140,7 @@ struct TypeTraits<half> {
typedef int16_t integer_type;
typedef uint16_t unsigned_type;
static inline half remove_negative_zero(half x) {
integer_type h_int = reinterpret_cast<integer_type const&>(x);
unsigned_type h_int = reinterpret_cast<unsigned_type const&>(x);
if (h_int == 0x8000) {
h_int = 0;
}