Skip to content

Commit

Permalink
FORMAT - Add .clang-format and .pre-commit-config.yaml
Browse files Browse the repository at this point in the history
Change-Id: Ia8e9779db328680031f219369287b66df64024ee
Signed-off-by: Galantsev, Dmitrii <[email protected]>
  • Loading branch information
dmitrii-galantsev committed Jan 12, 2024
1 parent 9bfdca2 commit c066360
Show file tree
Hide file tree
Showing 22 changed files with 3,258 additions and 3,283 deletions.
46 changes: 46 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
Language: Cpp
BasedOnStyle: Google
ColumnLimit: 100
IndentCaseBlocks: true
IndentWidth: 4
MaxEmptyLinesToKeep: 2
SpaceAfterTemplateKeyword: false
SpacesBeforeTrailingComments: 4
DerivePointerAlignment: false
PointerAlignment: Left
ReferenceAlignment: Left
Standard: Latest

# These must go in order from most to least specific.
# Priority number goes from lowest to highest.
# Higher the number - lower the include position.
IncludeCategories:
# "*"
- Regex: '^".*"'
Priority: 1
CaseSensitive: false
# <sys/*.h> and <*.h> together
- Regex: '^<sys/.*\.h>'
Priority: 2
CaseSensitive: false
# <*/*.h> after <*>
- Regex: '^<.*/.*\.h>'
Priority: 4
CaseSensitive: false
# <sys/*.h> and <*.h> together
- Regex: '^<.*\.h>'
Priority: 2
CaseSensitive: false
# <*>
- Regex: '^<.*'
Priority: 3
CaseSensitive: false
# *
- Regex: '.*'
Priority: 5
CaseSensitive: false

IndentAccessModifiers: true
...

25 changes: 25 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# THIS FILE IS GENERATED FROM .clangd!
# Run ./.update-clang-tidy.sh to regenerate.
Checks:
bugprone*,
clang-analyzer*,
google*,
misc*,
modernize*,
-abseil*,
-bugprone-easily-swappable-parameters,
-bugprone-reserved-identifier,
-clang-analyzer-security.insecureAPI.strcpy,
-cppcoreguidelines*,
-cppcoreguidelines-pro*,
-misc-non-copyable-objects,
-misc-use-anonymous-namespace,
-modernize-avoid-c-arrays,
-modernize-redundant-void-arg,
-modernize-use-auto,
-modernize-use-nodiscard,
-modernize-use-noexcept,
-modernize-use-trailing-return-type,
-modernize-use-using,
-performance*,
-readability*,
36 changes: 36 additions & 0 deletions .clangd
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
CompileFlags:
Remove: -W*
Add: [-Wall, -pedantic, -I/opt/rocm/include, -I/opt/rocm/include/hsa]
Compiler: clang++

# list here: https://clang.llvm.org/extra/clang-tidy/checks/list.html
Diagnostics:
UnusedIncludes: Strict
ClangTidy:
Add: [
bugprone*,
clang-analyzer*,
google*,
misc*,
modernize*,
]
Remove: [
abseil*,
bugprone-easily-swappable-parameters,
bugprone-reserved-identifier,
clang-analyzer-security.insecureAPI.strcpy,
cppcoreguidelines*,
cppcoreguidelines-pro*,
misc-non-copyable-objects,
misc-use-anonymous-namespace,
modernize-avoid-c-arrays,
modernize-redundant-void-arg,
modernize-use-auto,
modernize-use-nodiscard,
modernize-use-noexcept,
modernize-use-trailing-return-type,
modernize-use-using,
performance*,
readability*,
]
#CheckOptions:
28 changes: 28 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# NOTE! Please use 'git ls-files -i --exclude-standard'
# command after changing this file, to see if there are
# any tracked files which get ignored after the change.

# VisualStudioCode
.vscode/

# Below files generated via CMake

# Build directory
build/

# CMake cache
.cache/

# Simulated SYSFS - for early development or debug
device/

# Misc
__pycache__
README
README.html

# do NOT ignore these files
!.clang-format
!.clang-tidy
!.clangd

30 changes: 30 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# - How to use:
# python3 -m pip install pre-commit
# pre-commit install --install hooks
# Upon a new commit - the hooks should automagically run
#
# - How to skip:
# git commit --no-verify
# or
# SKIP=clang-format-docker git commit
# SKIP=cpplint-docker git commit

fail_fast: false
repos:
# For portability I decided to use Docker containers
- repo: https://github.com/dmitrii-galantsev/pre-commit-docker-cpplint
rev: 0.0.3
hooks:
- id: clang-format-docker
# - id: cpplint-docker
# Below is a local way of running formatters and linters
# NOTE: clang-tidy is not used in the above tests
# - repo: https://github.com/pocc/pre-commit-hooks
# rev: v1.3.5
# hooks:
# - id: clang-format
# args: [--no-diff, -i]
# - id: clang-tidy
# args: [-p=build, --quiet]
# - id: cpplint
# args: [--verbose=5]
36 changes: 36 additions & 0 deletions .update-clang-tidy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash

