Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add clang format to pre-commit config #1450

Merged
merged 3 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 17 additions & 46 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,71 +1,42 @@
BasedOnStyle: LLVM
IndentWidth: 4
UseTab: Never
Language: Cpp
Standard: Cpp11

AccessModifierOffset: -4

AlignConsecutiveDeclarations: false
AlignConsecutiveAssignments: false
AlignConsecutiveMacros: true
AlignTrailingComments: true
AlignConsecutiveBitFields: true
AlignEscapedNewlines: Right

AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Empty

AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
AlwaysBreakTemplateDeclarations: Yes

BinPackArguments: false
BinPackParameters: false

BreakBeforeBraces: Allman
BreakConstructorInitializersBeforeComma: true

BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: true
AfterControlStatement: MultiLine
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterObjCDeclaration: false
AfterStruct: true
AfterUnion: true
BeforeCatch: true
AfterExternBlock: true
BeforeCatch: false
BeforeElse: true
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBraces: Custom

ColumnLimit: 120
CommentPragmas: '.*'
ColumnLimit: 80

IndentCaseLabels: false
IndentWidth: 4
IndentWrappedFunctionNames: true

KeepEmptyLinesAtTheStartOfBlocks: false
NamespaceIndentation: All

PointerAlignment: Left
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false

SortIncludes: false
ReflowComments: true

IncludeCategories:
- Regex: '^".*'
Priority: 3
- Regex: '^<.*'
Priority: 2
SortIncludes: true
Standard: c++17
7 changes: 7 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# $ git config blame.ignoreRevsFile .git-blame-ignore-revs

# Add pre-commit hooks
b0cd5f85c9b0c2705359fee3a3f4f3feda53bfa0

# Add black to pre-commit config
88981b5ae1c99f9b64758db44dfb39f2c20b10db
17 changes: 12 additions & 5 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@ jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3.5.2
- uses: actions/setup-python@v4.6.1
with:
python-version: '3.10'
- uses: pre-commit/action@v3.0.0
- name: Set up clang-format
run: |
sudo apt-get install -y clang-format-12
sudo unlink /usr/bin/clang-format
sudo ln -s /usr/bin/clang-format-12 /usr/bin/clang-format
clang-format --version

- uses: actions/checkout@v3.5.2
- uses: actions/setup-python@v4.6.1
with:
python-version: '3.10'
- uses: pre-commit/action@v3.0.0
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,8 @@ repos:
hooks:
- id: black
args: ["--check", "--diff", "--color"]
- repo: https://github.com/pocc/pre-commit-hooks
rev: v1.3.5
hooks:
- id: clang-format
args: ["-i", "--version=12"]
40 changes: 24 additions & 16 deletions dpnp/backend/examples/example10.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
* Example 10.
*
* Possible compile line:
* clang++ -fsycl dpnp/backend/examples/example10.cpp -Idpnp -Idpnp/backend/include -Ldpnp -Wl,-rpath='$ORIGIN'/dpnp -ldpnp_backend_c -o example10 -lmkl_sycl -lmkl_intel_ilp64 -lmkl_core
* clang++ -fsycl dpnp/backend/examples/example10.cpp -Idpnp
* -Idpnp/backend/include -Ldpnp -Wl,-rpath='$ORIGIN'/dpnp -ldpnp_backend_c -o
* example10 -lmkl_sycl -lmkl_intel_ilp64 -lmkl_core
*/

#include <iostream>
Expand All @@ -38,21 +40,23 @@

#include <dpnp_iface.hpp>

