Skip to content

Commit 06d1be2

Browse files
gandalf2390facebook-github-bot
authored andcommittedNov 3, 2021
[NOOP][clangformat][codemod] Enable CLANGFORMAT for caffe2/caffe2/* (pytorch#67624)
Summary: Pull Request resolved: pytorch#67624 Test Plan: Visual inspection. Sandcastle. Reviewed By: malfet Differential Revision: D31986628 fbshipit-source-id: c872bded7325997a2945dbf5d4d052628dcb3659

File tree

83 files changed

+1231
-947
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+1231
-947
lines changed
 

‎caffe2/cuda_rtc/common_rtc.h

+36-25
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
#include <cuda.h>
88
#include <nvrtc.h>
99

10-
#define NVRTC_CHECK(condition) \
11-
do { \
12-
nvrtcResult result = condition; \
13-
if (result != NVRTC_SUCCESS) { \
14-
LOG(FATAL) << "Error at: " << __FILE__ << ":" << __LINE__ << ": " \
15-
<< nvrtcGetErrorString(result); \
16-
} \
17-
} while(0)
10+
#define NVRTC_CHECK(condition) \
11+
do { \
12+
nvrtcResult result = condition; \
13+
if (result != NVRTC_SUCCESS) { \
14+
LOG(FATAL) << "Error at: " << __FILE__ << ":" << __LINE__ << ": " \
15+
<< nvrtcGetErrorString(result); \
16+
} \
17+
} while (0)
1818

1919
namespace caffe2 {
2020

@@ -39,15 +39,14 @@ class CudaRTCFunction {
3939
VLOG(1) << "function src:\n" << src;
4040
// Actually do the compiling.
4141
nvrtcProgram prog;
42-
NVRTC_CHECK(nvrtcCreateProgram(
43-
&prog, src.c_str(), nullptr, 0, nullptr, nullptr));
42+
NVRTC_CHECK(
43+
nvrtcCreateProgram(&prog, src.c_str(), nullptr, 0, nullptr, nullptr));
4444
// Compile the program.
4545
// TODO(Yangqing): how to find the current gpu architecture instead of hard
4646
// coding it?
47-
const char *nvrtc_opts[] = {"--gpu-architecture=compute_35",
48-
"--use_fast_math"};
49-
nvrtcResult compile_result = nvrtcCompileProgram(
50-
prog, 2, nvrtc_opts);
47+
const char* nvrtc_opts[] = {
48+
"--gpu-architecture=compute_35", "--use_fast_math"};
49+
nvrtcResult compile_result = nvrtcCompileProgram(prog, 2, nvrtc_opts);
5150
if (compile_result != NVRTC_SUCCESS) {
5251
size_t log_size;
5352
NVRTC_CHECK(nvrtcGetProgramLogSize(prog, &log_size));
@@ -74,21 +73,33 @@ class CudaRTCFunction {
7473
}
7574

7675
template <typename... Args>
77-
void Launch(unsigned int gx, unsigned int gy, unsigned int gz,
78-
unsigned int bx, unsigned int by, unsigned int bz,
79-
unsigned int shared_mem, cudaStream_t stream,
80-
Args... args) {
76+
void Launch(
77+
unsigned int gx,
78+
unsigned int gy,
79+
unsigned int gz,
80+
unsigned int bx,
81+
unsigned int by,
82+
unsigned int bz,
83+
unsigned int shared_mem,
84+
cudaStream_t stream,
85+
Args... args) {
8186
CAFFE_ENFORCE(
8287
module_loaded_, "Cannot call Launch before a module is loaded.");
83-
void * args_voidp[] = {&args...};
88+
void* args_voidp[] = {&args...};
8489
CUDA_DRIVERAPI_ENFORCE(cuLaunchKernel(
8590
kernel_, gx, gy, gz, bx, by, bz, shared_mem, stream, args_voidp, 0));
8691
}
8792

88-
void LaunchEx(unsigned int gx, unsigned int gy, unsigned int gz,
89-
unsigned int bx, unsigned int by, unsigned int bz,
90-
unsigned int shared_mem, cudaStream_t stream,
91-
void** extra) {
93+
void LaunchEx(
94+
unsigned int gx,
95+
unsigned int gy,
96+
unsigned int gz,
97+
unsigned int bx,
98+
unsigned int by,
99+
unsigned int bz,
100+
unsigned int shared_mem,
101+
cudaStream_t stream,
102+
void** extra) {
92103
CAFFE_ENFORCE(
93104
module_loaded_, "Cannot call Launch before a module is loaded.");
94105
CUDA_DRIVERAPI_ENFORCE(cuLaunchKernel(
@@ -115,6 +126,6 @@ inline std::string GetUniqueName() {
115126
return ss.str();
116127
}
117128

118-
} // namepsace caffe2
129+
} // namespace caffe2
119130

120-
#endif // CAFFE2_CUDA_RTC_COMMON_RTC_H_
131+
#endif // CAFFE2_CUDA_RTC_COMMON_RTC_H_

‎caffe2/cuda_rtc/elemenntwise_rtc_gpu.cc

+20-21
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55

66
namespace caffe2 {
77
namespace {
8-
class ElementwiseRTCFunction
9-
: public CudaRTCFunction<ElementwiseRTCFunction> {
8+
class ElementwiseRTCFunction : public CudaRTCFunction<ElementwiseRTCFunction> {
109
public:
1110
ElementwiseRTCFunction() : CudaRTCFunction(), name_(GetUniqueName()) {}
1211

@@ -22,22 +21,21 @@ class ElementwiseRTCFunction
2221
string name_;
2322
};
2423

25-
template<>
24+
template <>
2625
string ElementwiseRTCFunction::GetSource(
27-
int input_size, int output_size,
26+
int input_size,
27+
int output_size,
2828
const string command_string) {
2929
std::stringstream ss;
30-
ss << "extern \"C\" __global__ void " << name_ <<
31-
"(const size_t nthreads, \n";
30+
ss << "extern \"C\" __global__ void " << name_
31+
<< "(const size_t nthreads, \n";
3232
// Insert the parameter list.
3333
int remain_params = input_size + output_size;
3434
for (int i = 0; i < input_size; ++i) {
35-
ss << "const float* in" << i
36-
<< ((remain_params--) ? ", \n" : "");
35+
ss << "const float* in" << i << ((remain_params--) ? ", \n" : "");
3736
}
3837
for (int i = 0; i < output_size; ++i) {
39-
ss << "float* out" << i
40-
<< ((remain_params--) ? ", \n" : "");
38+
ss << "float* out" << i << ((remain_params--) ? ", \n" : "");
4139
}
4240
ss << ") {\n"
4341
"for (int index = blockIdx.x * blockDim.x + threadIdx.x;\n"
@@ -46,7 +44,7 @@ string ElementwiseRTCFunction::GetSource(
4644
<< "}\n}";
4745
return ss.str();
4846
}
49-
} // namespace
47+
} // namespace
5048

5149
/**
5250
* A GPU operator that can generate limited elementwise operations.
@@ -75,17 +73,17 @@ class ElementwiseRTCOp final : public Operator<CUDAContext> {
7573
public:
7674
ElementwiseRTCOp(const OperatorDef& operator_def, Workspace* ws)
7775
: Operator<CUDAContext>(operator_def, ws) {
78-
const string src = OperatorBase::GetSingleArgument<string>(
79-
"rtc_src", "");
76+
const string src = OperatorBase::GetSingleArgument<string>("rtc_src", "");
8077
CAFFE_ENFORCE(src.size(), "Op should have a non-zero source code size.");
8178
func_.Compile(InputSize(), OutputSize(), src);
8279
}
8380
~ElementwiseRTCOp() override {}
8481

8582
bool RunOnDevice() override {
86-
static_assert(sizeof(void*) == sizeof(size_t),
87-
"The argbuffer relies on the assumption that void* and "
88-
"size_t have the same size.");
83+
static_assert(
84+
sizeof(void*) == sizeof(size_t),
85+
"The argbuffer relies on the assumption that void* and "
86+
"size_t have the same size.");
8987
vector<size_t> argBuffer_vec(InputSize() + OutputSize() + 1);
9088
size_t* argBuffer = argBuffer_vec.data();
9189
CAFFE_ENFORCE(
@@ -102,10 +100,11 @@ class ElementwiseRTCOp final : public Operator<CUDAContext> {
102100
}
103101
size_t argBufferSize = sizeof(argBuffer);
104102
void* config[] = {
105-
CU_LAUNCH_PARAM_BUFFER_POINTER, argBuffer,
106-
CU_LAUNCH_PARAM_BUFFER_SIZE, &argBufferSize,
107-
CU_LAUNCH_PARAM_END
108-
};
103+
CU_LAUNCH_PARAM_BUFFER_POINTER,
104+
argBuffer,
105+
CU_LAUNCH_PARAM_BUFFER_SIZE,
106+
&argBufferSize,
107+
CU_LAUNCH_PARAM_END};
109108
func_.LaunchEx(
110109
CAFFE_GET_BLOCKS(Input(0).numel()),
111110
1,
@@ -127,4 +126,4 @@ namespace {
127126
REGISTER_CUDA_OPERATOR_WITH_ENGINE(ElementwiseRTC, NVRTC, ElementwiseRTCOp);
128127
}
129128

130-
} // namespace caffe2
129+
} // namespace caffe2

0 commit comments

Comments
 (0)
Please sign in to comment.