Skip to content
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

ENH: Data management update to support SUA ifaces for Homogen OneDAL tables #2045

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 12 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
48 changes: 32 additions & 16 deletions onedal/datatypes/_data_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,55 @@
from daal4py.sklearn._utils import make2d
from onedal import _backend, _is_dpc_backend

from .._device_offload import dpctl_available, dpnp_available
from ..utils import _is_csr

try:
import dpctl
if dpctl_available:
import dpctl.tensor as dpt

dpctl_available = dpctl.__version__ >= "0.14"
except ImportError:
dpctl_available = False
if dpnp_available:
import dpnp


def _apply_and_pass(func, *args):
def _apply_and_pass(func, *args, **kwargs):
if len(args) == 1:
return func(args[0])
return tuple(map(func, args))
return func(args[0], **kwargs)
return tuple(map(func, args, kwargs))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the logic is broken. Should be fixed



def from_table(*args):
return _apply_and_pass(_backend.from_table, *args)
def from_table(*args, sua_iface=None, xp=None):
return _apply_and_pass(convert_one_from_table, *args, sua_iface=sua_iface, xp=xp)


def convert_one_to_table(arg):
if dpctl_available:
if isinstance(arg, dpt.usm_ndarray):
return _backend.dpctl_to_table(arg)
# TODO:
# add warnings if no dpc backend.
# TODO:
# sparse for sua data.
# TODO:
# update it for each of the datafrmae format.
def convert_one_from_table(table, sua_iface=None, xp=None):
# Currently only `__sycl_usm_array_interface__` protocol used to
# convert into dpnp/dpctl tensors.
if sua_iface:
return xp.asarray(table)
return _backend.from_table(table)


# TODO:
# add warnings if no dpc backend.
# TODO:
# sparse for sua data.
def convert_one_to_table(arg, sua_iface=None):
if sua_iface and _is_dpc_backend:
return _backend.sua_iface_to_table(arg)

if not _is_csr(arg):
arg = make2d(arg)
return _backend.to_table(arg)


def to_table(*args):
return _apply_and_pass(convert_one_to_table, *args)
def to_table(*args, sua_iface=None):
return _apply_and_pass(convert_one_to_table, *args, sua_iface=sua_iface)


if _is_dpc_backend:
Expand Down
41 changes: 41 additions & 0 deletions onedal/datatypes/common.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*******************************************************************************
* Copyright 2024 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/

#include <cstdint>

namespace oneapi::dal::python {

union endian_checker {
std::uint64_t blob;
std::uint8_t arr[8];
};

bool is_little_endian_impl() {
constexpr std::uint64_t one = 0xfful;
constexpr endian_checker checker{ one };
return static_cast<bool>(checker.arr[0]);
}

bool is_little_endian() {
static const bool value = is_little_endian_impl();
return value;
}

bool is_big_endian() {
return !is_little_endian();
}

} // namespace oneapi::dal
39 changes: 39 additions & 0 deletions onedal/datatypes/common.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*******************************************************************************
* Copyright 2024 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/

#pragma once

#include <unordered_map>

namespace oneapi::dal::python {

template <typename Key, typename Value>
inline auto inverse_map(const std::unordered_map<Key, Value>& input)
-> std::unordered_map<Value, Key> {
const auto b_count = input.bucket_count();
std::unordered_map<Value, Key> output(b_count);

for (const auto& [key, value] : input) {
output.emplace(value, key);
}

return output;
}

bool is_big_endian();
bool is_little_endian();

} // namespace oneapi::dal
225 changes: 0 additions & 225 deletions onedal/datatypes/data_conversion_dpctl.cpp

This file was deleted.

Loading
Loading