Skip to content

Commit 72231d0

Browse files
Merge remote-tracking branch 'origin/master' into elementwise-floor-ceil-trunc
2 parents ea451ff + f032154 commit 72231d0

22 files changed

+2659
-52
lines changed

.github/workflows/generate-docs.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
- name: Install Intel OneAPI
2727
if: ${{ !github.event.pull_request || github.event.action != 'closed' }}
2828
run: |
29-
sudo apt-get install intel-oneapi-dpcpp-cpp-compiler
29+
sudo apt-get install intel-oneapi-compiler-dpcpp-cpp
3030
- name: Install Lua
3131
if: ${{ !github.event.pull_request || github.event.action != 'closed' }}
3232
run: |

.github/workflows/os-llvm-sycl-build.yml

+31-23
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ jobs:
1111

1212
env:
1313
DOWNLOAD_URL_PREFIX: https://github.com/intel/llvm/releases/download
14-
DRIVER_PATH: 2023-WW13
15-
OCLCPUEXP_FN: oclcpuexp-2023.15.3.0.20_rel.tar.gz
16-
FPGAEMU_FN: fpgaemu-2023.15.3.0.20_rel.tar.gz
14+
DRIVER_PATH: 2023-WW27
15+
OCLCPUEXP_FN: oclcpuexp-2023.16.6.0.28_rel.tar.gz
16+
FPGAEMU_FN: fpgaemu-2023.16.6.0.28_rel.tar.gz
1717
TBB_URL: https://github.com/oneapi-src/oneTBB/releases/download/v2021.9.0/
1818
TBB_INSTALL_DIR: oneapi-tbb-2021.9.0
1919
TBB_FN: oneapi-tbb-2021.9.0-lin.tgz
@@ -37,34 +37,42 @@ jobs:
3737
${{ runner.os }}-
3838
3939
- name: Download and install nightly and components
40+
env:
41+
USE_LATEST_SYCLOS: 0
4042
shell: bash -l {0}
4143
run: |
4244
cd /home/runner/work
4345
mkdir -p sycl_bundle
4446
cd sycl_bundle
45-
# get list of shas and tags from remote, filter sycl-nightly tags and reverse order
46-
export LLVM_TAGS=$(git -c 'versionsort.suffix=-' ls-remote --tags --sort='v:refname' https://github.com/intel/llvm.git | \
47-
grep sycl-nightly | awk '{a[i++]=$0} END {for (j=i-1; j>=0;) print a[j--] }')
48-
# initialize
49-
unset DEPLOY_NIGHTLY_TAG
50-
unset DEPLOY_NIGHTLY_TAG_SHA
51-
52-
# go through tags and find the most recent one where nighly build binary is available
53-
while IFS= read -r NEXT_LLVM_TAG; do
54-
export NEXT_LLVM_TAG_SHA=$(echo ${NEXT_LLVM_TAG} | awk '{print $1}')
55-
export NEXT_NIGHTLY_TAG=$(python3 -c "import sys, urllib.parse as ul; print (ul.quote_plus(sys.argv[1]))" \
56-
$(echo ${NEXT_LLVM_TAG} | awk '{gsub(/^refs\/tags\//, "", $2)} {print $2}'))
57-
if [[ `wget -S --spider ${DOWNLOAD_URL_PREFIX}/${NEXT_NIGHTLY_TAG}/dpcpp-compiler.tar.gz 2>&1 | grep 'HTTP/1.1 200 OK'` ]];
58-
then
59-
export DEPLOY_NIGHTLY_TAG=${NEXT_NIGHTLY_TAG}
60-
export DEPLOY_LLVM_TAG_SHA=${NEXT_LLVM_TAG_SHA}
61-
break
62-
fi
63-
done <<< "${LLVM_TAGS}"
47+
if [[ "${USE_LATEST_SYCLOS:-0}" -eq "1" ]]; then
48+
# get list of shas and tags from remote, filter sycl-nightly tags and reverse order
49+
export LLVM_TAGS=$(git -c 'versionsort.suffix=-' ls-remote --tags --sort='v:refname' https://github.com/intel/llvm.git | \
50+
grep sycl-nightly | awk '{a[i++]=$0} END {for (j=i-1; j>=0;) print a[j--] }')
51+
# initialize
52+
unset DEPLOY_NIGHTLY_TAG
53+
unset DEPLOY_NIGHTLY_TAG_SHA
54+
55+
# go through tags and find the most recent one where nighly build binary is available
56+
while IFS= read -r NEXT_LLVM_TAG; do
57+
export NEXT_LLVM_TAG_SHA=$(echo ${NEXT_LLVM_TAG} | awk '{print $1}')
58+
export NEXT_NIGHTLY_TAG=$(python3 -c "import sys, urllib.parse as ul; print (ul.quote_plus(sys.argv[1]))" \
59+
$(echo ${NEXT_LLVM_TAG} | awk '{gsub(/^refs\/tags\//, "", $2)} {print $2}'))
60+
if [[ `wget -S --spider ${DOWNLOAD_URL_PREFIX}/${NEXT_NIGHTLY_TAG}/dpcpp-compiler.tar.gz 2>&1 | grep 'HTTP/1.1 200 OK'` ]];
61+
then
62+
export DEPLOY_NIGHTLY_TAG=${NEXT_NIGHTLY_TAG}
63+
export DEPLOY_LLVM_TAG_SHA=${NEXT_LLVM_TAG_SHA}
64+
break
65+
fi
66+
done <<< "${LLVM_TAGS}"
67+
else
68+
# Use latest known to work tag instead
69+
export DEPLOY_NIGHTLY_TAG="sycl-nightly%2F20230606"
70+
export DEPLOY_LLVM_TAG_SHA=f44d0133d4b0077298f034697a1f3818ff1d6134
71+
fi
6472
6573
[[ -n "${DEPLOY_NIGHTLY_TAG}" ]] || exit 1
6674
[[ -n "${DEPLOY_LLVM_TAG_SHA}" ]] || exit 1
67-
echo "Using ${m} corresponding to intel/llvm at ${DEPLOY_LLVM_TAG_SHA}"
75+
echo "Using ${DEPLOY_NIGHTLY_TAG} corresponding to intel/llvm at ${DEPLOY_LLVM_TAG_SHA}"
6876
6977
if [[ -f bundle_id.txt && ( "$(cat bundle_id.txt)" == "${DEPLOY_LLVM_TAG_SHA}" ) ]]; then
7078
echo "Using cached download of ${DEPLOY_LLVM_TAG_SHA}"

