|
|
|
@ -24,9 +24,9 @@ context.set_context(mode=context.GRAPH_MODE, device_target="GPU")
|
|
|
|
|
# all cases tested against dchip
|
|
|
|
|
|
|
|
|
|
class TestScatterAddNet(nn.Cell):
|
|
|
|
|
def __init__(self, inputx, indices, updates):
|
|
|
|
|
def __init__(self, lock, inputx, indices, updates):
|
|
|
|
|
super(TestScatterAddNet, self).__init__()
|
|
|
|
|
self.scatter_add = P.ScatterAdd()
|
|
|
|
|
self.scatter_add = P.ScatterAdd(use_locking=lock)
|
|
|
|
|
self.inputx = Parameter(inputx, name="inputx")
|
|
|
|
|
self.indices = Parameter(indices, name="indices")
|
|
|
|
|
self.updates = Parameter(updates, name="updates")
|
|
|
|
@ -36,7 +36,13 @@ class TestScatterAddNet(nn.Cell):
|
|
|
|
|
return out
|
|
|
|
|
|
|
|
|
|
def scatter_add_net(inputx, indices, updates):
|
|
|
|
|
net = TestScatterAddNet(inputx, indices, updates)
|
|
|
|
|
lock = True
|
|
|
|
|
net = TestScatterAddNet(lock, inputx, indices, updates)
|
|
|
|
|
return net()
|
|
|
|
|
|
|
|
|
|
def scatter_add_use_locking_false_net(inputx, indices, updates):
|
|
|
|
|
lock = False
|
|
|
|
|
net = TestScatterAddNet(lock, inputx, indices, updates)
|
|
|
|
|
return net()
|
|
|
|
|
|
|
|
|
|
@pytest.mark.level0
|
|
|
|
@ -51,6 +57,52 @@ def test_scatter_add_small_float32():
|
|
|
|
|
[12., 14., 16.]])
|
|
|
|
|
np.testing.assert_array_almost_equal(output.asnumpy(), expected)
|
|
|
|
|
|
|
|
|
|
@pytest.mark.level0
|
|
|
|
|
@pytest.mark.platform_x86_gpu_training
|
|
|
|
|
@pytest.mark.env_onecard
|
|
|
|
|
def test_scatter_add_large_shape_float32():
|
|
|
|
|
inputx = Tensor(np.ones((4, 2, 3, 4)).astype(np.float32))
|
|
|
|
|
indices = Tensor(np.array([[0, 2], [3, 1]]).astype(np.int32))
|
|
|
|
|
updates = Tensor(np.arange(96).reshape((2, 2, 2, 3, 4)).astype(np.float32))
|
|
|
|
|
output = scatter_add_net(inputx, indices, updates)
|
|
|
|
|
expected = np.array([[[[1., 2., 3., 4.],
|
|
|
|
|
[5., 6., 7., 8.],
|
|
|
|
|
[9., 10., 11., 12.]],
|
|
|
|
|
[[13., 14., 15., 16.],
|
|
|
|
|
[17., 18., 19., 20.],
|
|
|
|
|
[21., 22., 23., 24.]]],
|
|
|
|
|
[[[73., 74., 75., 76.],
|
|
|
|
|
[77., 78., 79., 80.],
|
|
|
|
|
[81., 82., 83., 84.]],
|
|
|
|
|
[[85., 86., 87., 88.],
|
|
|
|
|
[89., 90., 91., 92.],
|
|
|
|
|
[93., 94., 95., 96.]]],
|
|
|
|
|
[[[25., 26., 27., 28.],
|
|
|
|
|
[29., 30., 31., 32.],
|
|
|
|
|
[33., 34., 35., 36.]],
|
|
|
|
|
[[37., 38., 39., 40.],
|
|
|
|
|
[41., 42., 43., 44.],
|
|
|
|
|
[45., 46., 47., 48.]]],
|
|
|
|
|
[[[49., 50., 51., 52.],
|
|
|
|
|
[53., 54., 55., 56.],
|
|
|
|
|
[57., 58., 59., 60.]],
|
|
|
|
|
[[61., 62., 63., 64.],
|
|
|
|
|
[65., 66., 67., 68.],
|
|
|
|
|
[69., 70., 71., 72.]]]])
|
|
|
|
|
np.testing.assert_array_almost_equal(output.asnumpy(), expected)
|
|
|
|
|
|
|
|
|
|
@pytest.mark.level0
|
|
|
|
|
@pytest.mark.platform_x86_gpu_training
|
|
|
|
|
@pytest.mark.env_onecard
|
|
|
|
|
def test_scatter_add_small_float32_use_locking_false():
|
|
|
|
|
inputx = Tensor(np.zeros((2, 3)).astype(np.float32))
|
|
|
|
|
indices = Tensor(np.array([1, 0]).astype(np.int32))
|
|
|
|
|
updates = Tensor(np.arange(6).reshape((2, 3)).astype(np.float32))
|
|
|
|
|
output = scatter_add_use_locking_false_net(inputx, indices, updates)
|
|
|
|
|
expected = np.array([[3., 4., 5.],
|
|
|
|
|
[0., 1., 2.]])
|
|
|
|
|
np.testing.assert_array_almost_equal(output.asnumpy(), expected)
|
|
|
|
|
|
|
|
|
|
@pytest.mark.level0
|
|
|
|
|
@pytest.mark.platform_x86_gpu_training
|
|
|
|
|
@pytest.mark.env_onecard
|
|
|
|
@ -112,3 +164,35 @@ def test_scatter_add_disordered_float16():
|
|
|
|
|
[187., 188., 189., 190.],
|
|
|
|
|
[492., 496., 500., 504.]])
|
|
|
|
|
np.testing.assert_array_almost_equal(output.asnumpy(), expected)
|
|
|
|
|
|
|
|
|
|
@pytest.mark.level0
|
|
|
|
|
@pytest.mark.platform_x86_gpu_training
|
|
|
|
|
@pytest.mark.env_onecard
|
|
|
|
|
def test_scatter_add_large_int32():
|
|
|
|
|
inputx = Tensor(np.zeros((2, 3, 4)).astype(np.int32))
|
|
|
|
|
indices = Tensor(np.array([[0, 0], [1, 1]]).astype(np.int32))
|
|
|
|
|
updates = Tensor(np.arange(63, 111).reshape((2, 2, 3, 4)).astype(np.int32))
|
|
|
|
|
output = scatter_add_net(inputx, indices, updates)
|
|
|
|
|
expected = np.array([[[138., 140., 142., 144.],
|
|
|
|
|
[146., 148., 150., 152.],
|
|
|
|
|
[154., 156., 158., 160.]],
|
|
|
|
|
[[186., 188., 190., 192.],
|
|
|
|
|
[194., 196., 198., 200.],
|
|
|
|
|
[202., 204., 206., 208.]]]).astype(np.int32)
|
|
|
|
|
np.testing.assert_array_almost_equal(output.asnumpy(), expected)
|
|
|
|
|
|
|
|
|
|
@pytest.mark.level0
|
|
|
|
|
@pytest.mark.platform_x86_gpu_training
|
|
|
|
|
@pytest.mark.env_onecard
|
|
|
|
|
def test_scatter_add_disordered_int32():
|
|
|
|
|
inputx = Tensor(np.flip(np.arange(34, 46).reshape(3, 4).astype(np.int32)))
|
|
|
|
|
indices = Tensor(np.array([[[0, 1, 2],
|
|
|
|
|
[2, 1, 0]],
|
|
|
|
|
[[0, 0, 0],
|
|
|
|
|
[2, 2, 2]]]).astype(np.int32))
|
|
|
|
|
updates = Tensor(np.arange(63, 111).reshape((2, 2, 3, 4)).astype(np.int32))
|
|
|
|
|
output = scatter_add_net(inputx, indices, updates)
|
|
|
|
|
expected = np.array([[464., 468., 472., 476.],
|
|
|
|
|
[187., 188., 189., 190.],
|
|
|
|
|
[492., 496., 500., 504.]]).astype(np.int32)
|
|
|
|
|
np.testing.assert_array_almost_equal(output.asnumpy(), expected)
|
|
|
|
|