Skip to content

Commit

Permalink
handle non-contiguous input (#8665)
Browse files Browse the repository at this point in the history
* handle non-contiguous input

* refine

* auto format by CI

Co-authored-by: oneflow-ci-bot <ci-bot@oneflow.org>
  • Loading branch information
Flowingsun007 and oneflow-ci-bot authored Jul 18, 2022
1 parent 52ab1ee commit 4d9dac4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion oneflow/ir/include/OneFlow/OneFlowUserOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -8405,7 +8405,7 @@ def OneFlow_BernoulliOp : OneFlow_BaseOp<"bernoulli", [NoSideEffect, NoGrad, Cpu
let has_data_type_infer_fn = 1;
}

def OneFlow_CastOp : OneFlow_BaseOp<"cast", [NoSideEffect, SupportNonContiguous, DeclareOpInterfaceMethods<UserOpCompatibleInterface>]> {
def OneFlow_CastOp : OneFlow_BaseOp<"cast", [NoSideEffect, DeclareOpInterfaceMethods<UserOpCompatibleInterface>]> {
let input = (ins
OneFlow_Tensor:$in
);
Expand Down
3 changes: 2 additions & 1 deletion python/oneflow/test/modules/test_cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def _test_cast_with_non_contiguous_input(test_case, device, shape):
output = flow.cast(input, flow.float32)
np_out = np_arr.astype(np.float32).transpose(permute_dims)
test_case.assertTrue(np.array_equal(output.numpy(), np_out))
test_case.assertTrue(input.stride() == output.stride())
# TODO:when cast kernel support stride
# test_case.assertTrue(input.stride() == output.stride())


def _test_cast_backward(test_case, device, shape):
Expand Down
11 changes: 11 additions & 0 deletions python/oneflow/test/modules/test_tensor_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from collections import OrderedDict

import numpy as np
from random import shuffle
from oneflow.test_utils.test_util import GenArgList

import oneflow as flow
Expand Down Expand Up @@ -154,6 +155,16 @@ def test_long_0dim(test_case):
y = x.long()
return y

@autotest(n=5, auto_backward=False)
def test_long_with_non_contiguous_input(test_case):
device = random_device()
permute_list = list(range(4))
shuffle(permute_list)
input = random_tensor(ndim=4).to(device)
x = input.permute(permute_list)
y = x.long()
return y

@autotest(n=20, auto_backward=False, rtol=1e-4, atol=1e-4, check_graph=True)
def test_int(test_case):
device = random_device()
Expand Down

0 comments on commit 4d9dac4

Please sign in to comment.