dpctl/tensor/__init__.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,22 @@
113113
less_equal,
114114
log,
115115
log1p,
116+
log2,
117+
log10,
116118
logical_and,
117119
logical_not,
118120
logical_or,
119121
logical_xor,
120122
multiply,
123+
negative,
121124
not_equal,
125+
positive,
126+
pow,
122127
proj,
123128
real,
124129
sin,
125130
sqrt,
131+
square,
126132
subtract,
127133
trunc,
128134
)
@@ -217,9 +223,9 @@
217223
"greater",
218224
"greater_equal",
219225
"imag",
226+
"isfinite",
220227
"isinf",
221228
"isnan",
222-
"isfinite",
223229
"less",
224230
"less_equal",
225231
"log",
@@ -228,12 +234,18 @@
228234
"logical_or",
229235
"logical_xor",
230236
"log1p",
237+
"log2",
238+
"log10",
231239
"multiply",
240+
"negative",
232241
"not_equal",
242+
"positive",
243+
"pow",
233244
"proj",
234245
"real",
235246
"sin",
236247
"sqrt",
248+
"square",
237249
"subtract",
238250
"sum",
239251
"trunc",

dpctl/tensor/_elementwise_funcs.py

+132-6
Original file line numberDiff line numberDiff line change
@@ -609,10 +609,56 @@
609609
)
610610

611611
# U22: ==== LOG2 (x)
612-
# FIXME: implement U22
612+
_log2_docstring_ = """
613+
log2(x, out=None, order='K')
614+
615+
Computes the base-2 logarithm for each element `x_i` of input array `x`.
616+
617+
Args:
618+
x (usm_ndarray):
619+
Input array, expected to have numeric data type.
620+
out ({None, usm_ndarray}, optional):
621+
Output array to populate.
622+
Array have the correct shape and the expected data type.
623+
order ("C","F","A","K", optional):
624+
Memory layout of the newly output array, if parameter `out` is `None`.
625+
Default: "K".
626+
Returns:
627+
usm_narray:
628+
An array containing the base-2 logarithm of `x`.
629+
The data type of the returned array is determined by the
630+
Type Promotion Rules.
631+
"""
632+
633+
log2 = UnaryElementwiseFunc(
634+
"log2", ti._log2_result_type, ti._log2, _log2_docstring_
635+
)
613636

