Skip to content

Commit a8bf721

Browse files
authored
Merge pull request #272 from diptorupd/tools/clang-format
Tools/clang format
2 parents fd63a3e + e328619 commit a8bf721

Some content is hidden

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

41 files changed

+926
-922
lines changed

.clang-format

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
BasedOnStyle: LLVM
2+
IndentWidth: 4
3+
AccessModifierOffset: -4
4+
AlignEscapedNewlines: Right
5+
AllowAllParametersOfDeclarationOnNextLine: false
6+
BinPackParameters: false
7+
BreakBeforeBraces: Custom
8+
BraceWrapping:
9+
AfterCaseLabel: true
10+
AfterClass: true
11+
AfterControlStatement: MultiLine
12+
AfterEnum: true
13+
AfterFunction: true
14+
AfterNamespace: true
15+
AfterObjCDeclaration: false
16+
AfterStruct: true
17+
AfterUnion: true
18+
AfterExternBlock: true
19+
BeforeCatch: false
20+
BeforeElse: true
21+
IndentBraces: false
22+
SplitEmptyFunction: true
23+
SplitEmptyRecord: true
24+
SplitEmptyNamespace: true
25+

.git-blame-ignore-revs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22

33
# Migrate code style to Black
44
41ccd65e2e659aa0add0e5ab59f1a46e32cc4c46
5+
6+
# Migrate code style to clang-format
7+
4b0ecc01669bb2d281ee85b54fb76f8a9b94d63f

.github/workflows/clang-format.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# This is a workflow to format C/C++ sources with clang-format
2+
3+
name: clang-format Check
4+
5+
# Controls when the action will run. Triggers the workflow on push or pull request
6+
# events but only for the master branch
7+
on:
8+
push:
9+
branches: [master]
10+
pull_request:
11+
branches: [master]
12+
13+
jobs:
14+
formatting-check:
15+
name: Formatting Check
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v2
19+
- name: Run clang-format style check for C/C++ programs.
20+
uses: jidicula/[email protected]
21+
with:
22+
clang-format-version: '11'
23+
check-path: 'dpctl-capi'

CONTRIBUTING.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
## Source Code Formatting¶
44

