-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved inline functions into separate translation units
Instead of using inline keyword to allow multiple definitions of the same function in different translation units, introduced elementwise_functions_type_utils.cpp that defines these functions and a header file to use in other translatioon units. This should reduce the binary size of the produced object files and simplify the linker's job reducing the link-time.
- Loading branch information
1 parent
22b04e4
commit fa4924a
Showing
4 changed files
with
116 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
dpctl/tensor/libtensor/source/elementwise_functions/elementwise_functions_type_utils.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#include "dpctl4pybind11.hpp" | ||
#include <CL/sycl.hpp> | ||
#include <pybind11/numpy.h> | ||
#include <pybind11/pybind11.h> | ||
|
||
#include "elementwise_functions_type_utils.hpp" | ||
#include "utils/type_dispatch.hpp" | ||
|
||
namespace py = pybind11; | ||
namespace td_ns = dpctl::tensor::type_dispatch; | ||
|
||
namespace dpctl | ||
{ | ||
namespace tensor | ||
{ | ||
namespace py_internal | ||
{ | ||
namespace type_utils | ||
{ | ||
|
||
py::dtype _dtype_from_typenum(td_ns::typenum_t dst_typenum_t) | ||
{ | ||
switch (dst_typenum_t) { | ||
case td_ns::typenum_t::BOOL: | ||
return py::dtype("?"); | ||
case td_ns::typenum_t::INT8: | ||
return py::dtype("i1"); | ||
case td_ns::typenum_t::UINT8: | ||
return py::dtype("u1"); | ||
case td_ns::typenum_t::INT16: | ||
return py::dtype("i2"); | ||
case td_ns::typenum_t::UINT16: | ||
return py::dtype("u2"); | ||
case td_ns::typenum_t::INT32: | ||
return py::dtype("i4"); | ||
case td_ns::typenum_t::UINT32: | ||
return py::dtype("u4"); | ||
case td_ns::typenum_t::INT64: | ||
return py::dtype("i8"); | ||
case td_ns::typenum_t::UINT64: | ||
return py::dtype("u8"); | ||
case td_ns::typenum_t::HALF: | ||
return py::dtype("f2"); | ||
case td_ns::typenum_t::FLOAT: | ||
return py::dtype("f4"); | ||
case td_ns::typenum_t::DOUBLE: | ||
return py::dtype("f8"); | ||
case td_ns::typenum_t::CFLOAT: | ||
return py::dtype("c8"); | ||
case td_ns::typenum_t::CDOUBLE: | ||
return py::dtype("c16"); | ||
default: | ||
throw py::value_error("Unrecognized dst_typeid"); | ||
} | ||
} | ||
|
||
int _result_typeid(int arg_typeid, const int *fn_output_id) | ||
{ | ||
if (arg_typeid < 0 || arg_typeid >= td_ns::num_types) { | ||
throw py::value_error("Input typeid " + std::to_string(arg_typeid) + | ||
" is outside of expected bounds."); | ||
} | ||
|
||
return fn_output_id[arg_typeid]; | ||
} | ||
|
||
} // namespace type_utils | ||
} // namespace py_internal | ||
} // namespace tensor | ||
} // namespace dpctl |
33 changes: 33 additions & 0 deletions
33
dpctl/tensor/libtensor/source/elementwise_functions/elementwise_functions_type_utils.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#pragma once | ||
|
||
#pragma once | ||
#include "dpctl4pybind11.hpp" | ||
#include <CL/sycl.hpp> | ||
#include <pybind11/numpy.h> | ||
#include <pybind11/pybind11.h> | ||
|
||
#include "utils/type_dispatch.hpp" | ||
|
||
namespace py = pybind11; | ||
namespace td_ns = dpctl::tensor::type_dispatch; | ||
|
||
namespace dpctl | ||
{ | ||
namespace tensor | ||
{ | ||
namespace py_internal | ||
{ | ||
namespace type_utils | ||
{ | ||
|
||
/*! @brief Produce dtype from a type number */ | ||
extern py::dtype _dtype_from_typenum(td_ns::typenum_t); | ||
|
||
/*! @brief Lookup typeid of the result from typeid of | ||
* argument and the mapping table */ | ||
extern int _result_typeid(int, const int *); | ||
|
||
} // namespace type_utils | ||
} // namespace py_internal | ||
} // namespace tensor | ||
} // namespace dpctl |