wrapper.rst 2.68 KB
Newer Older
randyh62's avatar
randyh62 committed
1
2
3
4
5
6
7
.. meta::
  :description: Composable Kernel documentation and API reference library
  :keywords: composable kernel, CK, ROCm, API, documentation

.. _wrapper:

********************************************************************
8
Wrapper
randyh62's avatar
randyh62 committed
9
********************************************************************
10
11
12
13
14
15
16
17
18
19

-------------------------------------
Description
-------------------------------------

.. note::

    The wrapper is under development and its functionality is limited.


randyh62's avatar
randyh62 committed
20
The CK library provides a lightweight wrapper for more complex operations implemented in 
randyh62's avatar
randyh62 committed
21
22
the library. It allows indexing of nested layouts using a simple interface 
(avoiding complex descriptor transformations) and memory access (using Tensor).
23
24
25
26
27
28
29
30

Example:

.. code-block:: c

    const auto shape_4x2x4         = ck::make_tuple(4, ck::make_tuple(2, 4));
    const auto strides_s2x1x8      = ck::make_tuple(2, ck::make_tuple(1, 8));
    const auto layout = ck::wrapper::make_layout(shape_4x2x4, strides_s2x1x8);
31
32
33
    
    std::array<ck::index_t, 32> data;
    auto tensor = ck::wrapper::make_tensor<ck::wrapper::MemoryTypeEnum::Generic>(&data[0], layout);
34

35
36
37
38
39
40
41
42
    for(ck::index_t w = 0; w < size(tensor); w++) {
        tensor(w) = w;
    }

    // slice() == slice(0, -1) (whole dimension)
    auto tensor_slice = tensor(ck::wrapper::slice(1, 3), ck::make_tuple(ck::wrapper::slice(), ck::wrapper::slice()));
    std::cout << "dims:2,(2,4) strides:2,(1,8)" << std::endl;
    for(ck::index_t h = 0; h < ck::wrapper::size<0>(tensor_slice); h++)
43
    {
44
        for(ck::index_t w = 0; w < ck::wrapper::size<1>(tensor_slice); w++)
45
        {
46
            std::cout << tensor_slice(h, w) << " ";
47
48
49
50
51
52
        }
        std::cout << std::endl;
    }

Output::

53
54
55
    dims:2,(2,4) strides:2,(1,8)
    1 5 9 13 17 21 25 29 
    2 6 10 14 18 22 26 30 
56

57
58
59
60
61

Advanced examples:

* `Image to column <https://github.com/ROCm/composable_kernel/blob/develop/client_example/25_wrapper/wrapper_img2col.cpp>`_

62
63
64
65
-------------------------------------
Layout
-------------------------------------

66
.. doxygenstruct:: Layout
67
68
69
70
71

-------------------------------------
Layout helpers
-------------------------------------

72
.. doxygenfile:: include/ck/wrapper/utils/layout_utils.hpp
73
74
75
76
77

-------------------------------------
Tensor
-------------------------------------

78
.. doxygenstruct:: Tensor
79
80
81
82
83

-------------------------------------
Tensor helpers
-------------------------------------

84
.. doxygenfile:: include/ck/wrapper/utils/tensor_utils.hpp
85

86
.. doxygenfile:: include/ck/wrapper/utils/tensor_partition.hpp
87
88
89
90
91

-------------------------------------
Operations
-------------------------------------

92
93
.. doxygenfile:: include/ck/wrapper/operations/copy.hpp
.. doxygenfile:: include/ck/wrapper/operations/gemm.hpp