Skip to content

Commit a9578ae

Browse files
committed
formatting
1 parent d9f3059 commit a9578ae

32 files changed

+486
-515
lines changed

.clang-format

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
Language: Cpp
3+
BasedOnStyle: LLVM
4+
...
5+

include/scope/barrier.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22

3-
#include <memory>
43
#include <condition_variable>
4+
#include <memory>
55

66
// https://stackoverflow.com/questions/24465533/implementing-boostbarrier-in-c11
77
class Barrier {

include/scope/chrono.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <chrono>
22

33
namespace scope {
4-
using clock = std::chrono::high_resolution_clock;
5-
using duration = std::chrono::duration<double>;
6-
using time_point = std::chrono::time_point<clock>;
7-
}
4+
using clock = std::chrono::high_resolution_clock;
5+
using duration = std::chrono::duration<double>;
6+
using time_point = std::chrono::time_point<clock>;
7+
} // namespace scope

include/scope/clobber.hpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22

33
namespace scope {
44

5-
__host__
6-
inline __attribute__((always_inline)) void clobber_memory() {
5+
__host__ inline __attribute__((always_inline)) void clobber_memory() {
76
std::atomic_signal_fence(std::memory_order_acq_rel);
87
}
98

10-
__device__
11-
inline __attribute__((always_inline)) void clobber_memory() {
9+
__device__ inline __attribute__((always_inline)) void clobber_memory() {
1210
asm volatile("" : : : "memory");
1311
}
1412

15-
}
13+
} // namespace scope

include/scope/cuda.hpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,20 @@
88

99
cudaError_t cuda_reset_device(const int &id);
1010

11-
1211
namespace scope {
1312
namespace detail {
1413
inline void success_or_throw(cudaError err, const char *file, int line) {
15-
if (cudaSuccess != err) {
16-
std::stringstream ss;
17-
ss << __FILE__ << ":" << __LINE__ << "CUDA error " << cudaGetErrorString(err);
18-
throw std::runtime_error(ss.str());
19-
}
14+
if (cudaSuccess != err) {
15+
std::stringstream ss;
16+
ss << __FILE__ << ":" << __LINE__ << "CUDA error "
17+
<< cudaGetErrorString(err);
18+
throw std::runtime_error(ss.str());
19+
}
2020
}
2121
} // namespace detail
2222

2323
cudaError hip_reset_device(const int &id);
2424

2525
} // namespace scope
2626

27-
2827
#define CUDA_RUNTIME(x) scope::detail::success_or_throw(x, __FILE__, __LINE__)

include/scope/defer.hpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,21 @@
55
#include <type_traits>
66
#include <utility>
77

8-
template <class Function>
9-
class defer_func {
8+
template <class Function> class defer_func {
109
public:
1110
template <class F>
12-
explicit defer_func(F &&f) noexcept : defer_function_(std::forward<F>(f)) {
13-
}
11+
explicit defer_func(F &&f) noexcept : defer_function_(std::forward<F>(f)) {}
1412

15-
~defer_func() {
16-
defer_function_();
17-
}
13+
~defer_func() { defer_function_(); }
1814

1915
private:
2016
Function defer_function_;
2117
};
2218

2319
template <class F>
2420
defer_func<typename std::decay<F>::type> make_defer(F &&defer_function) {
25-
return defer_func<typename std::decay<F>::type>(std::forward<F>(defer_function));
21+
return defer_func<typename std::decay<F>::type>(
22+
std::forward<F>(defer_function));
2623
}
2724

2825
#define DEFER_1(x, y) x##y

include/scope/device.hpp

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,47 +10,40 @@
1010

1111
class Device {
1212
public:
13+
enum class Kind { cuda, hip };
1314

14-
enum class Kind {
15-
cuda,
16-
hip
17-
};
15+
Device(const Kind &kind, int id) : kind_(kind), id_(id) {}
1816

19-
Device(const Kind &kind, int id) : kind_(kind), id_(id) {}
17+
int device_id() const;
2018

21-
int device_id() const;
19+
operator int() const { return id_; }
2220

23-
operator int() const {
24-
return id_;
25-
}
21+
/*
22+
HIP: returns hipDeviceProp_t::canMapHostMemory
23+
*/
24+
bool can_map_host_memory() const;
2625

27-
/*
28-
HIP: returns hipDeviceProp_t::canMapHostMemory
29-
*/
30-
bool can_map_host_memory() const;
31-
32-
#if defined(SCOPE_USE_HIP)
33-
static Device hip_device(int id);
34-
#endif
26+
#if defined(SCOPE_USE_HIP)
27+
static Device hip_device(int id);
28+
#endif
3529

36-
#if defined(SCOPE_USE_CUDA)
37-
static Device cuda_device(int id);
38-
#endif
30+
#if defined(SCOPE_USE_CUDA)
31+
static Device cuda_device(int id);
32+
#endif
3933

4034
private:
41-
Kind kind_;
42-
int id_;
35+
Kind kind_;
36+
int id_;
4337

4438
#if defined(SCOPE_USE_HIP)
45-
hipDeviceProp_t hipDeviceProp_;
39+
hipDeviceProp_t hipDeviceProp_;
4640
#endif
4741

4842
#if defined(SCOPE_USE_CUDA)
4943
#if defined(SCOPE_HAVE_CUDA_DEVICE_PROP)
50-
cudaDeviceProp cudaDeviceProp_;
44+
cudaDeviceProp cudaDeviceProp_;
5145
#else
52-
cudaDeviceProp_t cudaDeviceProp_;
46+
cudaDeviceProp_t cudaDeviceProp_;
5347
#endif
5448
#endif
5549
};
56-

include/scope/do_not_optimize.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,18 @@
22

33
namespace scope {
44
template <class Tp>
5-
__device__
6-
void __attribute__((always_inline)) do_not_optimize(Tp const& value) {
5+
__device__ void __attribute__((always_inline))
6+
do_not_optimize(Tp const &value) {
77
asm volatile("" : : "r,m"(value) : "memory");
88
}
99

1010
// https://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html#Machine-Constraints
1111
template <class Tp>
12-
__device__
13-
void __attribute__((always_inline)) do_not_optimize(Tp& value) {
12+
__device__ void __attribute__((always_inline)) do_not_optimize(Tp &value) {
1413
#if defined(__HIP_DEVICE_COMPILE__)
1514
asm volatile("" : "+v"(value) : : "memory");
1615
#else
1716
asm volatile("" : "+r,m"(value) : : "memory");
1817
#endif
1918
}
20-
}
19+
} // namespace scope

0 commit comments

Comments
 (0)