From e2484aea4fbf86a99ffef19438b5239a06b02dd1 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Thu, 14 Sep 2023 11:34:17 -0500 Subject: [PATCH 1/4] Fix build with clang --- mkl_random/src/mkl_distributions.cpp | 4 ++++ mkl_random/src/{randomkit.c => randomkit.cpp} | 4 ++-- mkl_random/src/randomkit.h | 2 +- setup.py | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) rename mkl_random/src/{randomkit.c => randomkit.cpp} (99%) diff --git a/mkl_random/src/mkl_distributions.cpp b/mkl_random/src/mkl_distributions.cpp index faceac1..c942207 100644 --- a/mkl_random/src/mkl_distributions.cpp +++ b/mkl_random/src/mkl_distributions.cpp @@ -44,6 +44,10 @@ #define DIST_PRAGMA_VECTOR _Pragma("vector") #define DIST_PRAGMA_NOVECTOR _Pragma("novector") #define DIST_ASSUME_ALIGNED(p, b) __assume_aligned((p), (b)); +#elif defined(__clang__) +#define DIST_PRAGMA_VECTOR _Pragma("clang loop vectorize(enable)") +#define DIST_PRAGMA_NOVECTOR _Pragma("clang loop vectorize(disable)") +#define DIST_ASSUME_ALIGNED(p, b) #elif defined(__GNUG__) #define DIST_PRAGMA_VECTOR _Pragma("GCC ivdep") #define DIST_PRAGMA_NOVECTOR diff --git a/mkl_random/src/randomkit.c b/mkl_random/src/randomkit.cpp similarity index 99% rename from mkl_random/src/randomkit.c rename to mkl_random/src/randomkit.cpp index f0a82f6..af19167 100644 --- a/mkl_random/src/randomkit.c +++ b/mkl_random/src/randomkit.cpp @@ -90,7 +90,7 @@ #define RK_DEV_RANDOM "/dev/random" #endif -char *irk_strerror[RK_ERR_MAX] = +const char *irk_strerror[RK_ERR_MAX] = { "no error", "random device unvavailable"}; @@ -350,7 +350,7 @@ void irk_random_vec(irk_state *state, const int len, unsigned int *res) void irk_fill(void *buffer, size_t size, irk_state *state) { unsigned int r; - unsigned char *buf = buffer; + unsigned char *buf = reinterpret_cast(buffer); int err, len; /* len = size / 4 */ diff --git a/mkl_random/src/randomkit.h b/mkl_random/src/randomkit.h index 6cdc5d9..485e596 100644 --- a/mkl_random/src/randomkit.h +++ b/mkl_random/src/randomkit.h @@ -63,7 +63,7 @@ typedef enum { /* error strings */ -extern char *irk_strerror[RK_ERR_MAX]; +extern const char *irk_strerror[RK_ERR_MAX]; /* Maximum generated random value */ #define RK_MAX 0xFFFFFFFFUL diff --git a/setup.py b/setup.py index ec5d1bb..e01a444 100644 --- a/setup.py +++ b/setup.py @@ -103,7 +103,7 @@ def extensions(): [ os.path.join("mkl_random", "mklrand.pyx"), os.path.join("mkl_random", "src", "mkl_distributions.cpp"), - os.path.join("mkl_random", "src", "randomkit.c"), + os.path.join("mkl_random", "src", "randomkit.cpp"), ], depends = [ os.path.join("mkl_random", "src", "mkl_distributions.hpp"), From 65b6392d814dec0345d30bcf2bdbcb90866735e2 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Thu, 14 Sep 2023 11:36:37 -0500 Subject: [PATCH 2/4] Added global declaration for __RandomState_ctor per warning --- mkl_random/mklrand.pyx | 1 + 1 file changed, 1 insertion(+) diff --git a/mkl_random/mklrand.pyx b/mkl_random/mklrand.pyx index 21cf208..809e296 100644 --- a/mkl_random/mklrand.pyx +++ b/mkl_random/mklrand.pyx @@ -1212,6 +1212,7 @@ cdef class RandomState: self.set_state(state) def __reduce__(self): + global __RandomState_ctor return (__RandomState_ctor, (), self.get_state()) def leapfrog(self, int k, int nstreams): From 57442a188778861620501e9b15f415807f0d38d3 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Thu, 14 Sep 2023 11:49:10 -0500 Subject: [PATCH 3/4] Updated tests to no use removed qualifiers --- mkl_random/tests/test_random.py | 6 +----- mkl_random/tests/test_regression.py | 11 ++--------- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/mkl_random/tests/test_random.py b/mkl_random/tests/test_random.py index 9766541..7315643 100644 --- a/mkl_random/tests/test_random.py +++ b/mkl_random/tests/test_random.py @@ -29,7 +29,7 @@ import numpy as np from unittest import TestCase from numpy.testing import ( - run_module_suite, assert_, assert_raises, assert_equal, + assert_, assert_raises, assert_equal, assert_warns, suppress_warnings) import mkl_random as rnd from numpy.compat import asbytes @@ -952,7 +952,3 @@ def test_multinomial(self): def gen_random(state, out): out[...] = state.multinomial(10, [1/6.]*6, size=10000) self.check_function(gen_random, sz=(10000,6)) - - -if __name__ == "__main__": - run_module_suite() diff --git a/mkl_random/tests/test_regression.py b/mkl_random/tests/test_regression.py index 45593b9..c994001 100644 --- a/mkl_random/tests/test_regression.py +++ b/mkl_random/tests/test_regression.py @@ -25,9 +25,8 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import sys -from numpy.testing import (TestCase, run_module_suite, assert_, - assert_array_equal, assert_raises, dec) -import mkl +from numpy.testing import (TestCase, assert_, + assert_array_equal, assert_raises) import mkl_random as rnd from numpy.compat import long import numpy as np @@ -117,8 +116,6 @@ def test_multivariate_normal_size_types(self): rnd.multivariate_normal([0], [[0]], size=np.int_(1)) rnd.multivariate_normal([0], [[0]], size=np.int64(1)) -# @dec.skipif(tuple(map(mkl.get_version().get, ['MajorVersion', 'UpdateVersion'])) == (2020,3), -# msg="Intel(R) MKL 2020.3 produces NaN for these parameters") def test_beta_small_parameters(self): # Test that beta with small a and b parameters does not produce # NaNs due to roundoff errors causing 0 / 0, gh-5851 @@ -173,7 +170,3 @@ def test_shuffle_of_array_of_objects(self): def test_non_central_chi_squared_df_one(self): a = rnd.noncentral_chisquare(df = 1.0, nonc=2.3, size=10**4) assert(a.min() > 0.0) - - -if __name__ == "__main__": - run_module_suite() From a927d8b8f57760f83a1dfdd92928351dc95c1bc1 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Thu, 14 Sep 2023 11:50:37 -0500 Subject: [PATCH 4/4] Added workflow to build dpctl with oneAPI's clang/clang++ --- .github/workflows/build-with-clang.yml | 70 ++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 .github/workflows/build-with-clang.yml diff --git a/.github/workflows/build-with-clang.yml b/.github/workflows/build-with-clang.yml new file mode 100644 index 0000000..be95089 --- /dev/null +++ b/.github/workflows/build-with-clang.yml @@ -0,0 +1,70 @@ +name: Build mkl_random with clang +on: + pull_request: + push: + branches: [master] + +jobs: + generate-coverage: + name: Generate coverage and push to Coveralls.io + runs-on: ubuntu-latest + + env: + ONEAPI_ROOT: /opt/intel/oneapi + + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.11.0 + with: + access_token: ${{ github.token }} + + - name: Add Intel repository + run: | + wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB + sudo apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB + rm GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB + sudo add-apt-repository "deb https://apt.repos.intel.com/oneapi all main" + sudo apt-get update + + - name: Install Intel OneAPI + run: | + sudo apt-get install intel-oneapi-compiler-dpcpp-cpp + sudo apt-get install intel-oneapi-tbb + sudo apt-get install intel-oneapi-mkl-devel + + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: '3.11' + architecture: x64 + + - name: Checkout repo + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Install mkl_random dependencies + shell: bash -l {0} + run: | + pip install numpy cython setuptools pytest pytest-cov + + - name: List oneAPI folder content + shell: bash -l {0} + run: ls /opt/intel/oneapi/compiler + + - name: Build mkl_random + shell: bash -l {0} + run: | + source /opt/intel/oneapi/setvars.sh + echo $CMPLR_ROOT + export CC=$CMPLR_ROOT/../latest/bin-llvm/clang + export CXX=$CMPLR_ROOT/../latest/bin-llvm/clang++ + echo "CC = ${CC} CXX=${CXX}" + ls -l ${CC} ${CXX} + python setup.py develop + + - name: Run mkl_random tests + shell: bash -l {0} + run: | + source /opt/intel/oneapi/setvars.sh + pytest -s -v --pyargs mkl_random