set -x # trace
set -e # exit immediately if command fails
set -u # exit if an undefined variable is found

awk '
BEGIN {
print "# THIS FILE IS GENERATED FROM .clangd!"
print "# Run ./.update-clang-tidy.sh to regenerate."
print "Checks:"
}
/Add: \[$/{
a=1
next
}
/]/{
a=0
}
a{
gsub(/^\s+/," ")
print
}
/Remove: \[$/{
r=1
next
}
/]/{
r=0
}
r{
gsub(/^\s+/," -")
print
}
' .clangd | tee .clang-tidy
22 changes: 10 additions & 12 deletions base_test.cpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
//
// The University of Illinois/NCSA
// Open Source License (NCSA)
//
//
// Copyright (c) 2014-2015, Advanced Micro Devices, Inc. All rights reserved.
//
//
// Developed by:
//
//
// AMD Research and AMD HSA Software Development
//
//
// Advanced Micro Devices, Inc.
//
//
// www.amd.com
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal with the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
//
// - Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimers.
// - Redistributions in binary form must reproduce the above copyright
Expand All @@ -29,7 +29,7 @@
// nor the names of its contributors may be used to endorse or promote
// products derived from this Software without specific prior written
// permission.
//
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
Expand All @@ -44,10 +44,8 @@

// Default Constructor
BaseTest::BaseTest(size_t num) {

// Set the numIteration_ to be 10 by default
num_iteration_ = num;
// Set the numIteration_ to be 10 by default
num_iteration_ = num;
}

BaseTest::~BaseTest() {}

71 changes: 34 additions & 37 deletions base_test.hpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
//
// The University of Illinois/NCSA
// Open Source License (NCSA)
//
//
// Copyright (c) 2014-2015, Advanced Micro Devices, Inc. All rights reserved.
//
//
// Developed by:
//
//
// AMD Research and AMD HSA Software Development
//
//
// Advanced Micro Devices, Inc.
//
//
// www.amd.com
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal with the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
//
// - Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimers.
// - Redistributions in binary form must reproduce the above copyright
Expand All @@ -29,7 +29,7 @@
// nor the names of its contributors may be used to endorse or promote
// products derived from this Software without specific prior written
// permission.
//
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
Expand All @@ -42,7 +42,7 @@

#ifndef ROC_BANDWIDTH_TEST_BASE_H_
#define ROC_BANDWIDTH_TEST_BASE_H_
#if(defined(RBT_HSA_VERSION_FLAT) && ((RBT_HSA_VERSION_FLAT) < RBT_HSA_VERSION_FILEREORG))
#if (defined(RBT_HSA_VERSION_FLAT) && ((RBT_HSA_VERSION_FLAT) < RBT_HSA_VERSION_FILEREORG))
// Hsa package with out file reorganization
// This is for backward compatibility and will be deprecated from future release
#include "hsa.h"
Expand All @@ -59,41 +59,38 @@ using namespace std;
// @Brief: An interface for tests to do some basic things,

class BaseTest {
public:
BaseTest(size_t num_iter = 4);

public:

BaseTest(size_t num_iter = 4);

virtual ~BaseTest();

// @Brief: Allows setup proceedures to be completed
// before running the benchmark test case
virtual void SetUp() = 0;
virtual ~BaseTest();

// @Brief: Launches the proceedures of test scenario
virtual void Run() = 0;
// @Brief: Allows setup proceedures to be completed
// before running the benchmark test case
virtual void SetUp() = 0;

// @Brief: Allows clean up proceedures to be invoked
virtual void Close() = 0;
// @Brief: Launches the proceedures of test scenario
virtual void Run() = 0;

// @Brief: Display the results
virtual void Display() const = 0;
// @Brief: Allows clean up proceedures to be invoked
virtual void Close() = 0;

// @Brief: Set number of iterations to run
void set_num_iteration(size_t num_iter) {
num_iteration_ = num_iter;
return;
}
// @Brief: Display the results
virtual void Display() const = 0;

// @Brief: Pre-declare some variables for deriviation, the
// derived class may declare more if needed
protected:
// @Brief: Set number of iterations to run
void set_num_iteration(size_t num_iter) {
num_iteration_ = num_iter;
return;
}

// @Brief: Real iteration number
uint64_t num_iteration_;
// @Brief: Pre-declare some variables for deriviation, the
// derived class may declare more if needed
protected:
// @Brief: Real iteration number
uint64_t num_iteration_;

// @Brief: Status code
hsa_status_t err_;
// @Brief: Status code
hsa_status_t err_;
};

#endif // ROC_BANDWIDTH_TEST_BASE_H_
#endif // ROC_BANDWIDTH_TEST_BASE_H_
Loading

0 comments on commit c066360

Please sign in to comment.