Skip to content

Commit 16b854c

Browse files
Fix linalg compilation, update compiler and fix rng for stock (#19)
* Fix linalg compilation error * Replace icc with icx compiler * Fix icx compile macro * Fix icx compile error for constexpr * Remove -std=c++11 compile option for linalg * revert back -std=c++11 and change icx with icpx for linalg * Print samples size and Python implementation * Add arg for rng.py to choose RNG implementation * Change args names for rng.py * Switch to 2022.1 icx version * Fix LDFLAGS for umath * Replace COMMON-AVX512 with CORE-AVx512 in native impl
1 parent e6f28e5 commit 16b854c

File tree

7 files changed

+41
-20
lines changed

7 files changed

+41
-20
lines changed

numpy/linalg/Makefile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
#
33
# SPDX-License-Identifier: MIT
44

5-
CXX = icc
6-
CXXFLAGS = -O3 -g -xCORE-AVX2 -axCOMMON-AVX512 \
7-
-qopt-report=5 -qopt-report-phase=openmp,par,vec
5+
CXX = icpx
6+
CXXFLAGS = -O3 -g -xSSE4.2 -axCORE-AVX2,CORE-AVX512 -qopt-report
87
LDFLAGS = -lmkl_rt
98

109
TARGET = linalg

numpy/linalg/bench.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ using namespace std;
1515
#include "assert.h"
1616
#include "stdlib.h"
1717

18-
#if defined(__INTEL_COMPILER)
18+
#if defined(__INTEL_LLVM_COMPILER)
1919

2020
#include "mkl.h"
2121

2222
class Random {
2323
private:
2424
enum { SEED = 77777 };
25-
static double const d_zero = 0.0, d_one = 1.0;
25+
static constexpr double const d_zero = 0.0, d_one = 1.0;
2626
VSLStreamStatePtr stream;
2727

2828
public:

numpy/linalg/linalg.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <getopt.h>
1919
#include <iostream>
2020
#include <map>
21+
#include <vector>
2122

2223
static const struct option longopts[] = {
2324
{"size", required_argument, nullptr, 'n'},

numpy/random/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
BENCHMARKS = rng
66
SOURCES = $(addsuffix .c,$(BENCHMARKS))
7-
CC = icc
7+
CC = icx
88
CLANG_FORMAT = clang-format
99
CFLAGS += -m64 -fPIC -fomit-frame-pointer -xSSE4.2 -axCORE-AVX2,CORE-AVX512 \
1010
-O3 -fp-model fast=2 -fimf-precision=high -prec-sqrt -prec-div \

numpy/random/rng.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ int main(void) {
187187
if (times[i] < min_time)
188188
min_time = times[i];
189189

190-
printf("Native-C,%s,%s,%.5f\n", brng_names[brng_idx],
190+
printf("Native-C,%d,%s,%s,%.5f\n", sz, brng_names[brng_idx],
191191
dist_names[fn_idx], min_time);
192192
}
193193
}

numpy/random/rng.py

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,8 @@
33
# SPDX-License-Identifier: MIT
44

55
import numpy as np
6-
try:
7-
import mkl_random as rnd
8-
mkl = True
9-
except (ImportError, ModuleNotFoundError):
10-
import numpy.random as rnd
11-
mkl = False
126
import timeit
7+
import sys
138

149
def sample_uniform(rs, sz):
1510
rs.uniform(-1, 1, size=sz)
@@ -46,31 +41,56 @@ def sample_hypergeom(rs, sz):
4641

4742
OUTER_REPS=6
4843
INNER_REPS=512
44+
SEED=123
4945

5046
def main():
5147
import itertools
48+
import argparse
49+
parser = argparse.ArgumentParser()
50+
parser.add_argument('--prefix', required=False, default="IntelPython", help="Print with each result")
51+
parser.add_argument('--impl', required=False, default="mkl_random", choices=['mkl_random', 'numpy'], help='RNG implementation\n'
52+
'choices:\n'
53+
'mkl_random: mkl_random.RandomState to be used\n'
54+
'numpy: numpy.Generator to be used')
55+
56+
args = parser.parse_args()
57+
58+
if args.impl == 'mkl_random':
59+
try:
60+
import mkl_random as rnd
61+
mkl = True
62+
except (ImportError, ModuleNotFoundError) as e:
63+
print(str(e))
64+
print('mkl_random is chosen for benchmark, however it is not found in current environemnt')
65+
sys.exit(1)
66+
else:
67+
import numpy.random as rnd
68+
mkl = False
69+
5270
if mkl:
5371
brngs = ['WH', 'PHILOX4X32X10', 'MT2203', 'MCG59', 'MCG31', 'MT19937', 'MRG32K3A', 'SFMT19937', 'R250']
5472
else:
5573
brngs = [np.random.MT19937, np.random.Philox]
74+
5675
samplers = {'uniform': sample_uniform, 'normal': sample_normal, 'gamma': sample_gamma, 'beta': sample_beta,
5776
'randint': sample_randint, 'poisson': sample_poisson, 'hypergeom': sample_hypergeom}
5877
multipliers = {'uniform': 10, 'normal': 2, 'gamma': 1, 'beta': 1, 'randint': 10, 'poisson': 5, 'hypergeom': 1}
78+
5979
for brng_name, sfn in itertools.product(brngs, samplers.keys()):
6080
func = samplers[sfn]
6181
m = multipliers[sfn]
6282
times_list = []
6383
for __ in range(OUTER_REPS):
6484
if mkl:
65-
rs = rnd.RandomState(123, brng=brng_name)
85+
rs = rnd.RandomState(SEED, brng=brng_name)
6686
else:
67-
rs = rnd.Generator(brng_name(seed=123))
87+
rs = rnd.Generator(brng_name(seed=SEED))
6888
t0 = timeit.default_timer()
6989
for __ in range(INNER_REPS):
7090
func(rs, (m*100, 1000))
7191
t1 = timeit.default_timer()
7292
times_list.append(t1-t0)
73-
print("IntelPython,{brng_name},{dist_name},{time:.5f}".format(brng_name=brng_name, dist_name=sfn, time=min(times_list)))
93+
print(f"{args.prefix},{m*100*1000},{brng_name if mkl else brng_name().__class__.__name__},{sfn},{min(times_list):.5f}")
7494

7595

7696
if __name__ == '__main__':

numpy/umath/Makefile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
#
33
# SPDX-License-Identifier: MIT
44

5-
CC = icc
6-
CFLAGS = -qopenmp -xCORE-AVX2 -axCOMMON-AVX512 -O3 \
7-
-g -lmkl_rt -Wall -pedantic
5+
CC = icx
6+
CFLAGS = -qopenmp -xSSE4.2 -axCORE-AVX2,CORE-AVX512 -O3 \
7+
-g -Wall -pedantic
8+
LDFLAGS += -lmkl_rt
89

910
ifneq ($(CONDA_PREFIX),)
1011
CFLAGS += -I$(CONDA_PREFIX)/include
@@ -36,7 +37,7 @@ compile: $(TARGET)
3637

3738

3839
$(TARGET): umath_bench.c
39-
$(CC) umath_bench.c $(CPPFLAGS) $(CFLAGS) -o $(TARGET)
40+
$(CC) umath_bench.c $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $(TARGET)
4041

4142
umath_bench.c: umath_bench.c.src
4243
$(PYTHON) -m numpy.distutils.conv_template umath_bench.c.src

0 commit comments

Comments
 (0)