Skip to content

Commit 4b0ecc0

Browse files
author
Diptorup Deb
committed
Reformat C API sources using clang-format.
1 parent abaa044 commit 4b0ecc0

37 files changed

+864
-922
lines changed

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

dpctl-capi/include/dpctl_data_types.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@
4040
#ifndef _MSC_VER
4141

4242
#if !defined(UINT32_MAX)
43-
# error "The standard header <cstdint> is not C++11 compliant. Must #define "\
43+
#error "The standard header <cstdint> is not C++11 compliant. Must #define "\
4444
"__STDC_LIMIT_MACROS before #including llvm-c/DataTypes.h"
4545
#endif
4646

4747
#if !defined(UINT32_C)
48-
# error "The standard header <cstdint> is not C++11 compliant. Must #define "\
48+
#error "The standard header <cstdint> is not C++11 compliant. Must #define "\
4949
"__STDC_CONSTANT_MACROS before #including llvm-c/DataTypes.h"
5050
#endif
5151

@@ -80,21 +80,21 @@ typedef signed int ssize_t;
8080
@brief Represents tha largest possible value of a 64 bit signed integer.
8181
*/
8282
#if !defined(INT64_MAX)
83-
# define INT64_MAX 9223372036854775807LL
83+
#define INT64_MAX 9223372036854775807LL
8484
#endif
8585

8686
/*!
8787
@brief Represents tha smallest possible value of a 64 bit signed integer.
8888
*/
8989
#if !defined(INT64_MIN)
90-
# define INT64_MIN ((-INT64_MAX)-1)
90+
#define INT64_MIN ((-INT64_MAX) - 1)
9191
#endif
9292

9393
/*!
9494
@brief Represents tha largest possible value of a 64bit unsigned integer.
9595
*/
9696
#if !defined(UINT64_MAX)
97-
# define UINT64_MAX 0xffffffffffffffffULL
97+
#define UINT64_MAX 0xffffffffffffffffULL
9898
#endif
9999

100100
/*!

dpctl-capi/include/dpctl_sycl_context_interface.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525

2626
#pragma once
2727

28-
#include "dpctl_data_types.h"
29-
#include "dpctl_sycl_types.h"
30-
#include "dpctl_sycl_platform_interface.h"
3128
#include "Support/DllExport.h"
3229
#include "Support/ExternC.h"
3330
#include "Support/MemOwnershipAttrs.h"
31+
#include "dpctl_data_types.h"
32+
#include "dpctl_sycl_platform_interface.h"
33+
#include "dpctl_sycl_types.h"
3434
#include <stdbool.h>
3535

3636
DPCTL_C_EXTERN_C_BEGIN
@@ -44,8 +44,8 @@ DPCTL_C_EXTERN_C_BEGIN
4444
* @return True if the underlying sycl::context are same, false otherwise.
4545
*/
4646
DPCTL_API
47-
bool DPCTLContext_AreEq (__dpctl_keep const DPCTLSyclContextRef CtxRef1,
48-
__dpctl_keep const DPCTLSyclContextRef CtxRef2);
47+
bool DPCTLContext_AreEq(__dpctl_keep const DPCTLSyclContextRef CtxRef1,
48+
__dpctl_keep const DPCTLSyclContextRef CtxRef2);
4949

5050
/*!
5151
* @brief Returns true if this SYCL context is a host context.
@@ -54,7 +54,7 @@ bool DPCTLContext_AreEq (__dpctl_keep const DPCTLSyclContextRef CtxRef1,
5454
* @return True if the SYCL context is a host context, else False.
5555
*/
5656
DPCTL_API
57-
bool DPCTLContext_IsHost (__dpctl_keep const DPCTLSyclContextRef CtxRef);
57+
bool DPCTLContext_IsHost(__dpctl_keep const DPCTLSyclContextRef CtxRef);
5858

5959
/*!
6060
* @brief Returns the sycl backend for the DPCTLSyclContextRef pointer.
@@ -65,14 +65,14 @@ bool DPCTLContext_IsHost (__dpctl_keep const DPCTLSyclContextRef CtxRef);
6565
*/
6666
DPCTL_API
6767
DPCTLSyclBackendType
68-
DPCTLContext_GetBackend (__dpctl_keep const DPCTLSyclContextRef CtxRef);
68+
DPCTLContext_GetBackend(__dpctl_keep const DPCTLSyclContextRef CtxRef);
6969

7070
/*!
7171
* @brief Delete the pointer after casting it to sycl::context
7272
*
7373
* @param CtxRef The DPCTLSyclContextRef pointer to be deleted.
7474
*/
7575
DPCTL_API
76-
void DPCTLContext_Delete (__dpctl_take DPCTLSyclContextRef CtxRef);
76+
void DPCTLContext_Delete(__dpctl_take DPCTLSyclContextRef CtxRef);
7777

7878
DPCTL_C_EXTERN_C_END

0 commit comments

Comments
 (0)