Skip to content

Commit f959765

Browse files
authored
throw python constants to dpnpc (#925)
1 parent 3a43a96 commit f959765

File tree

6 files changed

+108
-0
lines changed

6 files changed

+108
-0
lines changed

dpnp/backend/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ set(DPNP_SRC
184184
kernels/dpnp_krnl_searching.cpp
185185
kernels/dpnp_krnl_sorting.cpp
186186
kernels/dpnp_krnl_statistics.cpp
187+
src/constants.cpp
187188
src/dpnp_iface_fptr.cpp
188189
src/memory_sycl.cpp
189190
src/queue_sycl.cpp

dpnp/backend/src/constants.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
#include <iostream>
27+
28+
#include "constants.hpp"
29+
30+
void* python_constants::py_none = nullptr;
31+
void* python_constants::py_nan = nullptr;
32+
33+
void dpnp_python_constants_initialize_c(void *_py_none, void *_py_nan)
34+
{
35+
python_constants::py_none = _py_none;
36+
python_constants::py_nan = _py_nan;
37+
// std::cout << "========dpnp_python_constants_initialize_c=============" << std::endl;
38+
// std::cout << "\t None=" << _py_none
39+
// << "\n\t NaN=" << _py_nan
40+
// << "\n\t py_none=" << python_constants::py_none
41+
// << "\n\t py_nan=" << python_constants::py_nan
42+
// << std::endl;
43+
}

dpnp/backend/src/constants.hpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
#pragma once
27+
#ifndef CONSTANTS_H // Cython compatibility
28+
#define CONSTANTS_H
29+
30+
#ifdef _WIN32
31+
#define INP_DLLEXPORT __declspec(dllexport)
32+
#else
33+
#define INP_DLLEXPORT
34+
#endif
35+
36+
37+
/**
38+
* This is container for the constants from Python interpreter and other modules. These constants are subject to use
39+
* in algorithms.
40+
*/
41+
struct python_constants
42+
{
43+
static void* py_none; /**< Python None */
44+
static void* py_nan; /**< Python NAN or NumPy.nan */
45+
};
46+
47+
/**
48+
* @ingroup BACKEND_API
49+
* @brief Python constants initialization in the backend.
50+
*
51+
* Global values from Python to use in algorithms.
52+
*
53+
* @param [in] py_none Python NONE representation
54+
* @param [in] py_nan Python NAN representation
55+
*/
56+
INP_DLLEXPORT void dpnp_python_constants_initialize_c(void *py_none, void *py_nan);
57+
58+
#endif // CONSTANTS_H

dpnp/dpnp_algo/dpnp_algo.pxd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ cdef extern from "dpnp_iface.hpp" namespace "QueueOptions": # need this namespa
218218
GPU_SELECTOR
219219
AUTO_SELECTOR
220220

221+
cdef extern from "constants.hpp":
222+
void dpnp_python_constants_initialize_c(void* py_none, void* py_nan)
223+
221224
cdef extern from "dpnp_iface.hpp":
222225
void dpnp_queue_initialize_c(QueueOptions selector)
223226
size_t dpnp_queue_is_cpu_c()

dpnp/dpnp_algo/dpnp_algo.pyx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ cpdef dpnp_queue_initialize():
188188
queue_type = GPU_SELECTOR
189189

190190
dpnp_queue_initialize_c(queue_type)
191+
dpnp_python_constants_initialize_c(<void*> None,
192+
<void*> dpnp.nan)
191193

192194
# TODO:
193195
# choose seed number as is in numpy

utils/command_build_clib.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@
178178
"dpnp/backend/kernels/dpnp_krnl_statistics.cpp",
179179
"dpnp/backend/src/dpnp_iface_fptr.cpp",
180180
"dpnp/backend/src/memory_sycl.cpp",
181+
"dpnp/backend/src/constants.cpp"
181182
"dpnp/backend/src/queue_sycl.cpp"
182183
],
183184
}

0 commit comments

Comments
 (0)