Skip to content

Commit 7746682

Browse files
Merge pull request #586 from IntelPython/gold/2021-update-0-5-1
Gold/2021 update 0 5 1
2 parents 920a53d + 0e46c54 commit 7746682

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1243
-392
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ python -m unittest tests/test_mixins.py
3737

3838
## Run numpy external test
3939
```bash
40-
. ./0.env
40+
. ./0.env.sh
4141
python -m tests.third_party.numpy_ext
4242
# or
4343
python -m tests.third_party.numpy_ext core/tests/test_umath.py
@@ -57,7 +57,7 @@ Building:
5757

5858
## Packaging:
5959
```bash
60-
. ./0.env
60+
. ./0.env.sh
6161
conda-build conda-recipe/
6262
```
6363

doc/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
# The short X.Y version
3434
version = '0.5'
3535
# The full version, including alpha/beta/rc tags
36-
release = '0.5.0'
36+
release = '0.5.1'
3737

3838

3939
# -- General configuration ---------------------------------------------------

dpnp/backend/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
2929

30-
# set(DPNP_VERSION 0.5.0)
30+
# set(DPNP_VERSION 0.5.1)
3131
# set(DPNP_API_VERSION 0.5)
3232

3333
# set directory where the custom finders live
@@ -57,6 +57,7 @@ option(DPNP_BACKEND_TESTS "Enable DPNP tests" FALSE)
5757
message(STATUS "CMAKE_VERSION: ${CMAKE_VERSION}")
5858
message(STATUS "CMAKE_GENERATOR: ${CMAKE_GENERATOR}")
5959
message(STATUS "CMAKE_HOST_SYSTEM_NAME: ${CMAKE_HOST_SYSTEM_NAME}")
60+
message(STATUS "========== User controlled variables list ==========")
6061
message(STATUS "DPNP_ONEAPI_ROOT: ${DPNP_ONEAPI_ROOT}")
6162
message(STATUS "DPNP_STATIC_LIB_ENABLE: ${DPNP_STATIC_LIB_ENABLE}")
6263
message(STATUS "DPNP_DEBUG_ENABLE: ${DPNP_DEBUG_ENABLE}")
@@ -65,6 +66,7 @@ message(STATUS "DPNP_INSTALL_STRUCTURED: ${DPNP_INSTALL_STRUCTURED}")
6566
message(STATUS "DPNP_SYCL_QUEUE_MGR_ENABLE: ${DPNP_SYCL_QUEUE_MGR_ENABLE}")
6667
message(STATUS " |- DPNP_QUEUEMGR_INCLUDE_DIR: ${DPNP_QUEUEMGR_INCLUDE_DIR}")
6768
message(STATUS " |- DPNP_QUEUEMGR_LIB_DIR: ${DPNP_QUEUEMGR_LIB_DIR}")
69+
message(STATUS "======= End of user controlled variables list ======")
6870

6971
# -----------------------------------------------------------------------------------------------
7072
# Compiler-specific logic...
@@ -162,6 +164,7 @@ project(dpnp_project
162164
# Building logic...
163165
# -----------------------------------------------------------------------------------------------
164166
set(DPNP_SRC
167+
kernels/dpnp_krnl_arraycreation.cpp
165168
kernels/dpnp_krnl_bitwise.cpp
166169
kernels/dpnp_krnl_common.cpp
167170
kernels/dpnp_krnl_elemwise.cpp

dpnp/backend/doc/Doxyfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ PROJECT_NAME = "DPNP C++ backend kernel library"
3838
# could be handy for archiving the generated documentation or if some version
3939
# control system is used.
4040

41-
PROJECT_NUMBER = 0.5.0
41+
PROJECT_NUMBER = 0.5.1
4242

4343
# Using the PROJECT_BRIEF tag one can provide an optional one line description
4444
# for a project that appears at the top of each page and should give viewer a

dpnp/backend/examples/example3.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ int main(int, char**)
4242
{
4343
const size_t size = 256;
4444

45-
dpnp_queue_initialize_c(QueueOptions::CPU_SELECTOR);
45+
dpnp_queue_initialize_c();
4646
std::cout << "SYCL queue is CPU: " << dpnp_queue_is_cpu_c() << std::endl;
4747

4848
int* array1 = (int*)dpnp_memory_alloc_c(size * sizeof(int));

dpnp/backend/examples/example_bs.cpp

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
//*****************************************************************************
2+
// Copyright (c) 2016-2020, Intel Corporation
3+
// All rights reserved.
4+
//
5+
// Redistribution and use in source and binary forms, with or without
6+
// modification, are permitted provided that the following conditions are met:
7+
// - Redistributions of source code must retain the above copyright notice,
8+
// this list of conditions and the following disclaimer.
9+
// - Redistributions in binary form must reproduce the above copyright notice,
10+
// this list of conditions and the following disclaimer in the documentation
11+
// and/or other materials provided with the distribution.
12+
//
13+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
14+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16+
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
17+
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18+
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19+
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20+
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21+
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22+
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23+
// THE POSSIBILITY OF SUCH DAMAGE.
24+
//*****************************************************************************
25+
26+
/**
27+
* Example BS.
28+
*
29+
* This example shows simple usage of the DPNP C++ Backend library
30+
* to calculate black scholes algorithm like in Python version
31+
*
32+
* Possible compile line:
33+
* clang++ -g -fPIC dpnp/backend/examples/example_bs.cpp -Idpnp -Idpnp/backend/include -Ldpnp -Wl,-rpath='$ORIGIN'/dpnp -ldpnp_backend_c -o example_bs
34+
*
35+
*/
36+
37+
#include <iostream>
38+
#include <cmath>
39+
40+
#include "dpnp_iface.hpp"
41+
42+
double* black_scholes_put(double* S, double* K, double* T, double* sigmas, double* r_sigma_sigma_2,
43+
double* nrs, double* sqrt2, double* ones, double* twos, const size_t size)
44+
{
45+
double* d1 = (double*)dpnp_memory_alloc_c(size * sizeof(double));
46+
dpnp_divide_c<double, double, double>(S, K, d1, size); // S/K
47+
dpnp_log_c<double, double>(d1, d1, size); // np.log(S/K)
48+
49+
double* bs_put = (double*)dpnp_memory_alloc_c(size * sizeof(double));
50+
dpnp_multiply_c<double, double, double>(r_sigma_sigma_2, T, bs_put, size); // r_sigma_sigma_2*T
51+
dpnp_add_c<double, double, double>(d1, bs_put, d1, size); // np.log(S/K) + r_sigma_sigma_2*T
52+
53+
dpnp_sqrt_c<double, double>(T, bs_put, size); // np.sqrt(T)
54+
dpnp_multiply_c<double, double, double>(sigmas, bs_put, bs_put, size); // sigmas*np.sqrt(T)
55+
56+
// (np.log(S/K) + r_sigma_sigma_2*T) / (sigmas*np.sqrt(T))
57+
dpnp_divide_c<double, double, double>(d1, bs_put, d1, size);
58+
59+
double* d2 = (double*)dpnp_memory_alloc_c(size * sizeof(double));
60+
dpnp_sqrt_c<double, double>(T, bs_put, size); // np.sqrt(T)
61+
dpnp_multiply_c<double, double, double>(sigmas, bs_put, bs_put, size); // sigmas*np.sqrt(T)
62+
dpnp_subtract_c<double, double, double>(d1, bs_put, d2, size); // d1 - sigmas*np.sqrt(T)
63+
64+
double* cdf_d1 = (double*)dpnp_memory_alloc_c(size * sizeof(double));
65+
dpnp_divide_c<double, double, double>(d1, sqrt2, cdf_d1, size); // d1 / sqrt2
66+
dpnp_erf_c<double>(cdf_d1, cdf_d1, size); // np.erf(d1 / sqrt2)
67+
dpnp_add_c<double, double, double>(ones, cdf_d1, cdf_d1, size); // ones + np.erf(d1 / sqrt2)
68+
dpnp_add_c<double, double, double>(ones, cdf_d1, cdf_d1, size); // (ones + np.erf(d1 / sqrt2)) / twos
69+
dpnp_memory_free_c(d1);
70+
71+
double* cdf_d2 = (double*)dpnp_memory_alloc_c(size * sizeof(double));
72+
dpnp_divide_c<double, double, double>(d2, sqrt2, cdf_d2, size); // d2 / sqrt2
73+
dpnp_erf_c<double>(cdf_d2, cdf_d2, size); // np.erf(d2 / sqrt2)
74+
dpnp_add_c<double, double, double>(ones, cdf_d2, cdf_d2, size); // ones + np.erf(d2 / sqrt2)
75+
dpnp_add_c<double, double, double>(ones, cdf_d2, cdf_d2, size); // (ones + np.erf(d2 / sqrt2)) / twos
76+
dpnp_memory_free_c(d2);
77+
78+
double* bs_call = (double*)dpnp_memory_alloc_c(size * sizeof(double));
79+
dpnp_multiply_c<double, double, double>(S, cdf_d1, bs_call, size); // S*cdf_d1
80+
dpnp_memory_free_c(cdf_d1);
81+
82+
dpnp_multiply_c<double, double, double>(nrs, T, bs_put, size); // nrs*T
83+
dpnp_exp_c<double, double>(bs_put, bs_put, size); // np.exp(nrs*T)
84+
dpnp_multiply_c<double, double, double>(K, bs_put, bs_put, size); // K*np.exp(nrs*T)
85+
86+
// K*np.exp(nrs*T)*cdf_d2
87+
dpnp_multiply_c<double, double, double>(bs_put, cdf_d2, bs_put, size);
88+
dpnp_memory_free_c(cdf_d2);
89+
90+
// S*cdf_d1 - K*np.exp(nrs*T)*cdf_d2
91+
dpnp_subtract_c<double, double, double>(bs_call, bs_put, bs_call, size);
92+
93+
dpnp_multiply_c<double, double, double>(nrs, T, bs_put, size); // nrs*T
94+
dpnp_exp_c<double, double>(bs_put, bs_put, size); // np.exp(nrs*T)
95+
dpnp_multiply_c<double, double, double>(K, bs_put, bs_put, size); // K*np.exp(nrs*T)
96+
dpnp_subtract_c<double, double, double>(bs_put, S, bs_put, size); // K*np.exp(nrs*T) - S
97+
dpnp_add_c<double, double, double>(bs_put, bs_call, bs_put, size); // K*np.exp(nrs*T) - S + bs_call
98+
dpnp_memory_free_c(bs_call);
99+
100+
return bs_put;
101+
}
102+
103+
int main(int, char**)
104+
{
105+
const size_t SIZE = 256;
106+
107+
const size_t SEED = 7777777;
108+
const long SL = 10, SH = 50;
109+
const long KL = 10, KH = 50;
110+
const long TL = 1, TH = 2;
111+
const double RISK_FREE = 0.1;
112+
const double VOLATILITY = 0.2;
113+
114+
dpnp_queue_initialize_c(QueueOptions::GPU_SELECTOR);
115+
std::cout << "SYCL queue is CPU: " << dpnp_queue_is_cpu_c() << std::endl;
116+
117+
double* S = (double*)dpnp_memory_alloc_c(SIZE * sizeof(double));
118+
double* K = (double*)dpnp_memory_alloc_c(SIZE * sizeof(double));
119+
double* T = (double*)dpnp_memory_alloc_c(SIZE * sizeof(double));
120+
121+
dpnp_rng_srand_c(SEED);
122+
dpnp_rng_uniform_c<double>(S, SL, SH, SIZE); // np.random.uniform(SL, SH, SIZE)
123+
dpnp_rng_uniform_c<double>(K, KL, KH, SIZE); // np.random.uniform(KL, KH, SIZE)
124+
dpnp_rng_uniform_c<double>(T, TL, TH, SIZE); // np.random.uniform(TL, TH, SIZE)
125+
126+
double* r = (double*)dpnp_memory_alloc_c(1 * sizeof(double));
127+
r[0] = RISK_FREE;
128+
129+
double* sigma = (double*)dpnp_memory_alloc_c(1 * sizeof(double));
130+
sigma[0] = VOLATILITY;
131+
132+
double* rss2 = (double*)dpnp_memory_alloc_c(1 * sizeof(double));
133+
rss2[0] = RISK_FREE + VOLATILITY*VOLATILITY/2.;
134+
135+
double* nr = (double*)dpnp_memory_alloc_c(1 * sizeof(double));
136+
nr[0] = -RISK_FREE;
137+
138+
double* sq2 = (double*)dpnp_memory_alloc_c(1 * sizeof(double));
139+
sq2[0] = sqrt(2.);
140+
141+
double* one = (double*)dpnp_memory_alloc_c(1 * sizeof(double));
142+
one[0] = 1.;
143+
144+
double* two = (double*)dpnp_memory_alloc_c(1 * sizeof(double));
145+
two[0] = 2.;
146+
147+
double* sigmas = (double*)dpnp_memory_alloc_c(SIZE * sizeof(double));
148+
double* r_sigma_sigma_2 = (double*)dpnp_memory_alloc_c(SIZE * sizeof(double));
149+
double* nrs = (double*)dpnp_memory_alloc_c(SIZE * sizeof(double));
150+
double* sqrt2 = (double*)dpnp_memory_alloc_c(SIZE * sizeof(double));
151+
double* ones = (double*)dpnp_memory_alloc_c(SIZE * sizeof(double));
152+
double* twos = (double*)dpnp_memory_alloc_c(SIZE * sizeof(double));
153+
154+
dpnp_full_c<double>(sigma, sigmas, SIZE); // np.full((SIZE,), sigma, dtype=DTYPE)
155+
dpnp_full_c<double>(rss2, r_sigma_sigma_2, SIZE); // np.full((SIZE,), r + sigma*sigma/2., dtype=DTYPE)
156+
dpnp_full_c<double>(nr, nrs, SIZE); // np.full((SIZE,), -r, dtype=DTYPE)
157+
dpnp_full_c<double>(sq2, sqrt2, SIZE); // np.full((SIZE,), np.sqrt(2), dtype=DTYPE)
158+
dpnp_full_c<double>(one, ones, SIZE); // np.full((SIZE,), 1, dtype=DTYPE)
159+
dpnp_full_c<double>(two, twos, SIZE); // np.full((SIZE,), 2, dtype=DTYPE)
160+
161+
dpnp_memory_free_c(one);
162+
dpnp_memory_free_c(two);
163+
dpnp_memory_free_c(sq2);
164+
dpnp_memory_free_c(nr);
165+
dpnp_memory_free_c(rss2);
166+
dpnp_memory_free_c(sigma);
167+
dpnp_memory_free_c(r);
168+
169+
double* bs_put = black_scholes_put(S, K, T, sigmas, r_sigma_sigma_2, nrs, sqrt2, ones, twos, SIZE);
170+
171+
std::cout << std::endl;
172+
for (size_t i = 0; i < 10; ++i)
173+
{
174+
std::cout << bs_put[i] << ", ";
175+
}
176+
std::cout << std::endl;
177+
178+
dpnp_memory_free_c(bs_put);
179+
180+
dpnp_memory_free_c(twos);
181+
dpnp_memory_free_c(ones);
182+
dpnp_memory_free_c(sqrt2);
183+
dpnp_memory_free_c(nrs);
184+
dpnp_memory_free_c(r_sigma_sigma_2);
185+
dpnp_memory_free_c(sigmas);
186+
187+
dpnp_memory_free_c(T);
188+
dpnp_memory_free_c(K);
189+
dpnp_memory_free_c(S);
190+
191+
return 0;
192+
}

dpnp/backend/include/dpnp_iface.hpp

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@
6868
enum class QueueOptions : uint32_t
6969
{
7070
CPU_SELECTOR, /**< CPU side execution mode */
71-
GPU_SELECTOR /**< Intel GPU side execution mode */
71+
GPU_SELECTOR, /**< Intel GPU side execution mode */
72+
AUTO_SELECTOR /**< Automatic selection based on environment variable with @ref CPU_SELECTOR default */
7273
};
7374

7475
/**
@@ -77,9 +78,9 @@ enum class QueueOptions : uint32_t
7778
*
7879
* Global SYCL queue initialization.
7980
*
80-
* @param [in] selector Select type @ref QueueOptions of the SYCL queue.
81+
* @param [in] selector Select type @ref QueueOptions of the SYCL queue. Default @ref AUTO_SELECTOR
8182
*/
82-
INP_DLLEXPORT void dpnp_queue_initialize_c(QueueOptions selector);
83+
INP_DLLEXPORT void dpnp_queue_initialize_c(QueueOptions selector = QueueOptions::AUTO_SELECTOR);
8384

8485
/**
8586
* @ingroup BACKEND_API
@@ -118,6 +119,17 @@ void dpnp_memory_memcpy_c(void* dst, const void* src, size_t size_in_bytes);
118119
template <typename _DataType>
119120
INP_DLLEXPORT void dpnp_arange_c(size_t start, size_t step, void* result1, size_t size);
120121

122+
/**
123+
* @ingroup BACKEND_API
124+
* @brief Implementation of full function
125+
*
126+
* @param [in] array_in Input one-element array.
127+
* @param [out] result Output array.
128+
* @param [in] size Number of elements in the output array.
129+
*/
130+
template <typename _DataType>
131+
INP_DLLEXPORT void dpnp_full_c(void* array_in, void* result, const size_t size);
132+
121133
/**
122134
* @ingroup BACKEND_API
123135
* @brief Matrix multiplication.
@@ -169,6 +181,30 @@ INP_DLLEXPORT void dpnp_dot_c(void* array1, void* array2, void* result1, size_t
169181
template <typename _DataType_input1, typename _DataType_input2, typename _DataType_output>
170182
INP_DLLEXPORT void dpnp_cross_c(void* array1_in, void* array2_in, void* result1, size_t size);
171183

184+
/**
185+
* @ingroup BACKEND_API
186+
* @brief Custom implementation of cumprod function
187+
*
188+
* @param [in] array1_in Input array.
189+
* @param [out] result1 Output array.
190+
* @param [in] size Number of elements in input arrays.
191+
*
192+
*/
193+
template <typename _DataType_input, typename _DataType_output>
194+
INP_DLLEXPORT void dpnp_cumprod_c(void* array1_in, void* result1, size_t size);
195+
196+
/**
197+
* @ingroup BACKEND_API
198+
* @brief Custom implementation of cumsum function
199+
*
200+
* @param [in] array1_in Input array.
201+
* @param [out] result1 Output array.
202+
* @param [in] size Number of elements in input arrays.
203+
*
204+
*/
205+
template <typename _DataType_input, typename _DataType_output>
206+
INP_DLLEXPORT void dpnp_cumsum_c(void* array1_in, void* result1, size_t size);
207+
172208
/**
173209
* @ingroup BACKEND_API
174210
* @brief Sum of array elements
@@ -284,6 +320,17 @@ INP_DLLEXPORT void dpnp_cov_c(void* array1_in, void* result1, size_t nrows, size
284320
template <typename _DataType>
285321
INP_DLLEXPORT void dpnp_det_c(void* array1_in, void* result1, size_t* shape, size_t ndim);
286322

323+
/**
324+
* @ingroup BACKEND_API
325+
* @brief implementation of creating filled with value array function
326+
*
327+
* @param [out] result Output array.
328+
* @param [in] value Value in array.
329+
* @param [in] size Number of elements in array.
330+
*/
331+
template <typename _DataType>
332+
INP_DLLEXPORT void dpnp_initval_c(void* result1, void* value, size_t size);
333+
287334
/**
288335
* @ingroup BACKEND_API
289336
* @brief math library implementation of inv function
@@ -411,11 +458,11 @@ INP_DLLEXPORT void dpnp_std_c(
411458
* @brief math library implementation of take function
412459
*
413460
* @param [in] array Input array with data.
414-
* @param [in] array Input array with indices.
415-
* @param [out] result Output array with indeces.
461+
* @param [in] indices Input array with indices.
462+
* @param [out] result Output array.
416463
* @param [in] size Number of elements in the input array.
417464
*/
418-
template <typename _DataType>
465+
template <typename _DataType, typename _IndecesType>
419466
INP_DLLEXPORT void dpnp_take_c(void* array, void* indices, void* result, size_t size);
420467

421468
/**
@@ -513,14 +560,16 @@ INP_DLLEXPORT void dpnp_remainder_c(void* array1_in, void* array2_in, void* resu
513560
* @param [in] input_shape Input shape.
514561
* @param [in] result_shape Output shape.
515562
* @param [in] permute_axes Order of axis by it's id as it should be presented in output.
563+
* @param [in] ndim Number of elements in shapes and axes.
516564
* @param [out] result1 Output array.
517565
* @param [in] size Number of elements in input arrays.
518566
*/
519567
template <typename _DataType>
520568
INP_DLLEXPORT void dpnp_elemwise_transpose_c(void* array1_in,
521-
const std::vector<long>& input_shape,
522-
const std::vector<long>& result_shape,
523-
const std::vector<long>& permute_axes,
569+
const size_t* input_shape,
570+
const size_t* result_shape,
571+
const size_t* permute_axes,
572+
size_t ndim,
524573
void* result1,
525574
size_t size);
526575

0 commit comments

Comments
 (0)