614637
# U23: ==== LOG10 (x)
615-
# FIXME: implement U23
638+
_log10_docstring_ = """
639+
log10(x, out=None, order='K')
640+
641+
Computes the base-10 logarithm for each element `x_i` of input array `x`.
642+
643+
Args:
644+
x (usm_ndarray):
645+
Input array, expected to have numeric data type.
646+
out ({None, usm_ndarray}, optional):
647+
Output array to populate.
648+
Array have the correct shape and the expected data type.
649+
order ("C","F","A","K", optional):
650+
Memory layout of the newly output array, if parameter `out` is `None`.
651+
Default: "K".
652+
Returns:
653+
usm_narray:
654+
An array containing the base-1- logarithm of `x`.
655+
The data type of the returned array is determined by the
656+
Type Promotion Rules.
657+
"""
658+
659+
log10 = UnaryElementwiseFunc(
660+
"log10", ti._log10_result_type, ti._log10, _log10_docstring_
661+
)
616662

617663
# B15: ==== LOGADDEXP (x1, x2)
618664
# FIXME: implement B15
@@ -761,7 +807,27 @@
761807
)
762808

763809
# U25: ==== NEGATIVE (x)
764-
# FIXME: implement U25
810+
_negative_docstring_ = """
811+
negative(x, out=None, order='K')
812+
813+
Computes the numerical negative for each element `x_i` of input array `x`.
814+
Args:
815+
x (usm_ndarray):
816+
Input array, expected to have numeric data type.
817+
out (usm_ndarray):
818+
Output array to populate. Array must have the correct
819+
shape and the expected data type.
820+
order ("C","F","A","K", optional): memory layout of the new
821+
output array, if parameter `out` is `None`.
822+
Default: "K".
823+
Return:
824+
usm_ndarray:
825+
An array containing the negative of `x`.
826+
"""
827+
828+
negative = UnaryElementwiseFunc(
829+
"negative", ti._negative_result_type, ti._negative, _negative_docstring_
830+
)
765831

766832
# B20: ==== NOT_EQUAL (x1, x2)
767833
_not_equal_docstring_ = """
@@ -793,10 +859,48 @@
793859
)
794860

795861
# U26: ==== POSITIVE (x)
796-
# FIXME: implement U26
862+
_positive_docstring_ = """
863+
positive(x, out=None, order='K')
864+
865+
Computes the numerical positive for each element `x_i` of input array `x`.
866+
Args:
867+
x (usm_ndarray):
868+
Input array, expected to have numeric data type.
869+
out (usm_ndarray):
870+
Output array to populate. Array must have the correct
871+
shape and the expected data type.
872+
order ("C","F","A","K", optional): memory layout of the new
873+
output array, if parameter `out` is `None`.
874+
Default: "K".
875+
Return:
876+
usm_ndarray:
877+
An array containing the values of `x`.
878+
"""
879+
880+
positive = UnaryElementwiseFunc(
881+
"positive", ti._positive_result_type, ti._positive, _positive_docstring_
882+
)
797883

798884
# B21: ==== POW (x1, x2)
799-
# FIXME: implement B21
885+
_pow_docstring_ = """
886+
pow(x1, x2, out=None, order='K')
887+
888+
Calculates `x1_i` raised to `x2_i` for each element `x1_i` of the input array
889+
`x1` with the respective element `x2_i` of the input array `x2`.
890+
891+
Args:
892+
x1 (usm_ndarray):
893+
First input array, expected to have a numeric data type.
894+
x2 (usm_ndarray):
895+
Second input array, also expected to have a numeric data type.
896+
Returns:
897+
usm_ndarray:
898+
an array containing the element-wise result. The data type of
899+
the returned array is determined by the Type Promotion Rules.
900+
"""
901+
pow = BinaryElementwiseFunc(
902+
"pow", ti._pow_result_type, ti._pow, _pow_docstring_
903+
)
800904

801905
# U??: ==== PROJ (x)
802906
_proj_docstring = """
@@ -884,7 +988,29 @@
884988
# FIXME: implement U31
885989

