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

Try to run CI on windows #36

Closed
wants to merge 3 commits into from
Closed
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
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
include:
- os: ubuntu-20.04
- os: macos-11
- os: windows-2019
steps:
- uses: actions/checkout@v3

Expand Down
24 changes: 22 additions & 2 deletions mops/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,14 @@ check_cxx_compiler_flag("-Wunknown-pragmas" COMPILER_SUPPORTS_WPRAGMAS)
if (MOPS_OPENMP)
find_package(OpenMP)
if(OpenMP_CXX_FOUND)
message(STATUS "OpenMP is enabled")
target_link_libraries(mops PUBLIC OpenMP::OpenMP_CXX)
if (MSVC)
# MSVC only supports an old version of OpenMP, let's disable it
# until we change the code to work with this version
message(STATUS "OpenMP was found, but is disabled on MSVC")
else()
message(STATUS "OpenMP is enabled")
target_link_libraries(mops PUBLIC OpenMP::OpenMP_CXX)
endif()
else()
message(WARNING "Could not find OpenMP")
if(COMPILER_SUPPORTS_WPRAGMAS)
Expand All @@ -153,6 +159,20 @@ else()
endif()
endif()

check_cxx_source_compiles("struct s {int *restrict x;}; int main() {return 0;}" HAVE_RESTRICT)
check_cxx_source_compiles("struct s {int *__restrict__ x;}; int main() {return 0;}" HAVE___RESTRICT__)
check_cxx_source_compiles("struct s {int *__restrict x;}; int main() {return 0;}" HAVE___RESTRICT)

if (HAVE_RESTRICT)
target_compile_definitions(mops PUBLIC "MOPS_RESTRICT=restrict")
elseif (HAVE___RESTRICT__)
target_compile_definitions(mops PUBLIC "MOPS_RESTRICT=__restrict__")
elseif (HAVE___RESTRICT)
target_compile_definitions(mops PUBLIC "MOPS_RESTRICT=__restrict")
else()
target_compile_definitions(mops PUBLIC "MOPS_RESTRICT=")
endif()

if (MOPS_ARCH_NATIVE)
check_cxx_compiler_flag("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE)
# for some reason COMPILER_SUPPORTS_MARCH_NATIVE is true with Apple clang,
Expand Down
17 changes: 8 additions & 9 deletions mops/include/mops/tensor.h
Original file line number Diff line number Diff line change
@@ -1,50 +1,49 @@
#ifndef MOPS_TENSOR_H
#define MOPS_TENSOR_H

#include <stddef.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

struct mops_tensor_3d_f32_t {
float *__restrict__ data;
float *MOPS_RESTRICT data;
int64_t shape[3];
};

struct mops_tensor_3d_f64_t {
double *__restrict__ data;
double *MOPS_RESTRICT data;
int64_t shape[3];
};

struct mops_tensor_2d_f32_t {
float *__restrict__ data;
float *MOPS_RESTRICT data;
int64_t shape[2];
};

struct mops_tensor_2d_f64_t {
double *__restrict__ data;
double *MOPS_RESTRICT data;
int64_t shape[2];
};

struct mops_tensor_1d_f32_t {
float *__restrict__ data;
float *MOPS_RESTRICT data;
int64_t shape[1];
};

struct mops_tensor_1d_f64_t {
double *__restrict__ data;
double *MOPS_RESTRICT data;
int64_t shape[1];
};

struct mops_tensor_1d_i32_t {
int32_t *__restrict__ data;
int32_t *MOPS_RESTRICT data;
int64_t shape[1];
};

struct mops_tensor_2d_i32_t {
int32_t *__restrict__ data;
int32_t *MOPS_RESTRICT data;
int64_t shape[2];
};

Expand Down
2 changes: 1 addition & 1 deletion mops/include/mops/tensor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace mops {
template <typename scalar_t, size_t N_DIMS> struct Tensor {
/// Pointer to the first element of the tensor. The data must be
/// contiguous and in row-major order.
scalar_t *__restrict__ data;
scalar_t *MOPS_RESTRICT data;
/// Shape of the tensor
size_t shape[N_DIMS];
};
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ repository = "https://github.com/lab-cosmo/mops"
[build-system]
requires = [
"setuptools >=68",
"cmake <3.28", # this should be changed once cmake 3.28.1 is on PyPI
"cmake",
]
build-backend = "setuptools.build_meta"

[tool.setuptools]
zip-safe = false

[tool.setuptools.packages.find]
where = ["python/mops/src/"]
where = ["python/mops/src"]

### ======================================================================== ###
[tool.pytest.ini_options]
Expand Down
27 changes: 19 additions & 8 deletions scripts/check-format.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
#!/bin/bash

for file in $(find . -type f \( -name "*.c" -o -name "*.cpp" -o -name "*.h" -o -name "*.hpp" -o -name "*.cu" -o -name "*.cuh" \) \
-not -path "*/external/*" -not -path "*/build/*" -not -path "*/.tox/*"); do
clang-format -i "$file"
if git diff --quiet "$file"; then
echo "✅ $file is properly formatted."
else
echo "❌ $file is not properly formatted. Please run './scripts/format.sh' from the mops root directory"
exit 1
ALL_FILES=$(
find . -type f \( -name "*.c" -o -name "*.cpp" -o -name "*.h" -o -name "*.hpp" -o -name "*.cu" -o -name "*.cuh" \) \
-not -path "*/external/*" \
-not -path "*/build/*" \
-not -path "*/.tox/*" \
)

ERRORS=0
for file in $ALL_FILES; do
if ! clang-format --dry-run --Werror "$file"; then
((ERRORS = ERRORS + 1))
fi
done

if [[ $ERRORS == 0 ]]; then
echo "✅ all files are properly formatted"
else
echo "❌ there are $ERRORS files not not properly formatted."
echo "Please run './scripts/format.sh' from the mops root directory"
exit $ERRORS
fi
Loading