void test_dpnp_random_normal(
const size_t size, const size_t iters, const size_t seed, const double loc, const double scale)
void test_dpnp_random_normal(const size_t size,
const size_t iters,
const size_t seed,
const double loc,
const double scale)
{
clock_t start, end;
double dev_time_used = 0.0;
double sum_dev_time_used = 0.0;

dpnp_queue_initialize_c(QueueOptions::GPU_SELECTOR);

double* result = (double*)dpnp_memory_alloc_c(size * sizeof(double));
double *result = (double *)dpnp_memory_alloc_c(size * sizeof(double));

dpnp_rng_srand_c(seed); // TODO: will move

for (size_t i = 0; i < iters; ++i)
{
for (size_t i = 0; i < iters; ++i) {
start = clock();
dpnp_rng_normal_c<double>(result, loc, scale, size);
end = clock();
Expand All @@ -70,29 +74,32 @@ void test_dpnp_random_normal(
}

// TODO: name check
void test_mkl_random_normal(
const size_t size, const size_t iters, const size_t seed, const double loc, const double scale)
void test_mkl_random_normal(const size_t size,
const size_t iters,
const size_t seed,
const double loc,
const double scale)
{
clock_t start, end;
double dev_time_used = 0.0;
double sum_dev_time_used = 0.0;

sycl::queue queue{sycl::gpu_selector()};

double* result = reinterpret_cast<double*>(malloc_shared(size * sizeof(double), queue));
if (result == nullptr)
{
double *result =
reinterpret_cast<double *>(malloc_shared(size * sizeof(double), queue));
if (result == nullptr) {
throw std::runtime_error("Error: out of memory.");
}

oneapi::mkl::rng::mt19937 rng_engine(queue, seed);
oneapi::mkl::rng::gaussian<double> distribution(loc, scale);

for (size_t i = 0; i < iters; ++i)
{
for (size_t i = 0; i < iters; ++i) {
start = clock();

auto event_out = oneapi::mkl::rng::generate(distribution, rng_engine, size, result);
auto event_out =
oneapi::mkl::rng::generate(distribution, rng_engine, size, result);
event_out.wait();

end = clock();
Expand All @@ -110,7 +117,7 @@ void test_mkl_random_normal(
return;
}

int main(int, char**)
int main(int, char **)
{
const size_t size = 100000000;
const size_t iters = 30;
Expand All @@ -119,7 +126,8 @@ int main(int, char**)
const double loc = 0.0;
const double scale = 1.0;

std::cout << "Normal distr. params:\nloc is " << loc << ", scale is " << scale << std::endl;
std::cout << "Normal distr. params:\nloc is " << loc << ", scale is "
<< scale << std::endl;

test_dpnp_random_normal(size, iters, seed, loc, scale);
test_mkl_random_normal(size, iters, seed, loc, scale);
Expand Down
28 changes: 15 additions & 13 deletions dpnp/backend/examples/example11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@
/**
* Example 11.
*
* This example shows simple usage of the DPNP C++ Backend library RNG shuffle function
* for one and ndim arrays.
* This example shows simple usage of the DPNP C++ Backend library RNG shuffle
* function for one and ndim arrays.
*
* Possible compile line:
* g++ -g dpnp/backend/examples/example11.cpp -Idpnp -Idpnp/backend/include -Ldpnp -Wl,-rpath='$ORIGIN'/dpnp -ldpnp_backend_c -o example11
* g++ -g dpnp/backend/examples/example11.cpp -Idpnp -Idpnp/backend/include
* -Ldpnp -Wl,-rpath='$ORIGIN'/dpnp -ldpnp_backend_c -o example11
*
*/

Expand All @@ -39,21 +40,21 @@
#include <dpnp_iface.hpp>

template <typename T>
void print_dpnp_array(T* arr, size_t size)
void print_dpnp_array(T *arr, size_t size)
{
std::cout << std::endl;
for (size_t i = 0; i < size; ++i)
{
for (size_t i = 0; i < size; ++i) {
std::cout << arr[i] << ", ";
}
std::cout << std::endl;
}

int main(int, char**)
int main(int, char **)
{
// Two cases:
// 1) array size = 100, ndim = 1, high_dim_size = 10 (aka ndarray with shape (100,) )
// 2) array size = 100, ndim = 2, high_dim_size = 20 (e.g. ndarray with shape (20, 5) and len(array) = 20 )
// 1) array size = 100, ndim = 1, high_dim_size = 10 (aka ndarray with shape
// (100,) ) 2) array size = 100, ndim = 2, high_dim_size = 20 (e.g. ndarray
// with shape (20, 5) and len(array) = 20 )
const size_t ndim_cases = 2;
const size_t itemsize = sizeof(double);
const size_t ndim[ndim_cases] = {1, 2};
Expand All @@ -63,9 +64,9 @@ int main(int, char**)

// DPNPC dpnp_rng_shuffle_c
// DPNPC interface
double* array_1 = reinterpret_cast<double*>(dpnp_memory_alloc_c(size * sizeof(double)));
for (size_t i = 0; i < ndim_cases; i++)
{
double *array_1 =
reinterpret_cast<double *>(dpnp_memory_alloc_c(size * sizeof(double)));
for (size_t i = 0; i < ndim_cases; i++) {
std::cout << "\nREPRODUCE: DPNPC dpnp_rng_shuffle_c:";
std::cout << "\nDIMS: " << ndim[i] << std::endl;
// init array 0, 1, 2, 3, 4, 5, 6, ....
Expand All @@ -74,7 +75,8 @@ int main(int, char**)
std::cout << "\nINPUT array:";
print_dpnp_array(array_1, size);
dpnp_rng_srand_c(seed);
dpnp_rng_shuffle_c<double>(array_1, itemsize, ndim[i], high_dim_size[i], size);
dpnp_rng_shuffle_c<double>(array_1, itemsize, ndim[i], high_dim_size[i],
size);
// print shuffle result
std::cout << "\nSHUFFLE INPUT array:";
print_dpnp_array(array_1, size);
Expand Down
24 changes: 13 additions & 11 deletions dpnp/backend/examples/example3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,42 +31,44 @@
*
* Possible compile line:
* . /opt/intel/oneapi/setvars.sh
* g++ -g dpnp/backend/examples/example3.cpp -Idpnp -Idpnp/backend/include -Ldpnp -Wl,-rpath='$ORIGIN'/dpnp -ldpnp_backend_c -o example3
* g++ -g dpnp/backend/examples/example3.cpp -Idpnp -Idpnp/backend/include
* -Ldpnp -Wl,-rpath='$ORIGIN'/dpnp -ldpnp_backend_c -o example3
*
*/

#include <iostream>

#include "dpnp_iface.hpp"

int main(int, char**)
int main(int, char **)
{
const size_t size = 256;

dpnp_queue_initialize_c();
std::cout << "SYCL queue is CPU: " << dpnp_queue_is_cpu_c() << std::endl;

int* array1 = (int*)dpnp_memory_alloc_c(size * sizeof(int));
double* result = (double*)dpnp_memory_alloc_c(size * sizeof(double));
int *array1 = (int *)dpnp_memory_alloc_c(size * sizeof(int));
double *result = (double *)dpnp_memory_alloc_c(size * sizeof(double));

for (size_t i = 0; i < 10; ++i)
{
for (size_t i = 0; i < 10; ++i) {
array1[i] = i;
result[i] = 0;
std::cout << ", " << array1[i];
}
std::cout << std::endl;

const long ndim = 1;
shape_elem_type* shape = reinterpret_cast<shape_elem_type*>(dpnp_memory_alloc_c(ndim * sizeof(shape_elem_type)));
shape_elem_type *shape = reinterpret_cast<shape_elem_type *>(
dpnp_memory_alloc_c(ndim * sizeof(shape_elem_type)));
shape[0] = size;
shape_elem_type* strides = reinterpret_cast<shape_elem_type*>(dpnp_memory_alloc_c(ndim * sizeof(shape_elem_type)));
shape_elem_type *strides = reinterpret_cast<shape_elem_type *>(
dpnp_memory_alloc_c(ndim * sizeof(shape_elem_type)));
strides[0] = 1;

dpnp_cos_c<int, double>(result, size, ndim, shape, strides, array1, size, ndim, shape, strides, NULL);
dpnp_cos_c<int, double>(result, size, ndim, shape, strides, array1, size,
ndim, shape, strides, NULL);

for (size_t i = 0; i < 10; ++i)
{
for (size_t i = 0; i < 10; ++i) {
std::cout << ", " << result[i];
}
std::cout << std::endl;
Expand Down
Loading