5+
### C/C++ code style
6+
7+
We use [clang-format](https://clang.llvm.org/docs/ClangFormat.html) code formatter.
8+
9+
Install: `pip install clang`
10+
11+
- Revision: `10.0.1`
12+
- See the default configuration used by dpCtl in `.clang-format`.
13+
14+
Run before each commit: `clang-format -style=file -i dpctl-capi/include/*.h dpctl-capi/include/Support/*.h dpctl-capi/source/*.cpp dpctl-capi/tests/*.cpp dpctl-capi/helper/include/*.h dpctl-capi/helper/source/*.cpp`
15+
516
### Python code style
617

718

dpctl-capi/helper/include/dpctl_dynamic_lib_helper.h

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@
2727

2828
#if defined(__linux__) || defined(_WIN32) || defined(_WIN64)
2929

30-
#ifdef __linux__
30+
#ifdef __linux__
3131

32-
#include <dlfcn.h>
32+
#include <dlfcn.h>
3333

34-
#elif defined(_WIN32) || defined(_WIN64)
34+
#elif defined(_WIN32) || defined(_WIN64)
3535

36-
#define NOMINMAX
37-
#include <windows.h>
36+
#define NOMINMAX
37+
#include <windows.h>
3838

39-
#endif // __linux__
39+
#endif // __linux__
4040

4141
#include <cstdint>
4242

@@ -46,51 +46,48 @@ namespace dpctl
4646
class DynamicLibHelper final
4747
{
4848
public:
49-
DynamicLibHelper() = delete;
49+
DynamicLibHelper() = delete;
5050
DynamicLibHelper(const DynamicLibHelper &) = delete;
51-
DynamicLibHelper(const char * libName, int flag)
51+
DynamicLibHelper(const char *libName, int flag)
5252
{
5353

54-
#ifdef __linux__
54+
#ifdef __linux__
5555
_handle = dlopen(libName, flag);
56-
#elif defined(_WIN32) || defined(_WIN64)
56+
#elif defined(_WIN32) || defined(_WIN64)
5757
_handle = LoadLibraryA(libName);
58-
#endif
58+
#endif
5959
}
6060

6161
~DynamicLibHelper()
6262
{
63-
#ifdef __linux__
63+
#ifdef __linux__
6464
dlclose(_handle);
65-
#elif defined(_WIN32) || defined(_WIN64)
65+
#elif defined(_WIN32) || defined(_WIN64)
6666
FreeLibrary((HMODULE)_handle);
67-
#endif
67+
#endif
6868
};
6969

70-
template <typename T>
71-
T getSymbol(const char * symName)
70+
template <typename T> T getSymbol(const char *symName)
7271
{
73-
#ifdef __linux__
74-
void * sym = dlsym(_handle, symName);
75-
char * error = dlerror();
72+
#ifdef __linux__
73+
void *sym = dlsym(_handle, symName);
74+
char *error = dlerror();
7675

77-
if (NULL != error)
78-
{
76+
if (NULL != error) {
7977
return nullptr;
8078
}
81-
#elif defined(_WIN32) || defined(_WIN64)
82-
void * sym = (void *)GetProcAddress((HMODULE)_handle, symName);
79+
#elif defined(_WIN32) || defined(_WIN64)
80+
void *sym = (void *)GetProcAddress((HMODULE)_handle, symName);
8381

84-
if (NULL == sym)
85-
{
82+
if (NULL == sym) {
8683
return nullptr;
8784
}
88-
#endif
85+
#endif
8986

9087
return (T)sym;
9188
}
9289

93-
bool opened () const
90+
bool opened() const
9491
{
9592
if (!_handle)
9693
return false;
@@ -99,7 +96,7 @@ class DynamicLibHelper final
9996
}
10097

10198
private:
102-
void * _handle = nullptr;
99+
void *_handle = nullptr;
103100
};
104101

105102
} // namespace dpctl

dpctl-capi/helper/source/dpctl_utils_helper.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,18 @@
2424
//===----------------------------------------------------------------------===//
2525

2626
#include "dpctl_utils_helper.h"
27-
#include <string>
2827
#include <sstream>
28+
#include <string>
2929

3030
using namespace cl::sycl;
3131

3232
/*!
33-
* Transforms enum info::device_type to string.
34-
*/
33+
* Transforms enum info::device_type to string.
34+
*/
3535
std::string DPCTL_DeviceTypeToStr(info::device_type devTy)
3636
{
3737
std::stringstream ss;
38-
switch (devTy)
39-
{
38+
switch (devTy) {
4039
case info::device_type::cpu:
4140
ss << "cpu" << '\n';
4241
break;
@@ -59,22 +58,27 @@ std::string DPCTL_DeviceTypeToStr(info::device_type devTy)
5958
}
6059

6160
/*!
62-
* Transforms string to enum info::device_type.
63-
*/
61+
* Transforms string to enum info::device_type.
62+
*/
6463
info::device_type DPCTL_StrToDeviceType(std::string devTyStr)
6564
{
6665
info::device_type devTy;
6766
if (devTyStr == "cpu") {
6867
devTy = info::device_type::cpu;
69-
} else if(devTyStr == "gpu") {
68+
}
69+
else if (devTyStr == "gpu") {
7070
devTy = info::device_type::gpu;
71-
} else if(devTyStr == "accelerator") {
71+
}
72+
else if (devTyStr == "accelerator") {
7273
devTy = info::device_type::accelerator;
73-
} else if(devTyStr == "custom") {
74+
}
75+
else if (devTyStr == "custom") {
7476
devTy = info::device_type::custom;
75-
} else if(devTyStr == "host") {
77+
}
78+
else if (devTyStr == "host") {
7679
devTy = info::device_type::host;
77-
} else {
80+
}
81+
else {
7882
// \todo handle the error
7983
throw std::runtime_error("Unknown device type.");
8084
}

dpctl-capi/include/Support/CBindingWrapping.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@
3232
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
3333
__attribute__((unused)) inline ty *unwrap(ref P) \
3434
{ \
35-
return reinterpret_cast<ty*>(P); \
35+
return reinterpret_cast<ty *>(P); \
3636
} \
3737
\
3838
__attribute__((unused)) inline ref wrap(const ty *P) \
3939
{ \
40-
return reinterpret_cast<ref>(const_cast<ty*>(P)); \
40+
return reinterpret_cast<ref>(const_cast<ty *>(P)); \
4141
}
4242

4343
/*!
@@ -47,10 +47,9 @@
4747
#define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
4848
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
4949
\
50-
template<typename T> \
51-
__attribute__((unused)) inline T *unwrap(ref P) \
50+
template <typename T> __attribute__((unused)) inline T *unwrap(ref P) \
5251
{ \
53-
T *Q = (T*)unwrap(P); \
52+
T *Q = (T *)unwrap(P); \
5453
assert(Q && "Invalid cast!"); \
5554
return Q; \
5655
}

dpctl-capi/include/Support/DllExport.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
#pragma once
2727

2828
#ifdef _WIN32
29-
# ifdef DPCTLSyclInterface_EXPORTS
30-
# define DPCTL_API __declspec(dllexport)
31-
# else
32-
# define DPCTL_API __declspec(dllimport)
33-
# endif
29+
#ifdef DPCTLSyclInterface_EXPORTS
30+
#define DPCTL_API __declspec(dllexport)
3431
#else
35-
# define DPCTL_API
32+
#define DPCTL_API __declspec(dllimport)
33+
#endif
34+
#else
35+
#define DPCTL_API
3636
#endif

dpctl-capi/include/Support/ExternC.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===----------- ExternC.h - Defines a extern C helper macro -*-C++-*- ===//
1+
//===----------- ExternC.h - Defines an extern C helper macro -*-C++-*- ===//
22
//
33
// Data Parallel Control (dpCtl)
44
//
@@ -26,8 +26,10 @@
2626
#pragma once
2727

2828
#ifdef __cplusplus
29-
#define DPCTL_C_EXTERN_C_BEGIN extern "C" {
30-
#define DPCTL_C_EXTERN_C_END }
29+
#define DPCTL_C_EXTERN_C_BEGIN \
30+
extern "C" \
31+
{
32+
#define DPCTL_C_EXTERN_C_END }
3133
#else
3234
#define DPCTL_C_EXTERN_C_BEGIN
3335
#define DPCTL_C_EXTERN_C_END

dpctl-capi/include/Support/MemOwnershipAttrs.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@
5151
#endif
5252
/*!
5353
* @def __dpctl_take
54-
* @brief The __dpctl_take attribute indicates that the function "takes" over the
55-
* ownership of the object and the user must not use the object as an argument
56-
* to another function.
54+
* @brief The __dpctl_take attribute indicates that the function "takes" over
55+
* the ownership of the object and the user must not use the object as an
56+
* argument to another function.
5757
*
5858
* The __dpctl_take attribute mens that the function destroys it before the
5959
* function returns, and the caller must not use the object again in any other

0 commit comments

Comments
 (0)