Skip to content

Commit 20e90e9

Browse files
Merge pull request #31 from IntelPython/fix-osx-build
Fix osx build
2 parents 68d9391 + a927d8b commit 20e90e9

File tree

8 files changed

+82
-18
lines changed

8 files changed

+82
-18
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Build mkl_random with clang
2+
on:
3+
pull_request:
4+
push:
5+
branches: [master]
6+
7+
jobs:
8+
generate-coverage:
9+
name: Generate coverage and push to Coveralls.io
10+
runs-on: ubuntu-latest
11+
12+
env:
13+
ONEAPI_ROOT: /opt/intel/oneapi
14+
15+
steps:
16+
- name: Cancel Previous Runs
17+
uses: styfle/[email protected]
18+
with:
19+
access_token: ${{ github.token }}
20+
21+
- name: Add Intel repository
22+
run: |
23+
wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB
24+
sudo apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB
25+
rm GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB
26+
sudo add-apt-repository "deb https://apt.repos.intel.com/oneapi all main"
27+
sudo apt-get update
28+
29+
- name: Install Intel OneAPI
30+
run: |
31+
sudo apt-get install intel-oneapi-compiler-dpcpp-cpp
32+
sudo apt-get install intel-oneapi-tbb
33+
sudo apt-get install intel-oneapi-mkl-devel
34+
35+
- name: Setup Python
36+
uses: actions/setup-python@v4
37+
with:
38+
python-version: '3.11'
39+
architecture: x64
40+
41+
- name: Checkout repo
42+
uses: actions/checkout@v3
43+
with:
44+
fetch-depth: 0
45+
46+
- name: Install mkl_random dependencies
47+
shell: bash -l {0}
48+
run: |
49+
pip install numpy cython setuptools pytest pytest-cov
50+
51+
- name: List oneAPI folder content
52+
shell: bash -l {0}
53+
run: ls /opt/intel/oneapi/compiler
54+
55+
- name: Build mkl_random
56+
shell: bash -l {0}
57+
run: |
58+
source /opt/intel/oneapi/setvars.sh
59+
echo $CMPLR_ROOT
60+
export CC=$CMPLR_ROOT/../latest/bin-llvm/clang
61+
export CXX=$CMPLR_ROOT/../latest/bin-llvm/clang++
62+
echo "CC = ${CC} CXX=${CXX}"
63+
ls -l ${CC} ${CXX}
64+
python setup.py develop
65+
66+
- name: Run mkl_random tests
67+
shell: bash -l {0}
68+
run: |
69+
source /opt/intel/oneapi/setvars.sh
70+
pytest -s -v --pyargs mkl_random

mkl_random/mklrand.pyx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,7 @@ cdef class RandomState:
12121212
self.set_state(state)
12131213

12141214
def __reduce__(self):
1215+
global __RandomState_ctor
12151216
return (__RandomState_ctor, (), self.get_state())
12161217

12171218
def leapfrog(self, int k, int nstreams):

mkl_random/src/mkl_distributions.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
#define DIST_PRAGMA_VECTOR _Pragma("vector")
4545
#define DIST_PRAGMA_NOVECTOR _Pragma("novector")
4646
#define DIST_ASSUME_ALIGNED(p, b) __assume_aligned((p), (b));
47+
#elif defined(__clang__)
48+
#define DIST_PRAGMA_VECTOR _Pragma("clang loop vectorize(enable)")
49+
#define DIST_PRAGMA_NOVECTOR _Pragma("clang loop vectorize(disable)")
50+
#define DIST_ASSUME_ALIGNED(p, b)
4751
#elif defined(__GNUG__)
4852
#define DIST_PRAGMA_VECTOR _Pragma("GCC ivdep")
4953
#define DIST_PRAGMA_NOVECTOR

mkl_random/src/randomkit.c renamed to mkl_random/src/randomkit.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
#define RK_DEV_RANDOM "/dev/random"
9191
#endif
9292

93-
char *irk_strerror[RK_ERR_MAX] =
93+
const char *irk_strerror[RK_ERR_MAX] =
9494
{
9595
"no error",
9696
"random device unvavailable"};
@@ -350,7 +350,7 @@ void irk_random_vec(irk_state *state, const int len, unsigned int *res)
350350
void irk_fill(void *buffer, size_t size, irk_state *state)
351351
{
352352
unsigned int r;
353-
unsigned char *buf = buffer;
353+
unsigned char *buf = reinterpret_cast<unsigned char *>(buffer);
354354
int err, len;
355355

356356
/* len = size / 4 */

mkl_random/src/randomkit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ typedef enum {
6363

6464

6565
/* error strings */
66-
extern char *irk_strerror[RK_ERR_MAX];
66+
extern const char *irk_strerror[RK_ERR_MAX];
6767

6868
/* Maximum generated random value */
6969
#define RK_MAX 0xFFFFFFFFUL

mkl_random/tests/test_random.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import numpy as np
3030
from unittest import TestCase
3131
from numpy.testing import (
32-
run_module_suite, assert_, assert_raises, assert_equal,
32+
assert_, assert_raises, assert_equal,
3333
assert_warns, suppress_warnings)
3434
import mkl_random as rnd
3535
from numpy.compat import asbytes
@@ -952,7 +952,3 @@ def test_multinomial(self):
952952
def gen_random(state, out):
953953
out[...] = state.multinomial(10, [1/6.]*6, size=10000)
954954
self.check_function(gen_random, sz=(10000,6))
955-
956-
957-
if __name__ == "__main__":
958-
run_module_suite()

mkl_random/tests/test_regression.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@
2525
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2626

2727
import sys
28-
from numpy.testing import (TestCase, run_module_suite, assert_,
29-
assert_array_equal, assert_raises, dec)
30-
import mkl
28+
from numpy.testing import (TestCase, assert_,
29+
assert_array_equal, assert_raises)
3130
import mkl_random as rnd
3231
from numpy.compat import long
3332
import numpy as np
@@ -117,8 +116,6 @@ def test_multivariate_normal_size_types(self):
117116
rnd.multivariate_normal([0], [[0]], size=np.int_(1))
118117
rnd.multivariate_normal([0], [[0]], size=np.int64(1))
119118

120-
# @dec.skipif(tuple(map(mkl.get_version().get, ['MajorVersion', 'UpdateVersion'])) == (2020,3),
121-
# msg="Intel(R) MKL 2020.3 produces NaN for these parameters")
122119
def test_beta_small_parameters(self):
123120
# Test that beta with small a and b parameters does not produce
124121
# NaNs due to roundoff errors causing 0 / 0, gh-5851
@@ -173,7 +170,3 @@ def test_shuffle_of_array_of_objects(self):
173170
def test_non_central_chi_squared_df_one(self):
174171
a = rnd.noncentral_chisquare(df = 1.0, nonc=2.3, size=10**4)
175172
assert(a.min() > 0.0)
176-
177-
178-
if __name__ == "__main__":
179-
run_module_suite()

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def extensions():
103103
[
104104
os.path.join("mkl_random", "mklrand.pyx"),
105105
os.path.join("mkl_random", "src", "mkl_distributions.cpp"),
106-
os.path.join("mkl_random", "src", "randomkit.c"),
106+
os.path.join("mkl_random", "src", "randomkit.cpp"),
107107
],
108108
depends = [
109109
os.path.join("mkl_random", "src", "mkl_distributions.hpp"),

0 commit comments

Comments
 (0)