Skip to content

Commit f48d0e6

Browse files
committed
add second step in func_ptr API implementation
1 parent 9d2da8b commit f48d0e6

File tree

5 files changed

+44
-44
lines changed

5 files changed

+44
-44
lines changed

dpnp/backend/backend_iface.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
#pragma once
3939

40+
#include <cstdint>
4041
#include <vector>
4142

4243
#ifdef _WIN

dpnp/backend/backend_iface_fptr.hpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,10 @@
3737

3838
#pragma once
3939

40+
#include <cstdint>
4041
#include <vector>
4142

42-
#ifdef _WIN
43-
#define INP_DLLEXPORT __declspec(dllexport)
44-
#else
45-
#define INP_DLLEXPORT
46-
#endif
43+
#include <backend/backend_iface.hpp>
4744

4845
/**
4946
* @defgroup BACKEND_FUNC_PTR_API Backend C++ library runtime interface API

dpnp/backend/queue_sycl.cpp

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -112,40 +112,3 @@ void dpnp_queue_initialize_c(QueueOptions selector)
112112
{
113113
backend_sycl::backend_sycl_queue_init(selector);
114114
}
115-
116-
#include <cstring>
117-
/**
118-
* Experimental interface. DO NOT USE IT!
119-
*/
120-
void* get_backend_function_name(const char* func_name, const char* type_name)
121-
{
122-
/** Implement it in this way to allow easier play with it */
123-
const char* supported_func_name = "dpnp_dot";
124-
const char* supported_type1_name = "double";
125-
const char* supported_type2_name = "float";
126-
const char* supported_type3_name = "long";
127-
const char* supported_type4_name = "int";
128-
129-
/** of coerce it will be converted into std::map later */
130-
if (!strncmp(func_name, supported_func_name, strlen(supported_func_name)))
131-
{
132-
if (!strncmp(type_name, supported_type1_name, strlen(supported_type1_name)))
133-
{
134-
return reinterpret_cast<void*>(mkl_blas_dot_c<double>);
135-
}
136-
else if (!strncmp(type_name, supported_type2_name, strlen(supported_type2_name)))
137-
{
138-
return reinterpret_cast<void*>(mkl_blas_dot_c<float>);
139-
}
140-
else if (!strncmp(type_name, supported_type3_name, strlen(supported_type3_name)))
141-
{
142-
return reinterpret_cast<void*>(custom_blas_dot_c<long>);
143-
}
144-
else if (!strncmp(type_name, supported_type4_name, strlen(supported_type4_name)))
145-
{
146-
return reinterpret_cast<void*>(custom_blas_dot_c<int>);
147-
}
148-
}
149-
150-
throw std::runtime_error("Intel NumPy Error: Unsupported function call");
151-
}
Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,49 @@
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 of experimental interface.
28+
*
29+
* This example shows how to get a runtime pointer from DPNP C++ Backend library
30+
*
31+
* Possible compile line:
32+
* clang++ examples/example_experimental_iface.cpp -o example_experimental_iface -Idpnp -Idpnp/backend -Ldpnp -Wl,-rpath='$ORIGIN'/dpnp -ldpnp_backend_c
33+
*
34+
*/
35+
136
#include <iostream>
237

3-
#include "backend_iface.hpp"
38+
#include <backend/backend_iface_fptr.hpp>
439

540
int main(int, char**)
641
{
742
void* result = get_backend_function_name("dpnp_dot", "float");
8-
std::cout << "Result Dot() function pointer: " << result << std::endl;
43+
std::cout << "Result Dot() function pointer (by old interface): " << result << std::endl;
44+
45+
void* dpnp_fptr = get_dpnp_function_ptr(DPNPFuncName::DPNP_FN_DOT, DPNPFuncType::DPNP_FT_FLOAT);
46+
std::cout << "Result Dot() function pointer: " << dpnp_fptr << std::endl;
947

1048
return 0;
1149
}

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@
211211
["dpnp_backend_c",
212212
{
213213
"sources": [
214+
"dpnp/backend/backend_iface_fptr.cpp",
214215
"dpnp/backend/custom_kernels.cpp",
215216
"dpnp/backend/custom_kernels_elemwise.cpp",
216217
"dpnp/backend/custom_kernels_manipulation.cpp",

0 commit comments

Comments
 (0)