Skip to content

Commit 68815e3

Browse files
authored
FPTR distributed init. step 1 (#134)
1 parent 8da099b commit 68815e3

File tree

3 files changed

+82
-38
lines changed

3 files changed

+82
-38
lines changed

dpnp/backend/backend_fptr.hpp

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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+
* This header file contains internal function declarations related to FPTR interface.
28+
* It should not contains public declarations
29+
*/
30+
31+
#pragma once
32+
#ifndef BACKEND_FPTR_H // Cython compatibility
33+
#define BACKEND_FPTR_H
34+
35+
#include <map>
36+
37+
#include <backend_iface_fptr.hpp>
38+
39+
40+
/**
41+
* Data storage type of the FPTR interface
42+
*
43+
* map[FunctionName][InputType2][InputType2]
44+
*
45+
* Function name is enum DPNPFuncName
46+
* InputTypes are presented as enum DPNPFuncType
47+
*
48+
* contains structure with kernel information
49+
*
50+
* if the kernel requires only one input type - use same type for both parameters
51+
*
52+
*/
53+
typedef std::map<DPNPFuncType, DPNPFuncData_t> map_2p_t;
54+
typedef std::map<DPNPFuncType, map_2p_t> map_1p_t;
55+
typedef std::map<DPNPFuncName, map_1p_t> func_map_t;
56+
57+
/**
58+
* Internal shortcuts for Data type enum values
59+
*/
60+
const DPNPFuncType eft_INT = DPNPFuncType::DPNP_FT_INT;
61+
const DPNPFuncType eft_LNG = DPNPFuncType::DPNP_FT_LONG;
62+
const DPNPFuncType eft_FLT = DPNPFuncType::DPNP_FT_FLOAT;
63+
const DPNPFuncType eft_DBL = DPNPFuncType::DPNP_FT_DOUBLE;
64+
65+
/**
66+
* FPTR interface initialization functions
67+
*/
68+
void func_map_init_manipulation(func_map_t &fmap);
69+
70+
#endif // BACKEND_FPTR_H

dpnp/backend/backend_iface_fptr.cpp

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,10 @@
3333
*/
3434

3535
#include <cstring>
36-
#include <map>
3736
#include <stdexcept>
3837

39-
#include <backend_iface_fptr.hpp>
38+
#include "backend_fptr.hpp"
4039

41-
typedef std::map<DPNPFuncType, DPNPFuncData_t> map_2p_t;
42-
typedef std::map<DPNPFuncType, map_2p_t> map_1p_t;
43-
typedef std::map<DPNPFuncName, map_1p_t> func_map_t;
4440

4541
static func_map_t func_map_init();
4642

@@ -137,12 +133,10 @@ void* get_dpnp_function_ptr1(DPNPFuncType& result_type,
137133

138134
static func_map_t func_map_init()
139135
{
140-
const DPNPFuncType eft_INT = DPNPFuncType::DPNP_FT_INT;
141-
const DPNPFuncType eft_LNG = DPNPFuncType::DPNP_FT_LONG;
142-
const DPNPFuncType eft_FLT = DPNPFuncType::DPNP_FT_FLOAT;
143-
const DPNPFuncType eft_DBL = DPNPFuncType::DPNP_FT_DOUBLE;
144136
func_map_t fmap;
145137

138+
func_map_init_manipulation(fmap);
139+
146140
fmap[DPNPFuncName::DPNP_FN_ABSOLUTE][eft_INT][eft_INT] = {eft_INT, (void*)custom_elemwise_absolute_c<int>};
147141
fmap[DPNPFuncName::DPNP_FN_ABSOLUTE][eft_LNG][eft_LNG] = {eft_LNG, (void*)custom_elemwise_absolute_c<long>};
148142
fmap[DPNPFuncName::DPNP_FN_ABSOLUTE][eft_FLT][eft_FLT] = {eft_FLT, (void*)custom_elemwise_absolute_c<float>};
@@ -663,11 +657,6 @@ static func_map_t func_map_init()
663657
fmap[DPNPFuncName::DPNP_FN_TANH][eft_FLT][eft_FLT] = {eft_FLT, (void*)custom_elemwise_tanh_c<float, float>};
664658
fmap[DPNPFuncName::DPNP_FN_TANH][eft_DBL][eft_DBL] = {eft_DBL, (void*)custom_elemwise_tanh_c<double, double>};
665659

666-
fmap[DPNPFuncName::DPNP_FN_TRANSPOSE][eft_INT][eft_INT] = {eft_INT, (void*)custom_elemwise_transpose_c<int>};
667-
fmap[DPNPFuncName::DPNP_FN_TRANSPOSE][eft_LNG][eft_LNG] = {eft_LNG, (void*)custom_elemwise_transpose_c<long>};
668-
fmap[DPNPFuncName::DPNP_FN_TRANSPOSE][eft_FLT][eft_FLT] = {eft_FLT, (void*)custom_elemwise_transpose_c<float>};
669-
fmap[DPNPFuncName::DPNP_FN_TRANSPOSE][eft_DBL][eft_DBL] = {eft_DBL, (void*)custom_elemwise_transpose_c<double>};
670-
671660
fmap[DPNPFuncName::DPNP_FN_TRUNC][eft_INT][eft_INT] = {eft_DBL, (void*)custom_elemwise_trunc_c<int, double>};
672661
fmap[DPNPFuncName::DPNP_FN_TRUNC][eft_LNG][eft_LNG] = {eft_DBL, (void*)custom_elemwise_trunc_c<long, double>};
673662
fmap[DPNPFuncName::DPNP_FN_TRUNC][eft_FLT][eft_FLT] = {eft_FLT, (void*)custom_elemwise_trunc_c<float, float>};

dpnp/backend/custom_kernels_manipulation.cpp

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#include <vector>
2929

3030
#include <backend_iface.hpp>
31+
32+
#include "backend_fptr.hpp"
3133
#include "backend_utils.hpp"
3234
#include "queue_sycl.hpp"
3335

@@ -102,27 +104,10 @@ void custom_elemwise_transpose_c(void* array1_in,
102104
free(result_offset_shape, DPNP_QUEUE);
103105
}
104106

105-
template void custom_elemwise_transpose_c<double>(void* array1_in,
106-
const std::vector<long>& input_shape,
107-
const std::vector<long>& result_shape,
108-
const std::vector<long>& permute_axes,
109-
void* result1,
110-
size_t size);
111-
template void custom_elemwise_transpose_c<float>(void* array1_in,
112-
const std::vector<long>& input_shape,
113-
const std::vector<long>& result_shape,
114-
const std::vector<long>& permute_axes,
115-
void* result1,
116-
size_t size);
117-
template void custom_elemwise_transpose_c<long>(void* array1_in,
118-
const std::vector<long>& input_shape,
119-
const std::vector<long>& result_shape,
120-
const std::vector<long>& permute_axes,
121-
void* result1,
122-
size_t size);
123-
template void custom_elemwise_transpose_c<int>(void* array1_in,
124-
const std::vector<long>& input_shape,
125-
const std::vector<long>& result_shape,
126-
const std::vector<long>& permute_axes,
127-
void* result1,
128-
size_t size);
107+
void func_map_init_manipulation(func_map_t &fmap)
108+
{
109+
fmap[DPNPFuncName::DPNP_FN_TRANSPOSE][eft_INT][eft_INT] = {eft_INT, (void*)custom_elemwise_transpose_c<int>};
110+
fmap[DPNPFuncName::DPNP_FN_TRANSPOSE][eft_LNG][eft_LNG] = {eft_LNG, (void*)custom_elemwise_transpose_c<long>};
111+
fmap[DPNPFuncName::DPNP_FN_TRANSPOSE][eft_FLT][eft_FLT] = {eft_FLT, (void*)custom_elemwise_transpose_c<float>};
112+
fmap[DPNPFuncName::DPNP_FN_TRANSPOSE][eft_DBL][eft_DBL] = {eft_DBL, (void*)custom_elemwise_transpose_c<double>};
113+
}

0 commit comments

Comments
 (0)