Skip to content

Commit 3092132

Browse files
authored
Fix slice size calculation (#189)
Also, reenable parfor tests on CI
1 parent 431e6ae commit 3092132

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

azure-pipelines.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ jobs:
126126
export OCL_ICD_FILENAMES=libintelocl.so
127127
export SYCL_DEVICE_FILTER=opencl:cpu
128128
export NUMBA_DISABLE_PERFORMANCE_WARNINGS=1
129+
export DPCOMP_ENABLE_PARFOR_TESTS=1
129130
pytest -n1 -vv --capture=tee-sys -rXF
130131
displayName: 'Tests'
131132

numba_dpcomp/numba_dpcomp/mlir/tests/test_numpy.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,6 +1140,19 @@ def py_func(a, i, j, k):
11401140
assert_equal(py_func(arr, 1, 2, 3), jit_func(arr, 1, 2, 3))
11411141

11421142

1143+
@pytest.mark.parametrize("count", [0, 1, 5, 7, 8, 16, 17, 32])
1144+
def test_slice3(count):
1145+
def py_func(A):
1146+
B = A[::3]
1147+
for i in range(len(B)):
1148+
B[i] = i
1149+
return B
1150+
1151+
arr = np.zeros(count)
1152+
jit_func = njit(py_func)
1153+
assert_equal(py_func(arr.copy()[::2]), jit_func(arr.copy()[::2]))
1154+
1155+
11431156
def test_multidim_slice():
11441157
def py_func(a, b):
11451158
return a[1, b, :]

numba_dpcomp/numba_dpcomp/mlir_compiler/lib/pipelines/plier_to_linalg.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,7 @@ computeIndices(mlir::OpBuilder &builder, mlir::Location loc, mlir::Value value,
627627
};
628628

629629
auto zero = builder.create<mlir::arith::ConstantIndexOp>(loc, 0);
630+
auto one = builder.create<mlir::arith::ConstantIndexOp>(loc, 1);
630631

631632
auto foldConst = [&](mlir::Value val) -> mlir::OpFoldResult {
632633
if (auto intVal = mlir::getConstantIntValue(val))
@@ -678,6 +679,13 @@ computeIndices(mlir::OpBuilder &builder, mlir::Location loc, mlir::Value value,
678679
auto end = handleNegativeVal(getItemOrConst(1));
679680
auto stride = getItemOrConst(2);
680681
auto size = builder.createOrFold<mlir::arith::SubIOp>(loc, end, offset);
682+
683+
auto constStride = mlir::getConstantIntValue(stride);
684+
if (!constStride || *constStride > 1 || *constStride < -1) {
685+
size = builder.createOrFold<mlir::arith::SubIOp>(loc, size, one);
686+
size = builder.createOrFold<mlir::arith::AddIOp>(loc, size, stride);
687+
size = builder.createOrFold<mlir::arith::DivUIOp>(loc, size, stride);
688+
}
681689
return {foldConst(offset), foldConst(size), stride, true};
682690
} else if (auto literal = valType.dyn_cast<plier::LiteralType>()) {
683691
auto offset = foldConst(handleNegativeVal(literal.getValue()));

0 commit comments

Comments
 (0)