diff --git a/.coveragerc b/.coveragerc index d437b28e..9b08c31b 100644 --- a/.coveragerc +++ b/.coveragerc @@ -3,4 +3,4 @@ omit = # omit anything in a .local directory anywhere */.local/* # omit everything in /usr - /usr/* \ No newline at end of file + /usr/* diff --git a/.github/workflows/formatting.yml b/.github/workflows/formatting.yml new file mode 100644 index 00000000..9bf2bb36 --- /dev/null +++ b/.github/workflows/formatting.yml @@ -0,0 +1,50 @@ +# This workflow will install Python formatting tool black and check correctness of code format for all python files +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions +name: python-package + +on: + push: + branches: [main, develop] + pull_request: + branches: [main, develop] + +jobs: + formatting: + strategy: + matrix: + python-version: [3.13] + os: [ubuntu-latest, ubuntu-22.04] + + runs-on: ${{matrix.os}} + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + # - name: Install dependencies + # run: | + # python -m pip install --upgrade pip + # pip install black + # - name: black format + # run: | + # black --diff --check . + - name: Check files end with newline + run: | + # Find all files (excluding binary and git files) and check if they end with a newline + EXIT_CODE=0 + while IFS= read -r -d '' file; do + # Skip __init__.py files (should not end with newline) + if [[ "$file" == *"__init__.py" ]]; then + continue + fi + # Skip binary files + if file "$file" | grep -q "text"; then + # Check if file ends with a newline + if [ -n "$(tail -c 1 "$file")" ]; then + echo "ERROR: $file does not end with a newline" + EXIT_CODE=1 + fi + fi + done < <(find . -type f -not -path '*/\.git/*' -print0) + exit $EXIT_CODE diff --git a/.gitignore b/.gitignore index bbb320e3..6472d9f5 100644 --- a/.gitignore +++ b/.gitignore @@ -45,3 +45,6 @@ Sessionx.vim tags # Persistent undo [._]*.un~ + +# Output files and directories +build/ diff --git a/examples/BabelStream/.gitignore b/examples/BabelStream/.gitignore index fa9a52a4..0397a539 100644 --- a/examples/BabelStream/.gitignore +++ b/examples/BabelStream/.gitignore @@ -1 +1 @@ -kokkos/babel_stream/babel_stream \ No newline at end of file +kokkos/babel_stream/babel_stream diff --git a/examples/ExaMiniMD/.gitignore b/examples/ExaMiniMD/.gitignore index 11f94777..68c0ffe6 100644 --- a/examples/ExaMiniMD/.gitignore +++ b/examples/ExaMiniMD/.gitignore @@ -1,2 +1,2 @@ *.nbi -*.nbc \ No newline at end of file +*.nbc diff --git a/examples/ExaMiniMD/README.md b/examples/ExaMiniMD/README.md index a8fc333d..c0d0723a 100644 --- a/examples/ExaMiniMD/README.md +++ b/examples/ExaMiniMD/README.md @@ -2,4 +2,4 @@ This directory contains an implementation of ExaMiniMD written in PyKokkos. Original repo: https://github.com/ECP-copa/ExaMiniMD SHA: b6db78eeab55ccd95675bbf87b4638bb7a403039 -To run: python src/main.py -il input/in.lj --fill \ No newline at end of file +To run: python src/main.py -il input/in.lj --fill diff --git a/examples/ExaMiniMD/standalone/.gitignore b/examples/ExaMiniMD/standalone/.gitignore index 11f94777..68c0ffe6 100644 --- a/examples/ExaMiniMD/standalone/.gitignore +++ b/examples/ExaMiniMD/standalone/.gitignore @@ -1,2 +1,2 @@ *.nbi -*.nbc \ No newline at end of file +*.nbc diff --git a/examples/ExaMiniMD/standalone/input.txt b/examples/ExaMiniMD/standalone/input.txt index b71392ed..270f5e07 100644 --- a/examples/ExaMiniMD/standalone/input.txt +++ b/examples/ExaMiniMD/standalone/input.txt @@ -1,4 +1,4 @@ V: 0.378024 0.545211 0.640403 || -1.068958 -0.481107 0.561693 || 0.460053 -1.095252 -0.577054 || 0.198839 1.077796 -0.682463 || 1.060739 1.373164 -0.723115 || 0.161829 -1.159987 -1.706320 || 0.039016 0.676862 0.622015 || -0.788906 -0.437339 -0.400488 || -1.359995 0.485555 1.040725 || 0.646287 0.055289 0.411390 || -1.268214 1.074131 0.584679 || 0.008655 -0.592103 0.395507 || -0.264262 -0.487297 -1.688796 || 0.905854 0.130842 0.702301 || -0.700365 -0.408724 -1.521469 || -1.064948 1.048318 0.905022 || Mass: 2.000000 || 0.000000 || 0.000000 || 0.000000 || 0.000000 || 0.000000 || 0.000000 || 0.000000 || 74922952976463886612494639615534525265225649798966677392892387483161181263696273328494175337183569571031983095237201100666603071569423424169407163557637775218342900125680904049529227457647208929519363737595668997040750422300188026968362339945938944.000000 || 0.005000 || 0.002500 || 0.000000 || 0.000000 || 16920071172525382285473125425930026455059225750565119522777865124712019447860338814225844729775420856359922438758568758850413809874236159358595359738524412104577874239900167886037697955889152.000000 || 10589246342251358090997449139234627623056451755240821348127726367574270708878985113278288483606729164319343270646915331883419249485806695294377605875108000780781466778198364969505790109913194980835559245252579557376.000000 || 0.000000 || Type: 0 || 0 || 0 || 0 || 0 || 0 || 0 || 0 || 0 || 0 || 0 || 0 || 0 || 0 || 0 || 0 || -Got: 65.100000 \ No newline at end of file +Got: 65.100000 diff --git a/examples/ExaMiniMD/standalone/src/main.py b/examples/ExaMiniMD/standalone/src/main.py index c0cdf917..1087e1d9 100644 --- a/examples/ExaMiniMD/standalone/src/main.py +++ b/examples/ExaMiniMD/standalone/src/main.py @@ -7,4 +7,4 @@ def run() -> None: exa_mini_md.run(exa_mini_md.input.nsteps) if __name__ == "__main__": - run() \ No newline at end of file + run() diff --git a/examples/ExaMiniMD/workload/input.txt b/examples/ExaMiniMD/workload/input.txt index b71392ed..270f5e07 100644 --- a/examples/ExaMiniMD/workload/input.txt +++ b/examples/ExaMiniMD/workload/input.txt @@ -1,4 +1,4 @@ V: 0.378024 0.545211 0.640403 || -1.068958 -0.481107 0.561693 || 0.460053 -1.095252 -0.577054 || 0.198839 1.077796 -0.682463 || 1.060739 1.373164 -0.723115 || 0.161829 -1.159987 -1.706320 || 0.039016 0.676862 0.622015 || -0.788906 -0.437339 -0.400488 || -1.359995 0.485555 1.040725 || 0.646287 0.055289 0.411390 || -1.268214 1.074131 0.584679 || 0.008655 -0.592103 0.395507 || -0.264262 -0.487297 -1.688796 || 0.905854 0.130842 0.702301 || -0.700365 -0.408724 -1.521469 || -1.064948 1.048318 0.905022 || Mass: 2.000000 || 0.000000 || 0.000000 || 0.000000 || 0.000000 || 0.000000 || 0.000000 || 0.000000 || 74922952976463886612494639615534525265225649798966677392892387483161181263696273328494175337183569571031983095237201100666603071569423424169407163557637775218342900125680904049529227457647208929519363737595668997040750422300188026968362339945938944.000000 || 0.005000 || 0.002500 || 0.000000 || 0.000000 || 16920071172525382285473125425930026455059225750565119522777865124712019447860338814225844729775420856359922438758568758850413809874236159358595359738524412104577874239900167886037697955889152.000000 || 10589246342251358090997449139234627623056451755240821348127726367574270708878985113278288483606729164319343270646915331883419249485806695294377605875108000780781466778198364969505790109913194980835559245252579557376.000000 || 0.000000 || Type: 0 || 0 || 0 || 0 || 0 || 0 || 0 || 0 || 0 || 0 || 0 || 0 || 0 || 0 || 0 || 0 || -Got: 65.100000 \ No newline at end of file +Got: 65.100000 diff --git a/examples/ExaMiniMD/workload/src/main.py b/examples/ExaMiniMD/workload/src/main.py index c0cdf917..1087e1d9 100644 --- a/examples/ExaMiniMD/workload/src/main.py +++ b/examples/ExaMiniMD/workload/src/main.py @@ -7,4 +7,4 @@ def run() -> None: exa_mini_md.run(exa_mini_md.input.nsteps) if __name__ == "__main__": - run() \ No newline at end of file + run() diff --git a/examples/LogisticRegression/LR.py b/examples/LogisticRegression/LR.py index 4f0146c5..ff5cefa4 100644 --- a/examples/LogisticRegression/LR.py +++ b/examples/LogisticRegression/LR.py @@ -1062,4 +1062,4 @@ def main(): clf.predict_proba(asarray(X[:2, :])) print(clf.score(asarray(X), asarray(y))) -main() \ No newline at end of file +main() diff --git a/examples/NaiveBayes/GaussianNB.py b/examples/NaiveBayes/GaussianNB.py index ee361b3c..7efb5f3e 100644 --- a/examples/NaiveBayes/GaussianNB.py +++ b/examples/NaiveBayes/GaussianNB.py @@ -627,4 +627,4 @@ def main(): y_pred = gnb.fit(asarray(X_train), asarray(y_train)).predict(asarray(X_test)) print("Number of mislabeled points out of a total %d points : %d" % (X_test.shape[0], (y_test != y_pred).sum())) -main() \ No newline at end of file +main() diff --git a/examples/ParRes/functor/nstream.py b/examples/ParRes/functor/nstream.py index 3cb2f356..6a4308ec 100644 --- a/examples/ParRes/functor/nstream.py +++ b/examples/ParRes/functor/nstream.py @@ -96,4 +96,4 @@ def run() -> None: print("Avg time (ms): %f" % (avgtime/1.e-3)) if __name__ == "__main__": - run() \ No newline at end of file + run() diff --git a/examples/ParRes/standalone/nstream.py b/examples/ParRes/standalone/nstream.py index ce934e61..dac421c2 100644 --- a/examples/ParRes/standalone/nstream.py +++ b/examples/ParRes/standalone/nstream.py @@ -83,4 +83,4 @@ def run() -> None: print("Avg time (ms): %f" % (avgtime/1.e-3)) if __name__ == "__main__": - run() \ No newline at end of file + run() diff --git a/examples/kokkos/README.md b/examples/kokkos/README.md index 91e619c4..87545332 100644 --- a/examples/kokkos/README.md +++ b/examples/kokkos/README.md @@ -1,2 +1,2 @@ This directory contains examples translated from the main Kokkos repository: -https://github.com/kokkos/kokkos/tree/develop/example/tutorial \ No newline at end of file +https://github.com/kokkos/kokkos/tree/develop/example/tutorial diff --git a/examples/pykokkos/README.md b/examples/pykokkos/README.md index 97d01445..2ba32994 100644 --- a/examples/pykokkos/README.md +++ b/examples/pykokkos/README.md @@ -1,2 +1,2 @@ This directory contains examples of how certain features -are implemented in PyKokkos. \ No newline at end of file +are implemented in PyKokkos. diff --git a/examples/pykokkos/team_thread_mdrange.py b/examples/pykokkos/team_thread_mdrange.py index 6fcde2c4..3912782e 100644 --- a/examples/pykokkos/team_thread_mdrange.py +++ b/examples/pykokkos/team_thread_mdrange.py @@ -32,4 +32,4 @@ def run(): print(A) if __name__ == "__main__": - run() \ No newline at end of file + run() diff --git a/pykokkos/core/fusion/access_modes.py b/pykokkos/core/fusion/access_modes.py index 1b392e77..aea53aad 100644 --- a/pykokkos/core/fusion/access_modes.py +++ b/pykokkos/core/fusion/access_modes.py @@ -214,4 +214,4 @@ def get_view_write_indices_and_modes(AST: ast.FunctionDef, view_args: Dict[str, visitor.visit(AST) access_indices: Dict[Tuple[str, int], Tuple[AccessIndex, AccessMode, str]] = visitor.access_indices - return access_indices \ No newline at end of file + return access_indices diff --git a/pykokkos/core/fusion/util.py b/pykokkos/core/fusion/util.py index d372e5fb..c3d0228e 100644 --- a/pykokkos/core/fusion/util.py +++ b/pykokkos/core/fusion/util.py @@ -76,4 +76,4 @@ def add_parent_refs(classdef: ast.ClassDef) -> ast.ClassDef: grand_child.parent_accessor = field_name grand_child.idx_in_parent = idx - return classdef \ No newline at end of file + return classdef diff --git a/pykokkos/core/module_setup.py b/pykokkos/core/module_setup.py index 7b8025bc..8063ff0f 100644 --- a/pykokkos/core/module_setup.py +++ b/pykokkos/core/module_setup.py @@ -224,4 +224,4 @@ def is_compiled(self) -> bool: Check if this module is compiled for its execution space """ - return CppSetup.is_compiled(self.get_output_dir(self.main, self.metadata, self.space, self.types_signature, self.restrict_signature)) \ No newline at end of file + return CppSetup.is_compiled(self.get_output_dir(self.main, self.metadata, self.space, self.types_signature, self.restrict_signature)) diff --git a/pykokkos/core/parsers/parser.py b/pykokkos/core/parsers/parser.py index cb42937c..457657d1 100644 --- a/pykokkos/core/parsers/parser.py +++ b/pykokkos/core/parsers/parser.py @@ -459,4 +459,4 @@ def is_workunit(node: ast.stmt, pk_import: str) -> bool: if (attribute.value.id == pk_import and Decorator.is_work_unit(attribute.attr)): return True - return False \ No newline at end of file + return False diff --git a/pykokkos/core/template_Makefile b/pykokkos/core/template_Makefile index 52e44f81..8ef0234b 100644 --- a/pykokkos/core/template_Makefile +++ b/pykokkos/core/template_Makefile @@ -41,4 +41,4 @@ run: $(TARGET) clean: rm *.o - rm $(TARGET) \ No newline at end of file + rm $(TARGET) diff --git a/pykokkos/core/translators/members.py b/pykokkos/core/translators/members.py index 0561ba80..95df540a 100644 --- a/pykokkos/core/translators/members.py +++ b/pykokkos/core/translators/members.py @@ -290,4 +290,4 @@ def get_random_pool(self, classdef: ast.ClassDef, source: Tuple[List[str], int], declref = n decltype = t - return declref, decltype \ No newline at end of file + return declref, decltype diff --git a/pykokkos/core/translators/symbols_pass.py b/pykokkos/core/translators/symbols_pass.py index be7acd5f..d8b997af 100644 --- a/pykokkos/core/translators/symbols_pass.py +++ b/pykokkos/core/translators/symbols_pass.py @@ -181,4 +181,4 @@ def get_error_messages(self, nodes: Dict[ast.AST, ErrorStatus]) -> List[str]: message: str = f"File \"{self.path}\", line {node.lineno}:\n {error.value} symbol {symbol} used" messages.append(message) - return messages \ No newline at end of file + return messages diff --git a/pykokkos/core/type_inference/args_type_inference.py b/pykokkos/core/type_inference/args_type_inference.py index 4e99ef03..96fcfb6c 100644 --- a/pykokkos/core/type_inference/args_type_inference.py +++ b/pykokkos/core/type_inference/args_type_inference.py @@ -495,4 +495,4 @@ def restore_original_args(workunit_str: str, tree: ast.AST) -> ast.AST: # first call, store the original params ORIGINAL_PARAMS[workunit_str] = pickle.dumps(tree.args.args) - return tree \ No newline at end of file + return tree diff --git a/pykokkos/interface/atomic/atomic_fetch_op.py b/pykokkos/interface/atomic/atomic_fetch_op.py index f82ea973..e42e2752 100644 --- a/pykokkos/interface/atomic/atomic_fetch_op.py +++ b/pykokkos/interface/atomic/atomic_fetch_op.py @@ -110,4 +110,4 @@ def atomic_compare_exchange( indices: List[int], comparison_value: int, new_value: int) -> int: - pass \ No newline at end of file + pass diff --git a/pykokkos/interface/execution_policy.py b/pykokkos/interface/execution_policy.py index 0220c933..b7207c2a 100644 --- a/pykokkos/interface/execution_policy.py +++ b/pykokkos/interface/execution_policy.py @@ -199,4 +199,4 @@ def __init__(self, team_member: TeamMember, count: int): class TeamThreadMDRange(ExecutionPolicy): def __init__(self, *args) -> None: - pass \ No newline at end of file + pass diff --git a/pykokkos/interface/execution_space.py b/pykokkos/interface/execution_space.py index f664be35..a601ed08 100644 --- a/pykokkos/interface/execution_space.py +++ b/pykokkos/interface/execution_space.py @@ -56,4 +56,4 @@ def __init__(self, space: ExecutionSpace, stream = None): self.instance = instance_constructor(stream.ptr, False) else: - self.instance = instance_constructor() \ No newline at end of file + self.instance = instance_constructor() diff --git a/pykokkos/interface/layout.py b/pykokkos/interface/layout.py index 4642fd47..f21524ba 100644 --- a/pykokkos/interface/layout.py +++ b/pykokkos/interface/layout.py @@ -23,4 +23,4 @@ def get_default_layout(space: MemorySpace) -> Layout: if space is MemorySpace.HostSpace: return Layout.LayoutRight else: - return Layout.LayoutLeft \ No newline at end of file + return Layout.LayoutLeft diff --git a/pykokkos/interface/mathematical_special_functions.py b/pykokkos/interface/mathematical_special_functions.py index b67be1e8..67aa891a 100644 --- a/pykokkos/interface/mathematical_special_functions.py +++ b/pykokkos/interface/mathematical_special_functions.py @@ -3,4 +3,4 @@ def cyl_bessel_j0(input: float) -> float: pass def cyl_bessel_j1(input: float) -> float: - pass \ No newline at end of file + pass diff --git a/pykokkos/interface/parallel_dispatch.py b/pykokkos/interface/parallel_dispatch.py index 7fc44293..3a3b3488 100644 --- a/pykokkos/interface/parallel_dispatch.py +++ b/pykokkos/interface/parallel_dispatch.py @@ -254,4 +254,4 @@ def execute(space: ExecutionSpace, workload: object) -> None: def flush(): - runtime_singleton.runtime.flush_trace() \ No newline at end of file + runtime_singleton.runtime.flush_trace() diff --git a/pykokkos/interface/random.py b/pykokkos/interface/random.py index 94046da7..d7407c8e 100644 --- a/pykokkos/interface/random.py +++ b/pykokkos/interface/random.py @@ -19,4 +19,4 @@ def rand(dtype: type): :param dtype: the data type of the number to be generated """ - pass \ No newline at end of file + pass diff --git a/pykokkos/lib/manipulate.py b/pykokkos/lib/manipulate.py index c21a2d57..b980806d 100644 --- a/pykokkos/lib/manipulate.py +++ b/pykokkos/lib/manipulate.py @@ -78,4 +78,4 @@ def expand_dims(view, axis=0): out = pk.View([view.shape[0], 1, view.shape[1]], pk.double) pk.parallel_for(view.shape[0], expand_dims_1_impl_2d_double, view=view, out=out) - return out \ No newline at end of file + return out diff --git a/tests.sh b/tests.sh index d72d58a3..5bdb7063 100755 --- a/tests.sh +++ b/tests.sh @@ -4,4 +4,4 @@ readonly RC_FILE="${_DIR}"/.coveragerc coverage run --rcfile="${RC_FILE}" -m unittest discover -s "${TESTS_DIR}" coverage report -coverage xml -o cov.xml \ No newline at end of file +coverage xml -o cov.xml diff --git a/tests/loop_fusion_kernels.py b/tests/loop_fusion_kernels.py index 2688b941..b377479d 100644 --- a/tests/loop_fusion_kernels.py +++ b/tests/loop_fusion_kernels.py @@ -178,4 +178,4 @@ def main(): if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/tests/test_parallelfor.py b/tests/test_parallelfor.py index 72a7094d..ad50d771 100644 --- a/tests/test_parallelfor.py +++ b/tests/test_parallelfor.py @@ -41,4 +41,4 @@ # self.assertEqual(result, expected_result) # if __name__ == '__main__': -# unittest.main() \ No newline at end of file +# unittest.main()