Skip to content

Get rid of env var which handles dep on dpctl.tensor #1205

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 3 commits into from
Oct 20, 2022
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
7 changes: 1 addition & 6 deletions dpnp/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# *****************************************************************************
# Copyright (c) 2016-2020, Intel Corporation
# Copyright (c) 2016-2022, Intel Corporation
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -43,11 +43,6 @@
Explicitly use NumPy.ndarray as return type for creation functions
'''

__DPNP_OUTPUT_DPCTL__ = int(os.getenv('DPNP_OUTPUT_DPCTL', 1))
'''
Explicitly use DPCtl package container as return type for creation functions
'''

__DPNP_OUTPUT_DPCTL_DEFAULT_SHARED__ = int(os.getenv('DPNP_OUTPUT_DPCTL_DEFAULT_SHARED', 0))
'''
Explicitly use SYCL shared memory parameter in DPCtl array constructor for creation functions
Expand Down
4 changes: 3 additions & 1 deletion dpnp/dpnp_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,9 @@ def astype(self, dtype, order='K', casting='unsafe', subok=True, copy=True):

"""

return dpnp.astype(self, dtype, order, casting, subok, copy)
new_array = self.__new__(dpnp_array)
new_array._array_obj = dpt.astype(self._array_obj, dtype, order=order, casting=casting, copy=copy)
return new_array

# 'base',
# 'byteswap',
Expand Down
25 changes: 12 additions & 13 deletions dpnp/dpnp_iface.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import dpctl
import dpctl.tensor as dpt

from dpnp.dpnp_array import dpnp_array
from dpnp.dpnp_algo import *
from dpnp.dpnp_utils import *
from dpnp.fft import *
Expand Down Expand Up @@ -137,26 +138,24 @@ def asnumpy(input, order='C'):
This function works exactly the same as :obj:`numpy.asarray`.

"""
if isinstance(input, dpnp_array):
return dpt.asnumpy(input.get_array())

if isinstance(input, dpctl.tensor.usm_ndarray):
return dpctl.tensor.to_numpy(input)

if config.__DPNP_OUTPUT_DPCTL__ and hasattr(input, "__sycl_usm_array_interface__"):
return dpctl.tensor.to_numpy(input.get_array())
if isinstance(input, dpt.usm_ndarray):
return dpt.asnumpy(input)

return numpy.asarray(input, order=order)


def astype(x1, dtype, order='K', casting='unsafe', subok=True, copy=True):
"""Copy the array with data type casting."""
if config.__DPNP_OUTPUT_DPCTL__ and hasattr(x1, "__sycl_usm_array_interface__"):
import dpctl.tensor as dpt
# TODO: remove check dpctl.tensor has attribute "astype"
if hasattr(dpt, "astype"):
# return dpt.astype(x1, dtype, order=order, casting=casting, copy=copy)
return dpt.astype(x1.get_array(), dtype, order=order, casting=casting, copy=copy)

x1_desc = get_dpnp_descriptor(x1)
if isinstance(x1, dpnp_array):
return x1.astype(dtype, order=order, casting=casting, copy=copy)

if isinstance(x1, dpt.usm_ndarray):
return dpt.astype(x1, dtype, order=order, casting=casting, copy=copy)

x1_desc = get_dpnp_descriptor(x1, copy_when_nondefault_queue=False)
if not x1_desc:
pass
elif order != 'K':
Expand Down
8 changes: 4 additions & 4 deletions dpnp/dpnp_utils/dpnp_algo_utils.pyx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# cython: language_level=3
# -*- coding: utf-8 -*-
# *****************************************************************************
# Copyright (c) 2016-2020, Intel Corporation
# Copyright (c) 2016-2022, Intel Corporation
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -100,10 +100,10 @@ def convert_list_args(input_list):

def copy_from_origin(dst, src):
"""Copy origin result to output result."""
if config.__DPNP_OUTPUT_DPCTL__ and hasattr(dst, "__sycl_usm_array_interface__"):
if hasattr(dst, "__sycl_usm_array_interface__"):
if src.size:
# dst.usm_data.copy_from_host(src.reshape(-1).view("|u1"))
dpctl.tensor._copy_utils._copy_from_numpy_into(unwrap_array(dst), src)
dst_dpt = unwrap_array(dst)
dst_dpt[...] = src
else:
for i in range(dst.size):
dst.flat[i] = src.item(i)
Expand Down