Skip to content
This repository was archived by the owner on Jul 1, 2025. It is now read-only.

Commit afcdbe8

Browse files
committed
Clang-tidy the code and cleanup a few places.
1 parent eacfce7 commit afcdbe8

File tree

4 files changed

+22
-19
lines changed

4 files changed

+22
-19
lines changed

include/glow/Backends/Backend.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef GLOW_BASE_BACKEND_H
2-
#define GLOW_BASE_BACKEND_H
1+
#ifndef GLOW_BACKENDS_BACKEND_H
2+
#define GLOW_BACKENDS_BACKEND_H
33

44
namespace glow {
55

@@ -19,7 +19,7 @@ enum class BackendKind {
1919
class Backend {
2020
public:
2121
/// Dtor.
22-
virtual ~Backend() {}
22+
virtual ~Backend() = default;
2323

2424
/// Wipe out the state of the interpreter.
2525
virtual void clear() = 0;
@@ -44,8 +44,8 @@ class Backend {
4444
};
4545

4646
/// Create a backend of kind \p kind, to run the module \p M.
47-
Backend *createBackend(BackendKind kind, Module *M);
47+
Backend *createBackend(BackendKind backendKind, Module *M);
4848

4949
} // namespace glow
5050

51-
#endif // GLOW_BASE_BACKEND_H
51+
#endif // GLOW_BACKENDS_BACKEND_H

include/glow/Backends/MemoryAllocator.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#ifndef GLOW_BASE_MEMORYALLOCATOR_H
2-
#define GLOW_BASE_MEMORYALLOCATOR_H
3-
1+
#ifndef GLOW_BACKENDS_MEMORYALLOCATOR_H
2+
#define GLOW_BACKENDS_MEMORYALLOCATOR_H
43
#include <cstddef>
54
#include <cstdint>
65
#include <list>
@@ -37,7 +36,7 @@ class MemoryAllocator {
3736
/// A reserved value to mark invalid allocation.
3837
static const size_t npos;
3938

40-
MemoryAllocator(size_t poolSize) : poolSize_(poolSize) {}
39+
explicit MemoryAllocator(size_t poolSize) : poolSize_(poolSize) {}
4140

4241
void reset() {
4342
maxMemoryAllocated_ = 0;
@@ -47,8 +46,9 @@ class MemoryAllocator {
4746
/// \returns True if the value \p idx is within the currently allocated range.
4847
bool contains(size_t idx) {
4948
for (auto &s : allocations_) {
50-
if (s.contains(idx))
49+
if (s.contains(idx)) {
5150
return true;
51+
}
5252
}
5353
return false;
5454
}
@@ -67,4 +67,4 @@ class MemoryAllocator {
6767

6868
} // namespace glow
6969

70-
#endif // GLOW_BASE_MEMORYALLOCATOR_H
70+
#endif // GLOW_BACKENDS_MEMORYALLOCATOR_H

src/glow/Backends/OpenCL/OpenCL.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static void dumpCompileLog(cl_device_id dev, cl_program prog) {
3636
clGetProgramBuildInfo(prog, dev, CL_PROGRAM_BUILD_LOG, 0, nullptr, &log_size);
3737

3838
// Allocate memory for the log.
39-
char *log = (char *)malloc(log_size);
39+
auto *log = (char *)malloc(log_size);
4040

4141
// Get the log.
4242
clGetProgramBuildInfo(prog, dev, CL_PROGRAM_BUILD_LOG, log_size, log,
@@ -53,7 +53,7 @@ OCLBackend::OCLBackend(Module *M) : M_(M), allocator_(0xFFFFFFFF) {
5353
clGetDeviceIDs(nullptr, CL_DEVICE_TYPE_DEFAULT, 1, &deviceId_, nullptr);
5454
GLOW_ASSERT(err == CL_SUCCESS && "clGetDeviceIDs Failed.");
5555

56-
context_ = clCreateContext(0, 1, &deviceId_, nullptr, nullptr, &err);
56+
context_ = clCreateContext(nullptr, 1, &deviceId_, nullptr, nullptr, &err);
5757
GLOW_ASSERT(context_ && "clCreateContext Failed.");
5858

5959
commands_ = clCreateCommandQueue(context_, deviceId_, 0, &err);
@@ -76,7 +76,7 @@ OCLBackend::~OCLBackend() {
7676
clReleaseContext(context_);
7777
if (deviceBuffer_) {
7878
clReleaseMemObject(deviceBuffer_);
79-
deviceBuffer_ = 0;
79+
deviceBuffer_ = nullptr;
8080
}
8181
clear();
8282
}
@@ -397,8 +397,9 @@ void OCLBackend::doForwardPass(bool isTrain) {
397397

398398
void OCLBackend::copyWeightsToDevice() {
399399
for (auto it : tensors_) {
400-
if (!externalTensors_.count(it.first))
400+
if (!externalTensors_.count(it.first)) {
401401
continue;
402+
}
402403
Tensor *T = externalTensors_[it.first];
403404
size_t sizeInBytes = T->getType().getSizeInBytes();
404405
// Issue a non-blocking command to copy the buffer to the device.
@@ -415,8 +416,9 @@ void OCLBackend::copyWeightsFromDevice() {
415416
clFinish(commands_);
416417

417418
for (auto it : tensors_) {
418-
if (!externalTensors_.count(it.first))
419+
if (!externalTensors_.count(it.first)) {
419420
continue;
421+
}
420422

421423
Tensor *T = externalTensors_[it.first];
422424
size_t sizeInBytes = T->getType().getSizeInBytes();
@@ -470,7 +472,7 @@ void OCLBackend::init() {
470472
// Release the memory from the previous run.
471473
if (deviceBuffer_) {
472474
clReleaseMemObject(deviceBuffer_);
473-
deviceBuffer_ = 0;
475+
deviceBuffer_ = nullptr;
474476
}
475477

476478
deviceBuffer_ = clCreateBuffer(context_, CL_MEM_READ_WRITE, requiredSpace,

src/glow/Graph/Graph.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,9 @@ TransposeNode *Graph::createTranspose(llvm::StringRef name, Node *input,
159159
/// \returns true if \p T1 and T2 has the exact same type except for dimension
160160
/// \p dim.
161161
static bool sameSameShapeExceptDim(TypeRef T1, TypeRef T2, unsigned dim) {
162-
if (T1->getElementType() != T2->getElementType())
162+
if (T1->getElementType() != T2->getElementType()) {
163163
return false;
164+
}
164165

165166
auto D1 = T1->dims();
166167
auto D2 = T2->dims();
@@ -303,7 +304,7 @@ struct DottyPrinterPass : NodeVisitor {
303304
return std::find(nodeEdges.begin(), nodeEdges.end(), e) == nodeEdges.end();
304305
}
305306

306-
DottyPrinterPass(std::ostream &os) : os_(os) {}
307+
explicit DottyPrinterPass(std::ostream &os) : os_(os) {}
307308

308309
void pre(Node *parent, Node *N) override {
309310
nodeEdges.emplace_back(parent, N);

0 commit comments

Comments
 (0)