File: driver.py

package info (click to toggle)
gridtools 2.3.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 29,480 kB
  • sloc: cpp: 228,792; python: 17,561; javascript: 9,164; ansic: 4,101; sh: 850; makefile: 231; f90: 201
file content (70 lines) | stat: -rw-r--r-- 1,908 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
import os
import sys

sys.path.append(os.getcwd())

import numpy as np
import py_implementation as testee

HIP = True if len(sys.argv) > 1 and sys.argv[1] == "HIPCC-AMDGPU" else False

def test_3d():
    src = np.fromfunction(lambda i, j, k : i + j + k, (3, 4, 5), dtype=np.double)
    dst = np.zeros_like(src)
    testee.copy_from_3D(src, dst)
    assert np.all(dst == src)

def test_3d_with_unit_stride():
    src = np.fromfunction(lambda i, j, k : i + j + k, (3, 4, 5), dtype=np.double)
    dst = np.zeros_like(src)
    testee.copy_from_3D_with_unit_stride(src, dst)
    assert np.all(dst == src)

def test_1d():
    shape = (3, 4, 5)
    src = np.arange(shape[0], dtype=np.double)
    dst = np.zeros(shape, dtype=np.double)
    testee.copy_from_1D(src, dst)
    expected = np.fromfunction(lambda i, j, k : i, shape, dtype=np.double)
    assert np.all(dst == expected)

def test_scalar():
    dst = np.zeros((3, 4, 5), dtype=np.double)
    testee.copy_from_scalar(42., dst)
    assert np.all(dst == 42.)

def test_cuda_sid():
    class Mock:
        def __init__(self, **kwargs):
            self.kwargs = kwargs
        
        if not HIP:
            @property
            def __cuda_array_interface__(self):
                return self.kwargs
        else:
            @property
            def __hip_array_interface__(self):
                return self.kwargs

    mock = Mock(
        shape=(3, 4, 5),
        typestr="|f8",
        data=(0xDEADBEAF, True),
        version=2,
        strides=(8, 3 * 8, 3 * 4 * 8),
        descr=[("", "|f8")],
        mask=None)
    testee.check_cuda_sid(mock, 0xDEADBEAF, (1, 3, 3 * 4), (3, 4, 5))
    mock = Mock(
        shape=(3, 4, 5),
        typestr="|f8",
        data=(0xDEADBEAF, True),
        version=2)
    testee.check_cuda_sid(mock, 0xDEADBEAF, (4 * 5, 5, 1), (3, 4, 5))

test_3d()
test_3d_with_unit_stride()
test_1d()
test_scalar()
test_cuda_sid()