Skip to content

FPTR distributed init. step 1 #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions dpnp/backend/backend_fptr.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//*****************************************************************************
// Copyright (c) 2016-2020, Intel Corporation
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// - Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
// THE POSSIBILITY OF SUCH DAMAGE.
//*****************************************************************************

/*
* This header file contains internal function declarations related to FPTR interface.
* It should not contains public declarations
*/

#pragma once
#ifndef BACKEND_FPTR_H // Cython compatibility
#define BACKEND_FPTR_H

#include <map>

#include <backend_iface_fptr.hpp>


/**
* Data storage type of the FPTR interface
*
* map[FunctionName][InputType2][InputType2]
*
* Function name is enum DPNPFuncName
* InputTypes are presented as enum DPNPFuncType
*
* contains structure with kernel information
*
* if the kernel requires only one input type - use same type for both parameters
*
*/
typedef std::map<DPNPFuncType, DPNPFuncData_t> map_2p_t;
typedef std::map<DPNPFuncType, map_2p_t> map_1p_t;
typedef std::map<DPNPFuncName, map_1p_t> func_map_t;

/**
* Internal shortcuts for Data type enum values
*/
const DPNPFuncType eft_INT = DPNPFuncType::DPNP_FT_INT;
const DPNPFuncType eft_LNG = DPNPFuncType::DPNP_FT_LONG;
const DPNPFuncType eft_FLT = DPNPFuncType::DPNP_FT_FLOAT;
const DPNPFuncType eft_DBL = DPNPFuncType::DPNP_FT_DOUBLE;

/**
* FPTR interface initialization functions
*/
void func_map_init_manipulation(func_map_t &fmap);

#endif // BACKEND_FPTR_H
17 changes: 3 additions & 14 deletions dpnp/backend/backend_iface_fptr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,10 @@
*/

#include <cstring>
#include <map>
#include <stdexcept>

#include <backend_iface_fptr.hpp>
#include "backend_fptr.hpp"

typedef std::map<DPNPFuncType, DPNPFuncData_t> map_2p_t;
typedef std::map<DPNPFuncType, map_2p_t> map_1p_t;
typedef std::map<DPNPFuncName, map_1p_t> func_map_t;

static func_map_t func_map_init();

Expand Down Expand Up @@ -137,12 +133,10 @@ void* get_dpnp_function_ptr1(DPNPFuncType& result_type,

static func_map_t func_map_init()
{
const DPNPFuncType eft_INT = DPNPFuncType::DPNP_FT_INT;
const DPNPFuncType eft_LNG = DPNPFuncType::DPNP_FT_LONG;
const DPNPFuncType eft_FLT = DPNPFuncType::DPNP_FT_FLOAT;
const DPNPFuncType eft_DBL = DPNPFuncType::DPNP_FT_DOUBLE;
func_map_t fmap;

func_map_init_manipulation(fmap);

fmap[DPNPFuncName::DPNP_FN_ABSOLUTE][eft_INT][eft_INT] = {eft_INT, (void*)custom_elemwise_absolute_c<int>};
fmap[DPNPFuncName::DPNP_FN_ABSOLUTE][eft_LNG][eft_LNG] = {eft_LNG, (void*)custom_elemwise_absolute_c<long>};
fmap[DPNPFuncName::DPNP_FN_ABSOLUTE][eft_FLT][eft_FLT] = {eft_FLT, (void*)custom_elemwise_absolute_c<float>};
Expand Down Expand Up @@ -663,11 +657,6 @@ static func_map_t func_map_init()
fmap[DPNPFuncName::DPNP_FN_TANH][eft_FLT][eft_FLT] = {eft_FLT, (void*)custom_elemwise_tanh_c<float, float>};
fmap[DPNPFuncName::DPNP_FN_TANH][eft_DBL][eft_DBL] = {eft_DBL, (void*)custom_elemwise_tanh_c<double, double>};

fmap[DPNPFuncName::DPNP_FN_TRANSPOSE][eft_INT][eft_INT] = {eft_INT, (void*)custom_elemwise_transpose_c<int>};
fmap[DPNPFuncName::DPNP_FN_TRANSPOSE][eft_LNG][eft_LNG] = {eft_LNG, (void*)custom_elemwise_transpose_c<long>};
fmap[DPNPFuncName::DPNP_FN_TRANSPOSE][eft_FLT][eft_FLT] = {eft_FLT, (void*)custom_elemwise_transpose_c<float>};
fmap[DPNPFuncName::DPNP_FN_TRANSPOSE][eft_DBL][eft_DBL] = {eft_DBL, (void*)custom_elemwise_transpose_c<double>};

fmap[DPNPFuncName::DPNP_FN_TRUNC][eft_INT][eft_INT] = {eft_DBL, (void*)custom_elemwise_trunc_c<int, double>};
fmap[DPNPFuncName::DPNP_FN_TRUNC][eft_LNG][eft_LNG] = {eft_DBL, (void*)custom_elemwise_trunc_c<long, double>};
fmap[DPNPFuncName::DPNP_FN_TRUNC][eft_FLT][eft_FLT] = {eft_FLT, (void*)custom_elemwise_trunc_c<float, float>};
Expand Down
33 changes: 9 additions & 24 deletions dpnp/backend/custom_kernels_manipulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include <vector>

#include <backend_iface.hpp>

#include "backend_fptr.hpp"
#include "backend_utils.hpp"
#include "queue_sycl.hpp"

Expand Down Expand Up @@ -103,27 +105,10 @@ void custom_elemwise_transpose_c(void* array1_in,
free(result_offset_shape, DPNP_QUEUE);
}

template void custom_elemwise_transpose_c<double>(void* array1_in,
const std::vector<long>& input_shape,
const std::vector<long>& result_shape,
const std::vector<long>& permute_axes,
void* result1,
size_t size);
template void custom_elemwise_transpose_c<float>(void* array1_in,
const std::vector<long>& input_shape,
const std::vector<long>& result_shape,
const std::vector<long>& permute_axes,
void* result1,
size_t size);
template void custom_elemwise_transpose_c<long>(void* array1_in,
const std::vector<long>& input_shape,
const std::vector<long>& result_shape,
const std::vector<long>& permute_axes,
void* result1,
size_t size);
template void custom_elemwise_transpose_c<int>(void* array1_in,
const std::vector<long>& input_shape,
const std::vector<long>& result_shape,
const std::vector<long>& permute_axes,
void* result1,
size_t size);
void func_map_init_manipulation(func_map_t &fmap)
{
fmap[DPNPFuncName::DPNP_FN_TRANSPOSE][eft_INT][eft_INT] = {eft_INT, (void*)custom_elemwise_transpose_c<int>};
fmap[DPNPFuncName::DPNP_FN_TRANSPOSE][eft_LNG][eft_LNG] = {eft_LNG, (void*)custom_elemwise_transpose_c<long>};
fmap[DPNPFuncName::DPNP_FN_TRANSPOSE][eft_FLT][eft_FLT] = {eft_FLT, (void*)custom_elemwise_transpose_c<float>};
fmap[DPNPFuncName::DPNP_FN_TRANSPOSE][eft_DBL][eft_DBL] = {eft_DBL, (void*)custom_elemwise_transpose_c<double>};
}