886990
# U32: ==== SQUARE (x)
887-
# FIXME: implement U32
991+
_square_docstring_ = """
992+
square(x, out=None, order='K')
993+
994+
Computes `x_i**2` (or `x_i*x_i`) for each element `x_i` of input array `x`.
995+
Args:
996+
x (usm_ndarray):
997+
Input array, expected to have numeric data type.
998+
out ({None, usm_ndarray}, optional):
999+
Output array to populate.
1000+
Array have the correct shape and the expected data type.
1001+
order ("C","F","A","K", optional):
1002+
Memory layout of the newly output array, if parameter `out` is `None`.
1003+
Default: "K".
1004+
Returns:
1005+
usm_ndarray:
1006+
An array containing the square `x`.
1007+
The data type of the returned array is determined by
1008+
the Type Promotion Rules.
1009+
"""
1010+
1011+
square = UnaryElementwiseFunc(
1012+
"square", ti._square_result_type, ti._square, _square_docstring_
1013+
)
8881014

8891015
# U33: ==== SQRT (x)
8901016
_sqrt_docstring_ = """

dpctl/tensor/_usmarray.pyx

+13-3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ cimport dpctl.memory as c_dpmem
3737
cimport dpctl.tensor._dlpack as c_dlpack
3838

3939
import dpctl.tensor._flags as _flags
40+
from dpctl.tensor._tensor_impl import default_device_fp_type
4041

4142
include "_stride_utils.pxi"
4243
include "_types.pxi"
@@ -104,7 +105,7 @@ cdef class InternalUSMArrayError(Exception):
104105

105106

106107
cdef class usm_ndarray:
107-
""" usm_ndarray(shape, dtype="|f8", strides=None, buffer="device", \
108+
""" usm_ndarray(shape, dtype=None, strides=None, buffer="device", \
108109
offset=0, order="C", buffer_ctor_kwargs=dict(), \
109110
array_namespace=None)
110111
@@ -116,6 +117,8 @@ cdef class usm_ndarray:
116117
Shape of the array to be created.
117118
dtype (str, dtype):
118119
Array data type, i.e. the type of array elements.
120+
If ``dtype`` has the value ``None``, it is determined by default
121+
floating point type supported by target device.
119122
The supported types are
120123
* ``bool``
121124
boolean type
@@ -134,7 +137,7 @@ cdef class usm_ndarray:
134137
double-precision real and complex floating
135138
types, supported if target device's property
136139
``has_aspect_fp64`` is ``True``.
137-
Default: ``"|f8"``.
140+
Default: ``None``.
138141
strides (tuple, optional):
139142
Strides of the array to be created in elements.
140143
If ``strides`` has the value ``None``, it is determined by the
@@ -219,7 +222,7 @@ cdef class usm_ndarray:
219222
"Data pointers of cloned and original objects are different.")
220223
return res
221224

222-
def __cinit__(self, shape, dtype="|f8", strides=None, buffer='device',
225+
def __cinit__(self, shape, dtype=None, strides=None, buffer='device',
223226
Py_ssize_t offset=0, order='C',
224227
buffer_ctor_kwargs=dict(),
225228
array_namespace=None):
@@ -252,6 +255,13 @@ cdef class usm_ndarray:
252255
except Exception:
253256
raise TypeError("Argument shape must be a list or a tuple.")
254257
nd = len(shape)
258+
if dtype is None:
259+
q = buffer_ctor_kwargs.get("queue")
260+
if q is not None:
261+
dtype = default_device_fp_type(q)
262+
else:
263+
dev = dpctl.select_default_device()
264+
dtype = "f8" if dev.has_aspect_fp64 else "f4"
255265
typenum = dtype_to_typenum(dtype)
256266
if (typenum < 0):
257267
if typenum == -2:

dpctl/tensor/libtensor/include/kernels/boolean_reductions.hpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,9 @@ struct SequentialBooleanReduction
198198
// must convert to boolean first to handle nans
199199
using dpctl::tensor::type_utils::convert_impl;
200200
outT val = convert_impl<bool, argT>(inp_[inp_offset]);
201+
ReductionOp op = reduction_op_;
201202

202-
red_val = reduction_op_(red_val, val);
203+
red_val = op(red_val, val);
203204
}
204205

205206
out_[out_iter_offset] = red_val;
@@ -452,9 +453,9 @@ struct StridedBooleanReduction
452453
// must convert to boolean first to handle nans
453454
using dpctl::tensor::type_utils::convert_impl;
454455
bool val = convert_impl<bool, argT>(inp_[inp_offset]);
456+
ReductionOp op = reduction_op_;
455457

456-
local_red_val =
457-
reduction_op_(local_red_val, static_cast<outT>(val));
458+
local_red_val = op(local_red_val, static_cast<outT>(val));
458459
}
459460
}
460461
// reduction and atomic operations are performed

0 commit comments

Comments
 (0)