Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
composable_kernel_ROCM
Commits
7d50244e
Unverified
Commit
7d50244e
authored
Oct 31, 2024
by
Illia Silin
Committed by
GitHub
Oct 31, 2024
Browse files
Merge pull request #209 from ROCm/andriy/merge_from_public
Update develop branch from public repository
parents
f221c2b0
d51701d4
Changes
291
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
3188 additions
and
211 deletions
+3188
-211
include/ck_tile/core/algorithm/indexing_adaptor.hpp
include/ck_tile/core/algorithm/indexing_adaptor.hpp
+60
-0
include/ck_tile/core/algorithm/space_filling_curve.hpp
include/ck_tile/core/algorithm/space_filling_curve.hpp
+7
-5
include/ck_tile/core/arch/amd_buffer_addressing.hpp
include/ck_tile/core/arch/amd_buffer_addressing.hpp
+195
-18
include/ck_tile/core/config.hpp
include/ck_tile/core/config.hpp
+18
-0
include/ck_tile/core/container/tuple.hpp
include/ck_tile/core/container/tuple.hpp
+29
-5
include/ck_tile/core/numeric/int8.hpp
include/ck_tile/core/numeric/int8.hpp
+104
-0
include/ck_tile/core/numeric/math.hpp
include/ck_tile/core/numeric/math.hpp
+930
-44
include/ck_tile/core/numeric/type_convert.hpp
include/ck_tile/core/numeric/type_convert.hpp
+4
-0
include/ck_tile/core/tensor/buffer_view.hpp
include/ck_tile/core/tensor/buffer_view.hpp
+121
-57
include/ck_tile/core/tensor/load_tile.hpp
include/ck_tile/core/tensor/load_tile.hpp
+83
-4
include/ck_tile/core/tensor/null_tile_window.hpp
include/ck_tile/core/tensor/null_tile_window.hpp
+7
-0
include/ck_tile/core/tensor/shuffle_tile.hpp
include/ck_tile/core/tensor/shuffle_tile.hpp
+1
-1
include/ck_tile/core/tensor/store_tile.hpp
include/ck_tile/core/tensor/store_tile.hpp
+29
-2
include/ck_tile/core/tensor/tensor_view.hpp
include/ck_tile/core/tensor/tensor_view.hpp
+192
-25
include/ck_tile/core/tensor/tile_window.hpp
include/ck_tile/core/tensor/tile_window.hpp
+182
-45
include/ck_tile/core/tensor/tile_window_linear.hpp
include/ck_tile/core/tensor/tile_window_linear.hpp
+1082
-0
include/ck_tile/core/utility/literals.hpp
include/ck_tile/core/utility/literals.hpp
+22
-0
include/ck_tile/core/utility/magic_div.hpp
include/ck_tile/core/utility/magic_div.hpp
+22
-5
include/ck_tile/core/utility/reduce_operator.hpp
include/ck_tile/core/utility/reduce_operator.hpp
+95
-0
include/ck_tile/host.hpp
include/ck_tile/host.hpp
+5
-0
No files found.
include/ck_tile/core/algorithm/indexing_adaptor.hpp
0 → 100644
View file @
7d50244e
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2024, Advanced Micro Devices, Inc. All rights reserved.
#pragma once
#include "ck_tile/core/config.hpp"
#include "ck_tile/core/container/multi_index.hpp"
#include "ck_tile/core/container/container_helper.hpp"
#include "ck_tile/core/utility/functional.hpp"
#include "ck_tile/core/utility/type_traits.hpp"
namespace
ck_tile
{
// pre-defined indexing adaptor used for indexing(scatter/gather)
// this version cache the index inside thread register(which is also prefered in real senario)
// however it's user's responsibility that each thread only provide one indexing, which means
// move coordinate will not change on this dim
template
<
typename
IndexingType
>
struct
indexing_adaptor_onshot_cached
{
CK_TILE_HOST_DEVICE
constexpr
indexing_adaptor_onshot_cached
()
=
default
;
CK_TILE_HOST_DEVICE
constexpr
indexing_adaptor_onshot_cached
(
const
IndexingType
&
idx
)
:
cached_idx_
(
idx
)
{
}
IndexingType
cached_idx_
;
template
<
typename
LowIdx
,
typename
UpIdx
>
CK_TILE_HOST_DEVICE
constexpr
void
calculate_lower_index
(
LowIdx
&
idx_low
,
const
UpIdx
&
/*idx_up*/
)
const
{
static_assert
(
LowIdx
::
size
()
==
1
&&
UpIdx
::
size
()
==
1
,
"wrong! inconsistent # of dimension"
);
idx_low
(
number
<
0
>
{})
=
cached_idx_
;
}
template
<
typename
LowIdxDiff
,
typename
UpIdxDiff
,
typename
LowIdx
,
typename
UpIdx
>
CK_TILE_HOST_DEVICE
void
update_lower_index
(
LowIdxDiff
&
idx_diff_low
,
const
UpIdxDiff
&
idx_diff_up
,
LowIdx
&
/*idx_low*/
,
const
UpIdx
&
/*idx_up*/
)
const
{
// TODO: nonthing changed here
static_assert
(
LowIdxDiff
::
size
()
==
1
&&
UpIdxDiff
::
size
()
==
1
&&
LowIdx
::
size
()
==
1
&&
UpIdx
::
size
()
==
1
,
"wrong! inconsistent # of dimension"
);
idx_diff_low
(
number
<
0
>
{})
=
idx_diff_up
[
number
<
0
>
{}];
// pass the diff to lower, but not changing the actually index
}
CK_TILE_HOST_DEVICE
static
constexpr
bool
is_known_at_compile_time
()
{
return
ck_tile
::
is_known_at_compile_time
<
IndexingType
>::
value
;
}
};
}
// namespace ck_tile
include/ck_tile/core/algorithm/space_filling_curve.hpp
View file @
7d50244e
// SPDX-License-Identifier: MIT
// Copyright (c) 20
18-2023
, Advanced Micro Devices, Inc. All rights reserved.
// Copyright (c) 20
24
, Advanced Micro Devices, Inc. All rights reserved.
#pragma once
...
...
@@ -81,8 +81,10 @@ struct space_filling_curve
return
get_step_between
(
number
<
AccessIdx1d
>
{},
number
<
AccessIdx1d
-
1
>
{});
}
// Do not use this function directly!
// TODO: can refactor into generic lambda in the future
template
<
index_t
AccessIdx1d
>
static
CK_TILE_HOST_DEVICE
constexpr
Index
get_index
(
number
<
AccessIdx1d
>
)
static
CK_TILE_HOST_DEVICE
constexpr
Index
_
get_index
(
number
<
AccessIdx1d
>
)
{
#if 0
/*
...
...
@@ -153,11 +155,11 @@ struct space_filling_curve
return
idx_md
;
}
// FIXME: re
name this function
// FIXME: re
turn tuple of number<>, which is compile time only variable
template
<
index_t
AccessIdx1d
>
static
CK_TILE_HOST_DEVICE
constexpr
auto
get_index
_tuple_of_number
(
number
<
AccessIdx1d
>
)
static
CK_TILE_HOST_DEVICE
constexpr
auto
get_index
(
number
<
AccessIdx1d
>
)
{
constexpr
auto
idx
=
get_index
(
number
<
AccessIdx1d
>
{});
constexpr
auto
idx
=
_
get_index
(
number
<
AccessIdx1d
>
{});
return
generate_tuple
([
&
](
auto
i
)
{
return
number
<
idx
[
i
]
>
{};
},
number
<
nDim
>
{});
}
...
...
include/ck_tile/core/arch/amd_buffer_addressing.hpp
View file @
7d50244e
...
...
@@ -621,6 +621,99 @@ CK_TILE_DEVICE void buffer_load_fence(index_t cnt = 0)
asm
volatile
(
"s_waitcnt vmcnt(%0)"
:
:
"n"
(
cnt
)
:
"memory"
);
}
namespace
impl
{
// below type indicate the data type used for buffer load inline asm
// clang-format off
template
<
index_t
N
,
typename
T
>
struct
smem_load_trait
;
template
<
typename
T
>
struct
smem_load_trait
<
16
,
T
>
{
using
payload_t
=
fp32x4_t
;
};
template
<
typename
T
>
struct
smem_load_trait
<
8
,
T
>
{
using
payload_t
=
fp32x2_t
;
};
template
<
typename
T
>
struct
smem_load_trait
<
4
,
T
>
{
using
payload_t
=
float
;
};
template
<
typename
T
>
struct
smem_load_trait
<
2
,
T
>
{
using
payload_t
=
float
;
};
template
<
typename
T
>
struct
smem_load_trait
<
1
,
T
>
{
using
payload_t
=
float
;
};
// clang-format on
}
// namespace impl
// NOTE: smem load/store no need pre_nop to make sure dependency by sw, happy :)
template
<
index_t
>
struct
smem_load
;
template
<
>
struct
smem_load
<
16
>
{
template
<
typename
T
>
CK_TILE_DEVICE
void
operator
()(
T
&
value
,
index_t
v_offset
,
index_t
i_offset
)
{
static_assert
(
sizeof
(
T
)
==
16
);
using
mbuf_t
=
typename
impl
::
smem_load_trait
<
16
,
T
>::
payload_t
;
asm
volatile
(
"ds_read_b128 %0, %1 offset:%2"
:
"=v"
(
reinterpret_cast
<
mbuf_t
&>
(
value
))
// ! direct write
:
"v"
(
v_offset
),
"n"
(
i_offset
)
:
"memory"
);
}
};
template
<
>
struct
smem_load
<
8
>
{
template
<
typename
T
>
CK_TILE_DEVICE
void
operator
()(
T
&
value
,
index_t
v_offset
,
index_t
i_offset
)
{
static_assert
(
sizeof
(
T
)
==
8
);
using
mbuf_t
=
typename
impl
::
smem_load_trait
<
8
,
T
>::
payload_t
;
asm
volatile
(
"ds_read_b64 %0, %1 offset:%2"
:
"=v"
(
reinterpret_cast
<
mbuf_t
&>
(
value
))
// ! direct write
:
"v"
(
v_offset
),
"n"
(
i_offset
)
:
"memory"
);
}
};
template
<
>
struct
smem_load
<
4
>
{
template
<
typename
T
>
CK_TILE_DEVICE
void
operator
()(
T
&
value
,
index_t
v_offset
,
index_t
i_offset
)
{
static_assert
(
sizeof
(
T
)
==
4
);
using
mbuf_t
=
typename
impl
::
smem_load_trait
<
4
,
T
>::
payload_t
;
asm
volatile
(
"ds_read_b32 %0, %1 offset:%2"
:
"=v"
(
reinterpret_cast
<
mbuf_t
&>
(
value
))
// ! direct write
:
"v"
(
v_offset
),
"n"
(
i_offset
)
:
"memory"
);
}
};
template
<
>
struct
smem_load
<
2
>
{
template
<
typename
T
>
CK_TILE_DEVICE
void
operator
()(
T
&
value
,
index_t
v_offset
,
index_t
i_offset
)
{
static_assert
(
sizeof
(
T
)
==
4
);
// subdword is buggy, use dword buf and convert manually
using
mbuf_t
=
typename
impl
::
smem_load_trait
<
1
,
T
>::
payload_t
;
asm
volatile
(
"ds_read_u16 %0, %1 offset:%2"
:
"=v"
(
reinterpret_cast
<
mbuf_t
&>
(
value
))
// ! direct write
:
"v"
(
v_offset
),
"n"
(
i_offset
)
:
"memory"
);
}
};
template
<
>
struct
smem_load
<
1
>
{
template
<
typename
T
>
CK_TILE_DEVICE
void
operator
()(
T
&
value
,
index_t
v_offset
,
index_t
i_offset
)
{
static_assert
(
sizeof
(
T
)
==
4
);
using
mbuf_t
=
typename
impl
::
smem_load_trait
<
1
,
T
>::
payload_t
;
asm
volatile
(
"ds_read_u8 %0, %1 offset:%2"
:
"=v"
(
reinterpret_cast
<
mbuf_t
&>
(
value
))
// ! direct write
:
"v"
(
v_offset
),
"n"
(
i_offset
)
:
"memory"
);
}
};
// clang-format off
namespace
impl
{
...
...
@@ -976,6 +1069,16 @@ llvm_amdgcn_raw_buffer_atomic_max_fp64(double vdata,
int
soffset
,
// dst_wave_addr_offset
int
glc_slc
)
__asm
(
"llvm.amdgcn.raw.buffer.atomic.fmax.f64"
);
// Direct loads from global to LDS.
CK_TILE_DEVICE_EXTERN
void
llvm_amdgcn_raw_buffer_load_lds
(
int32x4_t
rsrc
,
__attribute__
((
address_space
(
3
)))
uint32_t
*
lds_ptr
,
index_t
size
,
index_t
voffset
,
index_t
soffset
,
index_t
offset
,
index_t
aux
)
__asm
(
"llvm.amdgcn.raw.buffer.load.lds"
);
template
<
bool
pre_nop
=
false
>
CK_TILE_DEVICE
void
async_buffer_load_dword_v
(
void
*
smem
,
int32x4_t
rsrc
,
...
...
@@ -1313,6 +1416,7 @@ CK_TILE_DEVICE void amd_buffer_load_raw_impl(thread_buffer<T, N>& dst,
int32x4_t
src_wave_buffer_resource
,
index_t
src_thread_addr_offset
,
index_t
src_wave_addr_offset
,
index_t
src_linear_addr_offset
,
index_t
flag
=
0
,
bool_constant
<
pre_nop
>
=
{})
{
...
...
@@ -1327,7 +1431,7 @@ CK_TILE_DEVICE void amd_buffer_load_raw_impl(thread_buffer<T, N>& dst,
src_wave_buffer_resource
,
src_thread_addr_offset
,
src_wave_addr_offset
,
0
,
src_linear_addr_offset
,
flag
,
bool_constant
<
pre_nop
>
{});
}
...
...
@@ -1337,7 +1441,7 @@ CK_TILE_DEVICE void amd_buffer_load_raw_impl(thread_buffer<T, N>& dst,
src_wave_buffer_resource
,
src_thread_addr_offset
,
src_wave_addr_offset
,
0
,
src_linear_addr_offset
,
flag
,
bool_constant
<
pre_nop
>
{});
}
...
...
@@ -1365,6 +1469,43 @@ CK_TILE_DEVICE void amd_async_buffer_load_impl(T* smem,
bool_constant
<
pre_nop
>
{});
}
template
<
typename
T
,
index_t
N
,
amd_buffer_coherence_enum
coherence
=
amd_buffer_coherence_enum
::
coherence_default
,
bool
oob_conditional_check
=
true
>
CK_TILE_DEVICE
void
amd_async_buffer_load
(
CK_TILE_LDS_ADDR
T
*
smem
,
int32x4_t
src_wave_buffer_resource
,
index_t
src_thread_addr_offset
,
index_t
src_wave_addr_offset
,
index_t
src_immediate_addr_offset
=
0
,
index_t
flag
=
0
,
bool_constant
<
oob_conditional_check
>
=
{})
{
static_assert
(
sizeof
(
T
)
*
N
==
4
,
"wrong! not implemented vector size"
);
if
constexpr
(
oob_conditional_check
)
{
index_t
v_offset
=
flag
?
v_offset
:
src_wave_buffer_resource
[
2
];
llvm_amdgcn_raw_buffer_load_lds
(
src_wave_buffer_resource
,
smem
,
sizeof
(
uint32_t
),
v_offset
,
src_wave_addr_offset
,
src_immediate_addr_offset
,
static_cast
<
index_t
>
(
coherence
));
}
else
{
llvm_amdgcn_raw_buffer_load_lds
(
src_wave_buffer_resource
,
smem
,
sizeof
(
uint32_t
),
src_thread_addr_offset
,
src_wave_addr_offset
,
src_immediate_addr_offset
,
static_cast
<
index_t
>
(
coherence
));
}
}
template
<
index_t
N
,
amd_buffer_coherence_enum
coherence
=
amd_buffer_coherence_enum
::
coherence_default
>
CK_TILE_DEVICE
void
amd_buffer_store_impl_with_bytes
(
const
thread_buffer
<
int8_t
,
N
>
src_thread_data
,
...
...
@@ -1685,6 +1826,7 @@ CK_TILE_DEVICE void amd_buffer_store_raw_impl(const thread_buffer<T, N>& dst_thr
int32x4_t
dst_wave_buffer_resource
,
index_t
dst_thread_addr_offset
,
index_t
dst_wave_addr_offset
,
index_t
dst_linear_addr_offset
,
index_t
is_valid_element
=
1
)
{
constexpr
index_t
bytes
=
sizeof
(
T
)
*
N
;
...
...
@@ -1698,7 +1840,7 @@ CK_TILE_DEVICE void amd_buffer_store_raw_impl(const thread_buffer<T, N>& dst_thr
dst_wave_buffer_resource
,
dst_thread_addr_offset
,
dst_wave_addr_offset
,
0
,
dst_linear_addr_offset
,
is_valid_element
);
}
else
...
...
@@ -1707,7 +1849,7 @@ CK_TILE_DEVICE void amd_buffer_store_raw_impl(const thread_buffer<T, N>& dst_thr
dst_wave_buffer_resource
,
dst_thread_addr_offset
,
dst_wave_addr_offset
,
0
);
dst_linear_addr_offset
);
}
}
...
...
@@ -2014,6 +2156,7 @@ template <typename T,
CK_TILE_DEVICE
void
amd_buffer_load_raw
(
thread_buffer
<
T
,
N
>&
dst
,
const
T
*
p_src_wave
,
index_t
src_thread_element_offset
,
index_t
src_linear_element_offset
,
index_t
src_element_space_size
,
index_t
is_valid_element
=
0
,
bool_constant
<
pre_nop
>
=
{})
...
...
@@ -2022,12 +2165,14 @@ CK_TILE_DEVICE void amd_buffer_load_raw(thread_buffer<T, N>& dst,
make_wave_buffer_resource
(
p_src_wave
,
src_element_space_size
*
sizeof
(
T
));
index_t
src_thread_addr_offset
=
src_thread_element_offset
*
sizeof
(
T
);
index_t
src_linear_addr_offset
=
src_linear_element_offset
*
sizeof
(
T
);
amd_buffer_load_raw_impl
<
T
,
N
,
coherence
,
oob_conditional_check
,
pre_nop
>
(
dst
,
src_wave_buffer_resource
,
src_thread_addr_offset
,
0
,
src_linear_addr_offset
,
is_valid_element
,
bool_constant
<
pre_nop
>
{});
}
...
...
@@ -2041,16 +2186,19 @@ template <typename T,
CK_TILE_DEVICE
void
amd_buffer_load_raw
(
thread_buffer
<
T
,
N
>&
dst
,
const
int32x4_t
src_wave_buffer_resource
,
index_t
src_thread_element_offset
,
index_t
src_linear_element_offset
,
index_t
is_valid_element
=
0
,
bool_constant
<
pre_nop
>
=
{})
{
index_t
src_thread_addr_offset
=
src_thread_element_offset
*
sizeof
(
T
);
index_t
src_linear_addr_offset
=
src_linear_element_offset
*
sizeof
(
T
);
amd_buffer_load_raw_impl
<
T
,
N
,
coherence
,
oob_conditional_check
,
pre_nop
>
(
dst
,
src_wave_buffer_resource
,
src_thread_addr_offset
,
0
,
src_linear_addr_offset
,
is_valid_element
,
bool_constant
<
pre_nop
>
{});
}
...
...
@@ -2066,6 +2214,7 @@ template <typename T,
CK_TILE_DEVICE
void
amd_async_buffer_load_with_oob_raw
(
T
*
smem
,
const
T
*
p_src_wave
,
index_t
src_thread_element_offset
,
index_t
src_linear_element_offset
,
index_t
src_element_space_size
,
bool_constant
<
pre_nop
>
=
{})
{
...
...
@@ -2073,9 +2222,14 @@ CK_TILE_DEVICE void amd_async_buffer_load_with_oob_raw(T* smem,
make_wave_buffer_resource
(
p_src_wave
,
src_element_space_size
*
sizeof
(
T
));
index_t
src_thread_addr_offset
=
src_thread_element_offset
*
sizeof
(
T
);
index_t
src_linear_addr_offset
=
src_linear_element_offset
*
sizeof
(
T
);
amd_async_buffer_load_impl
<
T
,
N
,
coherence
>
(
smem
,
src_wave_buffer_resource
,
src_thread_addr_offset
,
0
,
0
,
bool_constant
<
pre_nop
>
{});
amd_async_buffer_load_impl
<
T
,
N
,
coherence
>
(
smem
,
src_wave_buffer_resource
,
src_thread_addr_offset
,
0
,
src_linear_addr_offset
,
bool_constant
<
pre_nop
>
{});
}
// This version support buffer resource as input arg
...
...
@@ -2086,12 +2240,42 @@ template <typename T,
CK_TILE_DEVICE
void
amd_async_buffer_load_with_oob_raw
(
T
*
smem
,
const
int32x4_t
src_wave_buffer_resource
,
index_t
src_thread_element_offset
,
index_t
src_linear_element_offset
,
bool_constant
<
pre_nop
>
=
{})
{
index_t
src_thread_addr_offset
=
src_thread_element_offset
*
sizeof
(
T
);
index_t
src_linear_addr_offset
=
src_linear_element_offset
*
sizeof
(
T
);
amd_async_buffer_load_impl
<
T
,
N
,
coherence
>
(
smem
,
src_wave_buffer_resource
,
src_thread_addr_offset
,
0
,
0
,
bool_constant
<
pre_nop
>
{});
amd_async_buffer_load_impl
<
T
,
N
,
coherence
>
(
smem
,
src_wave_buffer_resource
,
src_thread_addr_offset
,
0
,
src_linear_addr_offset
,
bool_constant
<
pre_nop
>
{});
}
// This version support buffer resource as input arg
template
<
typename
T
,
index_t
N
,
amd_buffer_coherence_enum
coherence
=
amd_buffer_coherence_enum
::
coherence_default
,
bool
oob_conditional_check
=
false
>
CK_TILE_DEVICE
void
amd_async_buffer_load_with_oob
(
CK_TILE_LDS_ADDR
T
*
smem
,
const
int32x4_t
src_wave_buffer_resource
,
index_t
src_thread_element_offset
,
index_t
src_linear_element_offset
,
bool
is_valid_element
,
bool_constant
<
oob_conditional_check
>
=
{})
{
index_t
src_thread_addr_offset
=
src_thread_element_offset
*
sizeof
(
T
);
index_t
src_linear_addr_offset
=
src_linear_element_offset
*
sizeof
(
T
);
amd_async_buffer_load
<
T
,
N
,
coherence
>
(
smem
,
src_wave_buffer_resource
,
src_thread_addr_offset
,
0
,
src_linear_addr_offset
,
is_valid_element
,
bool_constant
<
oob_conditional_check
>
{});
}
// buffer_store requires:
...
...
@@ -2146,6 +2330,7 @@ template <typename T,
CK_TILE_DEVICE
void
amd_buffer_store_raw
(
const
thread_buffer
<
T
,
N
>&
src_thread_data
,
T
*
p_dst_wave
,
const
index_t
dst_thread_element_offset
,
const
index_t
dst_linear_element_offset
,
const
bool
dst_thread_element_valid
,
const
index_t
dst_element_space_size
)
{
...
...
@@ -2153,11 +2338,13 @@ CK_TILE_DEVICE void amd_buffer_store_raw(const thread_buffer<T, N>& src_thread_d
make_wave_buffer_resource
(
p_dst_wave
,
dst_element_space_size
*
sizeof
(
T
));
index_t
dst_thread_addr_offset
=
dst_thread_element_offset
*
sizeof
(
T
);
index_t
dst_linear_addr_offset
=
dst_linear_element_offset
*
sizeof
(
T
);
amd_buffer_store_raw_impl
<
T
,
N
,
coherence
,
oob_conditional_check
>
(
src_thread_data
,
dst_wave_buffer_resource
,
dst_thread_addr_offset
,
0
,
dst_linear_addr_offset
,
dst_thread_element_valid
);
}
...
...
@@ -2221,16 +2408,6 @@ CK_TILE_DEVICE void amd_buffer_atomic_max(const thread_buffer<T, N>& src_thread_
#endif
}
// Direct loads from global to LDS.
CK_TILE_DEVICE_EXTERN
void
llvm_amdgcn_raw_buffer_load_lds
(
int32x4_t
rsrc
,
__attribute__
((
address_space
(
3
)))
uint32_t
*
lds_ptr
,
index_t
size
,
index_t
voffset
,
index_t
soffset
,
index_t
offset
,
index_t
aux
)
__asm
(
"llvm.amdgcn.raw.buffer.load.lds"
);
template
<
typename
T
,
index_t
NumElemsPerThread
>
CK_TILE_DEVICE
void
amd_direct_load_global_to_lds
(
const
T
*
global_base_ptr
,
const
index_t
global_offset
,
...
...
include/ck_tile/core/config.hpp
View file @
7d50244e
...
...
@@ -41,6 +41,19 @@
#define CK_TILE_HOST_DEVICE_EXTERN
#endif
// implementing the "memory address space" attribute
// https://llvm.org/docs/AMDGPUUsage.html#amdgpu-address-spaces-table
#ifdef __HIPCC_
#define CK_TILE_GENERIC_ADDR __attribute__((address_space(0)))
#define CK_TILE_GLOBAL_ADDR __attribute__((address_space(1)))
#define CK_TILE_LDS_ADDR __attribute__((address_space(3)))
#define CK_TILE_BUF_RES_ADDR __attribute__((address_space(8)))
#else
#define CK_TILE_GENERIC_ADDR
#define CK_TILE_GLOBAL_ADDR
#define CK_TILE_LDS_ADDR
#define CK_TILE_BUF_RES_ADDR
#endif
#ifndef CK_TILE_USE_CUSTOM_DATA_TYPE
#define CK_TILE_USE_CUSTOM_DATA_TYPE 0 // custom data type will generate extra move/bfi code
#endif
...
...
@@ -205,3 +218,8 @@
#ifndef CK_TILE_BUFFER_LOAD_RAW_BF16_WA
#define CK_TILE_BUFFER_LOAD_RAW_BF16_WA 1
#endif
// workaround: compiler not emiting reciprocal instruction frm __frcp_rn()
#ifndef CK_TILE_WORKAROUND_SWDEV_383542
#define CK_TILE_WORKAROUND_SWDEV_383542 1
#endif
include/ck_tile/core/container/tuple.hpp
View file @
7d50244e
...
...
@@ -623,7 +623,7 @@ template <typename... Ys,
false
>
CK_TILE_HOST_DEVICE
constexpr
auto
operator
+=
(
tuple
<
Ys
...
>&
y
,
const
X
&
x
)
{
static_assert
(
X
::
S
ize
()
==
sizeof
...(
Ys
),
"wrong! size not the same"
);
static_assert
(
X
::
s
ize
()
==
sizeof
...(
Ys
),
"wrong! size not the same"
);
constexpr
index_t
NSize
=
sizeof
...(
Ys
);
static_for
<
0
,
NSize
,
1
>
{}([
&
](
auto
i
)
{
y
[
i
]
+=
x
[
i
];
});
return
y
;
...
...
@@ -635,7 +635,7 @@ template <typename... Ys,
false
>
CK_TILE_HOST_DEVICE
constexpr
auto
operator
-=
(
tuple
<
Ys
...
>&
y
,
const
X
&
x
)
{
static_assert
(
X
::
S
ize
()
==
sizeof
...(
Ys
),
"wrong! size not the same"
);
static_assert
(
X
::
s
ize
()
==
sizeof
...(
Ys
),
"wrong! size not the same"
);
constexpr
index_t
NSize
=
sizeof
...(
Ys
);
static_for
<
0
,
NSize
,
1
>
{}([
&
](
auto
i
)
{
y
[
i
]
-=
x
[
i
];
});
return
y
;
...
...
@@ -647,7 +647,7 @@ template <typename... Xs,
false
>
CK_TILE_HOST_DEVICE
constexpr
auto
operator
+
(
const
tuple
<
Xs
...
>&
x
,
const
Y
&
y
)
{
static_assert
(
Y
::
S
ize
()
==
sizeof
...(
Xs
),
"wrong! size not the same"
);
static_assert
(
Y
::
s
ize
()
==
sizeof
...(
Xs
),
"wrong! size not the same"
);
constexpr
index_t
NSize
=
sizeof
...(
Xs
);
tuple
<
Xs
...
>
r
;
...
...
@@ -655,13 +655,21 @@ CK_TILE_HOST_DEVICE constexpr auto operator+(const tuple<Xs...>& x, const Y& y)
return
r
;
}
template
<
typename
...
Xs
,
typename
...
Ys
>
CK_TILE_HOST_DEVICE
constexpr
auto
operator
+
(
const
tuple
<
Xs
...
>&
x
,
const
tuple
<
Ys
...
>&
y
)
{
static_assert
(
sizeof
...(
Xs
)
==
sizeof
...(
Ys
),
"wrong!"
);
constexpr
index_t
NSize
=
sizeof
...(
Xs
);
return
generate_tuple
([
&
](
auto
i
)
{
return
x
[
i
]
+
y
[
i
];
},
number
<
NSize
>
{});
}
template
<
typename
...
Xs
,
typename
Y
,
std
::
enable_if_t
<!
std
::
is_integral
<
Y
>
::
value
&&
!
std
::
is_floating_point
<
Y
>::
value
,
bool
>
=
false
>
CK_TILE_HOST_DEVICE
constexpr
auto
operator
-
(
const
tuple
<
Xs
...
>&
x
,
const
Y
&
y
)
{
static_assert
(
Y
::
S
ize
()
==
sizeof
...(
Xs
),
"wrong! size not the same"
);
static_assert
(
Y
::
s
ize
()
==
sizeof
...(
Xs
),
"wrong! size not the same"
);
constexpr
index_t
NSize
=
sizeof
...(
Xs
);
tuple
<
Xs
...
>
r
;
...
...
@@ -669,13 +677,21 @@ CK_TILE_HOST_DEVICE constexpr auto operator-(const tuple<Xs...>& x, const Y& y)
return
r
;
}
template
<
typename
...
Xs
,
typename
...
Ys
>
CK_TILE_HOST_DEVICE
constexpr
auto
operator
-
(
const
tuple
<
Xs
...
>&
x
,
const
tuple
<
Ys
...
>&
y
)
{
static_assert
(
sizeof
...(
Xs
)
==
sizeof
...(
Ys
),
"wrong!"
);
constexpr
index_t
NSize
=
sizeof
...(
Xs
);
return
generate_tuple
([
&
](
auto
i
)
{
return
x
[
i
]
-
y
[
i
];
},
number
<
NSize
>
{});
}
template
<
typename
...
Xs
,
typename
Y
,
std
::
enable_if_t
<!
std
::
is_integral
<
Y
>
::
value
&&
!
std
::
is_floating_point
<
Y
>::
value
,
bool
>
=
false
>
CK_TILE_HOST_DEVICE
constexpr
auto
operator
*
(
const
tuple
<
Xs
...
>&
x
,
const
Y
&
y
)
{
static_assert
(
Y
::
S
ize
()
==
sizeof
...(
Xs
),
"wrong! size not the same"
);
static_assert
(
Y
::
s
ize
()
==
sizeof
...(
Xs
),
"wrong! size not the same"
);
constexpr
index_t
NSize
=
sizeof
...(
Xs
);
tuple
<
Xs
...
>
r
;
...
...
@@ -706,6 +722,14 @@ CK_TILE_HOST_DEVICE constexpr auto operator*(const tuple<Xs...>& x, Y a)
return
a
*
x
;
}
template
<
typename
...
Xs
,
typename
...
Ys
>
CK_TILE_HOST_DEVICE
constexpr
auto
operator
*
(
const
tuple
<
Xs
...
>&
x
,
const
tuple
<
Ys
...
>&
y
)
{
static_assert
(
sizeof
...(
Xs
)
==
sizeof
...(
Ys
),
"wrong!"
);
constexpr
index_t
NSize
=
sizeof
...(
Xs
);
return
generate_tuple
([
&
](
auto
i
)
{
return
x
[
i
]
*
y
[
i
];
},
number
<
NSize
>
{});
}
template
<
typename
...
Xs
,
typename
...
Ys
>
CK_TILE_HOST_DEVICE
constexpr
auto
operator
/
(
const
tuple
<
Xs
...
>&
x
,
const
tuple
<
Ys
...
>&
y
)
{
...
...
include/ck_tile/core/numeric/int8.hpp
0 → 100644
View file @
7d50244e
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2024, Advanced Micro Devices, Inc. All rights reserved.
#include "ck_tile/core/config.hpp"
#include "ck_tile/core/numeric/half.hpp"
#include "ck_tile/core/numeric/integral_constant.hpp"
#include "ck_tile/core/numeric/math.hpp"
#include "ck_tile/core/numeric/numeric.hpp"
#include "ck_tile/core/utility/bit_cast.hpp"
#include "ck_tile/core/utility/random.hpp"
#include <stdint.h>
#include <type_traits>
#pragma once
namespace
ck_tile
{
// use int8_t directly for int8 arithemetic
// here one can use ck_tile::int8_t to access original int8_t
using
int8_t
=
int8_t
;
// limits
template
<
class
T
>
struct
numeric
;
template
<
>
struct
numeric
<
int8_t
>
{
// minimum finite value, or minimum positive normalized value for float
CK_TILE_HOST_DEVICE
static
constexpr
int8_t
min
()
{
return
int8_t
(
-
128
);
}
// minumum finite value
CK_TILE_HOST_DEVICE
static
constexpr
int8_t
lowest
()
{
return
int8_t
(
-
128
);
}
// maximum finite value
CK_TILE_HOST_DEVICE
static
constexpr
int8_t
max
()
{
return
int8_t
(
127
);
}
// difference between 1.0 and next value representable by float
CK_TILE_HOST_DEVICE
static
constexpr
int8_t
epsilon
()
{
return
1
;
// not used
}
CK_TILE_HOST_DEVICE
static
constexpr
int8_t
round_error
()
{
return
1
;
// not used
}
// positive infinity value
CK_TILE_HOST_DEVICE
static
constexpr
int8_t
infinity
()
{
return
1
;
// not used
}
// quiet NaN
CK_TILE_HOST_DEVICE
static
constexpr
int8_t
quiet_NaN
()
{
return
1
;
// not used
}
// signaling NaN
CK_TILE_HOST_DEVICE
static
constexpr
int8_t
signaling_NaN
()
{
return
1
;
// not used
}
// smallest positive subnormal value
CK_TILE_HOST_DEVICE
static
constexpr
int8_t
denorm_min
()
{
return
1
;
// not used
}
CK_TILE_HOST_DEVICE
static
constexpr
int8_t
zero
()
{
return
0
;
}
};
#if 0
template <typename T>
struct numeric_traits;
template <>
struct numeric_traits<int8_t>
{
static constexpr int exp = 5;
static constexpr int mant = 10;
static constexpr int bias = 15;
static constexpr uint16_t nan_mask = 0x7C00;
static constexpr uint16_t head_mask = 0xFC00;
static constexpr uint16_t mant_mask = 0x3FF;
static constexpr uint16_t exp_mask = 0x1F;
static constexpr uint32_t Inf = 0x7C00;
static constexpr uint32_t NegInf = 0xFC00;
static constexpr uint32_t NaN = 0x7C01;
static constexpr uint32_t Neg0 = 0x8000;
using bitwise_type = uint16_t;
};
#endif
CK_TILE_HOST_DEVICE
constexpr
float
int8_to_float
(
const
int8_t
&
x
)
{
return
static_cast
<
float
>
(
x
);
}
CK_TILE_HOST_DEVICE
constexpr
int8_t
float_to_int8
(
const
float
&
x
)
{
return
static_cast
<
int8_t
>
(
x
);
}
}
// namespace ck_tile
include/ck_tile/core/numeric/math.hpp
View file @
7d50244e
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-202
3
, Advanced Micro Devices, Inc. All rights reserved.
// Copyright (c) 2018-202
4
, Advanced Micro Devices, Inc. All rights reserved.
#pragma once
...
...
@@ -487,55 +487,12 @@ struct log2e<float>
template
<
typename
T
=
double
>
constexpr
T
log2e_v
=
log2e
<
T
>::
value
;
// math
CK_TILE_HOST_DEVICE
float
abs
(
const
float
&
x
)
{
union
{
float
f32
;
uint32_t
u32
;
}
y
;
y
.
f32
=
x
;
y
.
u32
=
y
.
u32
&
0x7fffffff
;
return
y
.
f32
;
}
CK_TILE_HOST_DEVICE
bool
isnan
(
const
float
&
x
)
{
uint32_t
xx
=
bit_cast
<
uint32_t
>
(
x
);
return
(
xx
&
0x7fffffff
)
>
0x7F800000
;
}
CK_TILE_HOST
float
sqrt
(
float
x
)
{
return
std
::
sqrt
(
x
);
};
CK_TILE_HOST
double
sqrt
(
double
x
)
{
return
std
::
sqrt
(
x
);
};
CK_TILE_DEVICE
float
sqrt
(
float
x
)
{
return
__builtin_amdgcn_sqrtf
(
x
);
};
CK_TILE_DEVICE
double
sqrt
(
double
x
)
{
return
__builtin_amdgcn_sqrt
(
x
);
};
CK_TILE_DEVICE
float
exp
(
float
x
)
{
return
__ocml_exp_f32
(
x
);
};
CK_TILE_HOST
float
exp
(
float
x
)
{
return
std
::
expf
(
x
);
}
CK_TILE_DEVICE
float
exp2
(
float
x
)
{
return
exp2f
(
x
);
};
CK_TILE_HOST
float
exp2
(
float
x
)
{
return
std
::
exp2f
(
x
);
};
CK_TILE_DEVICE
float
log
(
float
x
)
{
return
__logf
(
x
);
};
CK_TILE_HOST
float
log
(
float
x
)
{
return
std
::
logf
(
x
);
};
CK_TILE_DEVICE
uint16_t
sad_u16
(
uint16_t
x
,
uint16_t
y
,
uint16_t
acc
)
{
return
__builtin_amdgcn_sad_u16
(
x
,
y
,
acc
);
...
...
@@ -554,4 +511,933 @@ CK_TILE_HOST uint32_t sad_u32(uint32_t x, uint32_t y, uint32_t acc)
return
(
x
>
y
?
(
x
-
y
)
:
(
y
-
x
))
+
acc
;
}
///////////////////////////////////////////////////////////////
}
// namespace ck_tile
// blow function need data type pre-defined
#include "ck_tile/core/numeric/half.hpp"
#include "ck_tile/core/numeric/bfloat16.hpp"
#include "ck_tile/core/numeric/float8.hpp"
#include "ck_tile/core/numeric/type_convert.hpp"
#ifndef __HIP_DEVICE_COMPILE__
#include <cmath>
#endif
namespace
ck_tile
{
#if CK_TILE_WORKAROUND_SWDEV_383542
extern
"C"
CK_TILE_DEVICE
float
__ocml_native_recip_f32
(
float
);
#endif
// math functions for the host, some are implemented by calling C++ std functions
CK_TILE_HOST
float
abs
(
float
x
)
{
return
std
::
abs
(
x
);
};
CK_TILE_HOST
double
abs
(
double
x
)
{
return
std
::
abs
(
x
);
};
CK_TILE_HOST
int8_t
abs
(
int8_t
x
)
{
int8_t
sgn
=
x
>>
(
8
-
1
);
return
(
x
^
sgn
)
-
sgn
;
};
CK_TILE_HOST
int32_t
abs
(
int32_t
x
)
{
int32_t
sgn
=
x
>>
(
32
-
1
);
return
(
x
^
sgn
)
-
sgn
;
};
CK_TILE_HOST
fp16_t
abs
(
fp16_t
x
)
{
uint16_t
xx
=
bit_cast
<
uint16_t
>
(
x
);
uint16_t
abs_xx
=
xx
&
0x7fff
;
fp16_t
abs_x
=
bit_cast
<
fp16_t
>
(
abs_xx
);
return
abs_x
;
};
#ifdef CK_TILE_EXPERIMENTAL_BIT_INT_EXTENSION_INT4
CK_TILE_HOST
int4_t
abs
(
int4_t
x
)
{
int4_t
sgn
=
x
>>
(
4
-
1
);
return
(
x
^
sgn
)
-
sgn
;
}
#endif
CK_TILE_HOST
bool
isnan
(
float
x
)
{
return
std
::
isnan
(
x
);
};
CK_TILE_HOST
bool
isnan
(
double
x
)
{
return
std
::
isnan
(
x
);
};
CK_TILE_HOST
bool
isnan
(
int8_t
x
)
{
(
void
)
x
;
return
false
;
};
CK_TILE_HOST
bool
isnan
(
int32_t
x
)
{
(
void
)
x
;
return
false
;
};
CK_TILE_HOST
bool
isnan
(
fp16_t
x
)
{
uint16_t
xx
=
bit_cast
<
uint16_t
>
(
x
);
return
(
xx
&
0x7FFF
)
>
0x7C00
;
};
#ifdef CK_TILE_EXPERIMENTAL_BIT_INT_EXTENSION_INT4
CK_TILE_HOST
bool
isnan
(
int4_t
x
)
{
(
void
)
x
;
return
false
;
};
#endif
CK_TILE_HOST
fp16_t
sqrt
(
fp16_t
x
)
{
return
static_cast
<
fp16_t
>
(
std
::
sqrt
(
static_cast
<
float
>
(
x
)));
};
CK_TILE_HOST
float
sqrt
(
float
x
)
{
return
std
::
sqrt
(
x
);
};
CK_TILE_HOST
double
sqrt
(
double
x
)
{
return
std
::
sqrt
(
x
);
};
template
<
typename
T
>
CK_TILE_HOST
T
tanh
(
T
x
)
{
return
type_convert
<
T
>
(
std
::
tanhf
(
type_convert
<
float
>
(
x
)));
};
template
<
>
CK_TILE_HOST
float
tanh
<
float
>
(
float
x
)
{
return
std
::
tanhf
(
x
);
};
template
<
>
CK_TILE_HOST
double
tanh
<
double
>
(
double
x
)
{
return
std
::
tanh
(
x
);
};
template
<
typename
T
>
CK_TILE_HOST
T
acos
(
T
x
)
{
return
type_convert
<
T
>
(
std
::
acosf
(
type_convert
<
float
>
(
x
)));
};
template
<
>
CK_TILE_HOST
float
acos
<
float
>
(
float
x
)
{
return
std
::
acosf
(
x
);
};
template
<
>
CK_TILE_HOST
double
acos
<
double
>
(
double
x
)
{
return
std
::
acos
(
x
);
};
template
<
typename
T
>
CK_TILE_HOST
T
neg
(
T
x
)
{
return
type_convert
<
T
>
(
-
(
type_convert
<
float
>
(
x
)));
};
template
<
>
CK_TILE_HOST
float
neg
<
float
>
(
float
x
)
{
return
-
x
;
};
template
<
>
CK_TILE_HOST
double
neg
<
double
>
(
double
x
)
{
return
-
x
;
};
template
<
>
CK_TILE_HOST
int32_t
neg
<
int32_t
>
(
int32_t
x
)
{
return
-
x
;
};
template
<
>
CK_TILE_HOST
int8_t
neg
<
int8_t
>
(
int8_t
x
)
{
return
-
x
;
};
template
<
typename
T
>
CK_TILE_HOST
T
atan
(
T
x
)
{
return
type_convert
<
T
>
(
std
::
atanf
(
type_convert
<
float
>
(
x
)));
};
template
<
>
CK_TILE_HOST
float
atan
<
float
>
(
float
x
)
{
return
std
::
atanf
(
x
);
};
template
<
>
CK_TILE_HOST
double
atan
<
double
>
(
double
x
)
{
return
std
::
atan
(
x
);
};
template
<
typename
T
>
CK_TILE_HOST
T
sin
(
T
x
)
{
return
type_convert
<
T
>
(
std
::
sinf
(
type_convert
<
float
>
(
x
)));
};
template
<
>
CK_TILE_HOST
float
sin
<
float
>
(
float
x
)
{
return
std
::
sinf
(
x
);
};
template
<
>
CK_TILE_HOST
double
sin
<
double
>
(
double
x
)
{
return
std
::
sin
(
x
);
};
template
<
typename
T
>
CK_TILE_HOST
T
asin
(
T
x
)
{
return
type_convert
<
T
>
(
std
::
asinf
(
type_convert
<
float
>
(
x
)));
};
template
<
>
CK_TILE_HOST
float
asin
<
float
>
(
float
x
)
{
return
std
::
asinf
(
x
);
};
template
<
>
CK_TILE_HOST
double
asin
<
double
>
(
double
x
)
{
return
std
::
asin
(
x
);
};
template
<
typename
T
>
CK_TILE_HOST
T
asinh
(
T
x
)
{
return
type_convert
<
T
>
(
std
::
asinhf
(
type_convert
<
float
>
(
x
)));
};
template
<
>
CK_TILE_HOST
float
asinh
<
float
>
(
float
x
)
{
return
std
::
asinhf
(
x
);
};
template
<
>
CK_TILE_HOST
double
asinh
<
double
>
(
double
x
)
{
return
std
::
asinh
(
x
);
};
template
<
typename
T
>
CK_TILE_HOST
T
cos
(
T
x
)
{
return
type_convert
<
T
>
(
std
::
cosf
(
type_convert
<
float
>
(
x
)));
};
template
<
>
CK_TILE_HOST
float
cos
<
float
>
(
float
x
)
{
return
std
::
cosf
(
x
);
};
template
<
>
CK_TILE_HOST
double
cos
<
double
>
(
double
x
)
{
return
std
::
cos
(
x
);
};
template
<
typename
T
>
CK_TILE_HOST
T
acosh
(
T
x
)
{
return
type_convert
<
T
>
(
std
::
acoshf
(
type_convert
<
float
>
(
x
)));
};
template
<
>
CK_TILE_HOST
float
acosh
<
float
>
(
float
x
)
{
return
std
::
acoshf
(
x
);
};
template
<
>
CK_TILE_HOST
double
acosh
<
double
>
(
double
x
)
{
return
std
::
acosh
(
x
);
};
template
<
typename
T
>
CK_TILE_HOST
T
tan
(
T
x
)
{
return
type_convert
<
T
>
(
std
::
tanf
(
type_convert
<
float
>
(
x
)));
};
template
<
>
CK_TILE_HOST
float
tan
<
float
>
(
float
x
)
{
return
std
::
tanf
(
x
);
};
template
<
>
CK_TILE_HOST
double
tan
<
double
>
(
double
x
)
{
return
std
::
tan
(
x
);
};
template
<
typename
T
>
CK_TILE_HOST
T
atanh
(
T
x
)
{
return
type_convert
<
T
>
(
std
::
atanhf
(
type_convert
<
float
>
(
x
)));
};
template
<
>
CK_TILE_HOST
float
atanh
<
float
>
(
float
x
)
{
return
std
::
atanhf
(
x
);
};
template
<
>
CK_TILE_HOST
double
atanh
<
double
>
(
double
x
)
{
return
std
::
atanh
(
x
);
};
template
<
typename
T
>
CK_TILE_HOST
T
sinh
(
T
x
)
{
return
type_convert
<
T
>
(
std
::
sinhf
(
type_convert
<
float
>
(
x
)));
};
template
<
>
CK_TILE_HOST
float
sinh
<
float
>
(
float
x
)
{
return
std
::
sinhf
(
x
);
};
template
<
>
CK_TILE_HOST
double
sinh
<
double
>
(
double
x
)
{
return
std
::
sinh
(
x
);
};
template
<
typename
T
>
CK_TILE_HOST
T
ceil
(
T
x
)
{
return
type_convert
<
T
>
(
std
::
ceilf
(
type_convert
<
float
>
(
x
)));
};
template
<
>
CK_TILE_HOST
float
ceil
<
float
>
(
float
x
)
{
return
std
::
ceilf
(
x
);
};
template
<
>
CK_TILE_HOST
double
ceil
<
double
>
(
double
x
)
{
return
std
::
ceil
(
x
);
};
template
<
typename
T
>
CK_TILE_HOST
T
cosh
(
T
x
)
{
return
type_convert
<
T
>
(
std
::
coshf
(
type_convert
<
float
>
(
x
)));
};
template
<
>
CK_TILE_HOST
float
cosh
<
float
>
(
float
x
)
{
return
std
::
coshf
(
x
);
};
template
<
>
CK_TILE_HOST
double
cosh
<
double
>
(
double
x
)
{
return
std
::
cosh
(
x
);
};
template
<
typename
T
>
CK_TILE_HOST
T
floor
(
T
x
)
{
return
type_convert
<
T
>
(
std
::
floorf
(
type_convert
<
float
>
(
x
)));
};
template
<
>
CK_TILE_HOST
float
floor
<
float
>
(
float
x
)
{
return
std
::
floorf
(
x
);
};
template
<
>
CK_TILE_HOST
double
floor
<
double
>
(
double
x
)
{
return
std
::
floor
(
x
);
};
template
<
typename
T
>
CK_TILE_HOST
T
rcp
(
T
x
)
{
return
type_convert
<
T
>
(
1.
f
/
type_convert
<
float
>
(
x
));
};
template
<
typename
T
>
CK_TILE_HOST
T
exp
(
T
x
)
{
return
type_convert
<
T
>
(
std
::
expf
(
type_convert
<
float
>
(
x
)));
}
template
<
>
CK_TILE_HOST
float
exp
<
float
>
(
float
x
)
{
return
std
::
expf
(
x
);
}
template
<
>
CK_TILE_HOST
double
exp
<
double
>
(
double
x
)
{
return
std
::
exp
(
x
);
}
template
<
typename
T
>
CK_TILE_HOST
T
log
(
T
x
)
{
return
type_convert
<
T
>
(
std
::
logf
(
type_convert
<
float
>
(
x
)));
}
template
<
>
CK_TILE_HOST
float
log
<
float
>
(
float
x
)
{
return
std
::
logf
(
x
);
}
template
<
>
CK_TILE_HOST
double
log
<
double
>
(
double
x
)
{
return
std
::
log
(
x
);
}
template
<
typename
T
>
CK_TILE_HOST
T
pow
(
T
x
,
T
gamma
)
{
return
type_convert
<
T
>
(
std
::
powf
(
type_convert
<
float
>
(
x
),
type_convert
<
float
>
(
gamma
)));
}
template
<
>
CK_TILE_HOST
float
pow
<
float
>
(
float
x
,
float
gamma
)
{
return
std
::
powf
(
x
,
gamma
);
}
template
<
>
CK_TILE_HOST
double
pow
<
double
>
(
double
x
,
double
gamma
)
{
return
std
::
pow
(
x
,
gamma
);
}
template
<
typename
T
>
CK_TILE_HOST
T
expm1
(
T
x
)
{
return
type_convert
<
T
>
(
std
::
expm1f
(
type_convert
<
float
>
(
x
)));
}
template
<
>
CK_TILE_HOST
float
expm1
<
float
>
(
float
x
)
{
return
std
::
expm1f
(
x
);
}
template
<
>
CK_TILE_HOST
double
expm1
<
double
>
(
double
x
)
{
return
std
::
expm1
(
x
);
}
// math functions for the HIP kernel, some are implemented by calling hip builtin functions
CK_TILE_DEVICE
float
abs
(
float
x
)
{
union
{
float
f32
;
uint32_t
u32
;
}
y
;
y
.
f32
=
x
;
y
.
u32
=
y
.
u32
&
0x7fffffff
;
return
y
.
f32
;
};
CK_TILE_DEVICE
double
abs
(
double
x
)
{
return
::
abs
(
x
);
};
CK_TILE_DEVICE
int8_t
abs
(
int8_t
x
)
{
int8_t
sgn
=
x
>>
(
8
-
1
);
return
(
x
^
sgn
)
-
sgn
;
};
CK_TILE_DEVICE
int32_t
abs
(
int32_t
x
)
{
int32_t
sgn
=
x
>>
(
32
-
1
);
return
(
x
^
sgn
)
-
sgn
;
};
#ifdef CK_TILE_EXPERIMENTAL_BIT_INT_EXTENSION_INT4
CK_TILE_DEVICE
int4_t
abs
(
int4_t
x
)
{
int4_t
sgn
=
x
>>
(
4
-
1
);
return
(
x
^
sgn
)
-
sgn
;
};
#endif
CK_TILE_DEVICE
fp16_t
abs
(
fp16_t
x
)
{
uint16_t
xx
=
bit_cast
<
uint16_t
>
(
x
);
uint16_t
abs_xx
=
xx
&
0x7fff
;
fp16_t
abs_x
=
bit_cast
<
fp16_t
>
(
abs_xx
);
return
abs_x
;
};
CK_TILE_DEVICE
bool
isnan
(
float
x
)
{
return
::
isnan
(
x
);
};
CK_TILE_DEVICE
bool
isnan
(
double
x
)
{
return
::
isnan
(
x
);
};
CK_TILE_DEVICE
bool
isnan
(
int8_t
x
)
{
(
void
)
x
;
return
false
;
};
CK_TILE_DEVICE
bool
isnan
(
int32_t
x
)
{
(
void
)
x
;
return
false
;
};
#ifdef CK_TILE_EXPERIMENTAL_BIT_INT_EXTENSION_INT4
CK_TILE_DEVICE
bool
isnan
(
int4_t
x
)
{
(
void
)
x
;
return
false
;
};
#endif
CK_TILE_DEVICE
bool
isnan
(
fp16_t
x
)
{
uint16_t
xx
=
bit_cast
<
uint16_t
>
(
x
);
return
(
xx
&
0x7FFF
)
>
0x7C00
;
};
CK_TILE_DEVICE
fp16_t
sqrt
(
fp16_t
x
)
{
return
static_cast
<
fp16_t
>
(
__builtin_amdgcn_sqrtf
(
static_cast
<
float
>
(
x
)));
};
CK_TILE_DEVICE
float
sqrt
(
float
x
)
{
return
__builtin_amdgcn_sqrtf
(
x
);
};
CK_TILE_DEVICE
double
sqrt
(
double
x
)
{
return
__builtin_amdgcn_sqrt
(
x
);
};
template
<
typename
T
>
CK_TILE_DEVICE
T
tanh
(
T
x
)
{
return
type_convert
<
T
>
(
::
tanhf
(
type_convert
<
float
>
(
x
)));
};
template
<
>
CK_TILE_DEVICE
float
tanh
<
float
>
(
float
x
)
{
return
::
tanhf
(
x
);
};
template
<
>
CK_TILE_DEVICE
double
tanh
<
double
>
(
double
x
)
{
return
::
tanh
(
x
);
};
template
<
typename
T
>
CK_TILE_DEVICE
T
acos
(
T
x
)
{
return
type_convert
<
T
>
(
::
acosf
(
type_convert
<
float
>
(
x
)));
};
template
<
>
CK_TILE_DEVICE
float
acos
<
float
>
(
float
x
)
{
return
::
acosf
(
x
);
};
template
<
>
CK_TILE_DEVICE
double
acos
<
double
>
(
double
x
)
{
return
::
acos
(
x
);
};
template
<
typename
T
>
CK_TILE_DEVICE
T
neg
(
T
x
)
{
return
type_convert
<
T
>
(
-
(
type_convert
<
float
>
(
x
)));
};
template
<
>
CK_TILE_DEVICE
float
neg
<
float
>
(
float
x
)
{
return
-
x
;
};
template
<
>
CK_TILE_DEVICE
double
neg
<
double
>
(
double
x
)
{
return
-
x
;
};
template
<
>
CK_TILE_DEVICE
int32_t
neg
<
int32_t
>
(
int32_t
x
)
{
return
-
x
;
};
template
<
>
CK_TILE_DEVICE
int8_t
neg
<
int8_t
>
(
int8_t
x
)
{
return
-
x
;
};
template
<
>
CK_TILE_DEVICE
fp16_t
neg
<
fp16_t
>
(
fp16_t
x
)
{
return
-
x
;
};
template
<
typename
T
>
CK_TILE_DEVICE
T
atan
(
T
x
)
{
return
type_convert
<
T
>
(
::
atanf
(
type_convert
<
float
>
(
x
)));
};
template
<
>
CK_TILE_DEVICE
float
atan
<
float
>
(
float
x
)
{
return
::
atanf
(
x
);
};
template
<
>
CK_TILE_DEVICE
double
atan
<
double
>
(
double
x
)
{
return
::
atan
(
x
);
};
template
<
typename
T
>
CK_TILE_DEVICE
T
sin
(
T
x
)
{
return
type_convert
<
T
>
(
::
sinf
(
type_convert
<
float
>
(
x
)));
};
template
<
>
CK_TILE_DEVICE
float
sin
<
float
>
(
float
x
)
{
return
::
sinf
(
x
);
};
template
<
>
CK_TILE_DEVICE
double
sin
<
double
>
(
double
x
)
{
return
::
sin
(
x
);
};
template
<
>
CK_TILE_DEVICE
fp16_t
sin
<
fp16_t
>
(
fp16_t
x
)
{
return
__ocml_sin_f16
(
x
);
};
template
<
typename
T
>
CK_TILE_DEVICE
T
asin
(
T
x
)
{
return
type_convert
<
T
>
(
::
asinf
(
type_convert
<
float
>
(
x
)));
};
template
<
>
CK_TILE_DEVICE
float
asin
<
float
>
(
float
x
)
{
return
::
asinf
(
x
);
};
template
<
>
CK_TILE_DEVICE
double
asin
<
double
>
(
double
x
)
{
return
::
asin
(
x
);
};
template
<
typename
T
>
CK_TILE_DEVICE
T
asinh
(
T
x
)
{
return
type_convert
<
T
>
(
::
asinhf
(
type_convert
<
float
>
(
x
)));
};
template
<
>
CK_TILE_DEVICE
float
asinh
<
float
>
(
float
x
)
{
return
::
asinhf
(
x
);
};
template
<
>
CK_TILE_DEVICE
double
asinh
<
double
>
(
double
x
)
{
return
::
asinh
(
x
);
};
template
<
typename
T
>
CK_TILE_DEVICE
T
acosh
(
T
x
)
{
return
type_convert
<
T
>
(
::
acoshf
(
type_convert
<
float
>
(
x
)));
};
template
<
>
CK_TILE_DEVICE
float
acosh
<
float
>
(
float
x
)
{
return
::
acoshf
(
x
);
};
template
<
>
CK_TILE_DEVICE
double
acosh
<
double
>
(
double
x
)
{
return
::
acosh
(
x
);
};
template
<
typename
T
>
CK_TILE_DEVICE
T
tan
(
T
x
)
{
return
type_convert
<
T
>
(
::
tanf
(
type_convert
<
float
>
(
x
)));
};
template
<
>
CK_TILE_DEVICE
float
tan
<
float
>
(
float
x
)
{
return
::
tanf
(
x
);
};
template
<
>
CK_TILE_DEVICE
double
tan
<
double
>
(
double
x
)
{
return
::
tan
(
x
);
};
template
<
typename
T
>
CK_TILE_DEVICE
T
atanh
(
T
x
)
{
return
type_convert
<
T
>
(
::
atanhf
(
type_convert
<
float
>
(
x
)));
};
template
<
>
CK_TILE_DEVICE
float
atanh
<
float
>
(
float
x
)
{
return
::
atanhf
(
x
);
};
template
<
>
CK_TILE_DEVICE
double
atanh
<
double
>
(
double
x
)
{
return
::
atanh
(
x
);
};
template
<
typename
T
>
CK_TILE_DEVICE
T
sinh
(
T
x
)
{
return
type_convert
<
T
>
(
::
sinhf
(
type_convert
<
float
>
(
x
)));
};
template
<
>
CK_TILE_DEVICE
float
sinh
<
float
>
(
float
x
)
{
return
::
sinhf
(
x
);
};
template
<
>
CK_TILE_DEVICE
double
sinh
<
double
>
(
double
x
)
{
return
::
sinh
(
x
);
};
template
<
typename
T
>
CK_TILE_DEVICE
T
ceil
(
T
x
)
{
return
type_convert
<
T
>
(
::
ceilf
(
type_convert
<
float
>
(
x
)));
};
template
<
>
CK_TILE_DEVICE
float
ceil
<
float
>
(
float
x
)
{
return
::
ceilf
(
x
);
};
template
<
>
CK_TILE_DEVICE
double
ceil
<
double
>
(
double
x
)
{
return
::
ceil
(
x
);
};
template
<
>
CK_TILE_DEVICE
fp16_t
ceil
<
fp16_t
>
(
fp16_t
x
)
{
return
__ocml_ceil_f16
(
x
);
};
template
<
typename
T
>
CK_TILE_DEVICE
T
cosh
(
T
x
)
{
return
type_convert
<
T
>
(
::
coshf
(
type_convert
<
float
>
(
x
)));
};
template
<
>
CK_TILE_DEVICE
float
cosh
<
float
>
(
float
x
)
{
return
::
coshf
(
x
);
};
template
<
>
CK_TILE_DEVICE
double
cosh
<
double
>
(
double
x
)
{
return
::
cosh
(
x
);
};
template
<
typename
T
>
CK_TILE_DEVICE
T
floor
(
T
x
)
{
return
type_convert
<
T
>
(
::
floorf
(
type_convert
<
float
>
(
x
)));
};
template
<
>
CK_TILE_DEVICE
float
floor
<
float
>
(
float
x
)
{
return
::
floorf
(
x
);
};
template
<
>
CK_TILE_DEVICE
double
floor
<
double
>
(
double
x
)
{
return
::
floor
(
x
);
};
template
<
>
CK_TILE_DEVICE
fp16_t
floor
<
fp16_t
>
(
fp16_t
x
)
{
return
__ocml_floor_f16
(
x
);
};
template
<
typename
T
>
CK_TILE_DEVICE
T
rcp
(
T
x
)
{
#if !CK_TILE_WORKAROUND_SWDEV_383542
return
__frcp_rn
(
x
);
#else
// return __ocml_native_recip_f32(x);
return
__builtin_amdgcn_rcpf
(
x
);
#endif
};
template
<
typename
T
>
CK_TILE_DEVICE
T
exp
(
T
x
)
{
return
type_convert
<
T
>
(
__ocml_exp_f32
(
type_convert
<
float
>
(
x
)));
};
template
<
>
CK_TILE_DEVICE
fp16_t
exp
<
fp16_t
>
(
fp16_t
x
)
{
return
__ocml_exp_f16
(
x
);
};
template
<
>
CK_TILE_DEVICE
float
exp
<
float
>
(
float
x
)
{
return
__ocml_exp_f32
(
x
);
};
template
<
>
CK_TILE_DEVICE
double
exp
<
double
>
(
double
x
)
{
return
exp
(
x
);
};
template
<
typename
T
>
CK_TILE_DEVICE
T
log
(
T
x
)
{
return
type_convert
<
T
>
(
__logf
(
type_convert
<
float
>
(
x
)));
};
template
<
>
CK_TILE_DEVICE
fp16_t
log
<
fp16_t
>
(
fp16_t
x
)
{
return
__ocml_log_f16
(
x
);
};
template
<
>
CK_TILE_DEVICE
float
log
<
float
>
(
float
x
)
{
return
__logf
(
x
);
};
template
<
>
CK_TILE_DEVICE
double
log
<
double
>
(
double
x
)
{
return
log
(
x
);
};
template
<
typename
T
>
CK_TILE_DEVICE
T
pow
(
T
x
,
T
gamma
)
{
return
type_convert
<
T
>
(
powf
(
type_convert
<
float
>
(
x
),
type_convert
<
float
>
(
gamma
)));
};
template
<
>
CK_TILE_DEVICE
float
pow
<
float
>
(
float
x
,
float
gamma
)
{
return
powf
(
x
,
gamma
);
};
template
<
>
CK_TILE_DEVICE
double
pow
<
double
>
(
double
x
,
double
gamma
)
{
return
pow
(
x
,
gamma
);
};
template
<
typename
T
>
CK_TILE_DEVICE
T
expm1
(
T
x
)
{
return
type_convert
<
T
>
(
expm1f
(
type_convert
<
float
>
(
x
)));
};
template
<
>
CK_TILE_DEVICE
float
expm1
<
float
>
(
float
x
)
{
return
expm1f
(
x
);
};
template
<
>
CK_TILE_DEVICE
double
expm1
<
double
>
(
double
x
)
{
return
expm1
(
x
);
};
}
// namespace ck_tile
include/ck_tile/core/numeric/type_convert.hpp
View file @
7d50244e
...
...
@@ -10,6 +10,7 @@
#include "ck_tile/core/numeric/half.hpp"
#include "ck_tile/core/numeric/bfloat16.hpp"
#include "ck_tile/core/numeric/float8.hpp"
#include "ck_tile/core/numeric/int8.hpp"
namespace
ck_tile
{
...
...
@@ -60,6 +61,9 @@ CK_TILE_TYPE_CONVERT(bf16_t, bf16, float, float)
CK_TILE_TYPE_CONVERT
(
fp8_t
,
fp8
,
float
,
float
)
CK_TILE_TYPE_CONVERT
(
bf8_t
,
bf8
,
float
,
float
)
CK_TILE_TYPE_CONVERT
(
float
,
float
,
int8_t
,
int8
)
CK_TILE_TYPE_CONVERT
(
int8_t
,
int8
,
float
,
float
)
#undef CK_TILE_TYPE_CONVERT
#endif
...
...
include/ck_tile/core/tensor/buffer_view.hpp
View file @
7d50244e
...
...
@@ -91,8 +91,10 @@ struct buffer_view<address_space_enum::generic,
std
::
is_same
<
typename
vector_traits
<
remove_cvref_t
<
X
>
>::
scalar_type
,
typename
vector_traits
<
remove_cvref_t
<
T
>>::
scalar_type
>::
value
,
bool
>::
type
=
false
>
CK_TILE_DEVICE
constexpr
auto
get
(
index_t
i
,
bool
is_valid_element
,
bool_constant
<
oob_conditional_check
>
=
{})
const
CK_TILE_DEVICE
constexpr
auto
get
(
index_t
i
,
index_t
linear_offset
,
bool
is_valid_element
,
bool_constant
<
oob_conditional_check
>
=
{})
const
{
// X contains multiple T
constexpr
index_t
scalar_per_t_vector
=
vector_traits
<
remove_cvref_t
<
T
>>::
vector_size
;
...
...
@@ -107,11 +109,11 @@ struct buffer_view<address_space_enum::generic,
#if CK_TILE_EXPERIMENTAL_USE_MEMCPY_FOR_VECTOR_ACCESS
X
tmp
;
__builtin_memcpy
(
&
tmp
,
&
(
p_data_
[
i
]),
sizeof
(
X
));
__builtin_memcpy
(
&
tmp
,
&
(
p_data_
[
i
+
linear_offset
]),
sizeof
(
X
));
return
tmp
;
#else
return
*
c_style_pointer_cast
<
const
X
*>
(
&
p_data_
[
i
]);
return
*
c_style_pointer_cast
<
const
X
*>
(
&
p_data_
[
i
+
linear_offset
]);
#endif
}
else
...
...
@@ -134,17 +136,17 @@ struct buffer_view<address_space_enum::generic,
std
::
is_same
<
typename
vector_traits
<
remove_cvref_t
<
X
>
>::
scalar_type
,
typename
vector_traits
<
remove_cvref_t
<
T
>>::
scalar_type
>::
value
,
bool
>::
type
=
false
>
CK_TILE_DEVICE
void
update
(
index_t
i
,
bool
is_valid_element
,
const
X
&
x
)
CK_TILE_DEVICE
void
update
(
index_t
i
,
index_t
linear_offset
,
bool
is_valid_element
,
const
X
&
x
)
{
if
constexpr
(
Op
==
memory_operation_enum
::
set
)
{
this
->
template
set
<
X
>(
i
,
is_valid_element
,
x
);
this
->
template
set
<
X
>(
i
,
linear_offset
,
is_valid_element
,
x
);
}
// FIXME: remove memory_operation_enum::add
else
if
constexpr
(
Op
==
memory_operation_enum
::
add
)
{
auto
tmp
=
this
->
template
get
<
X
>(
i
,
is_valid_element
);
this
->
template
set
<
X
>(
i
,
is_valid_element
,
x
+
tmp
);
auto
tmp
=
this
->
template
get
<
X
>(
i
,
linear_offset
,
is_valid_element
);
this
->
template
set
<
X
>(
i
,
linear_offset
,
is_valid_element
,
x
+
tmp
);
}
}
...
...
@@ -154,7 +156,7 @@ struct buffer_view<address_space_enum::generic,
std
::
is_same
<
typename
vector_traits
<
remove_cvref_t
<
X
>
>::
scalar_type
,
typename
vector_traits
<
remove_cvref_t
<
T
>>::
scalar_type
>::
value
,
bool
>::
type
=
false
>
CK_TILE_DEVICE
void
set
(
index_t
i
,
bool
is_valid_element
,
const
X
&
x
)
CK_TILE_DEVICE
void
set
(
index_t
i
,
index_t
linear_offset
,
bool
is_valid_element
,
const
X
&
x
)
{
// X contains multiple T
constexpr
index_t
scalar_per_t_vector
=
vector_traits
<
remove_cvref_t
<
T
>>::
vector_size
;
...
...
@@ -169,9 +171,9 @@ struct buffer_view<address_space_enum::generic,
#if CK_TILE_EXPERIMENTAL_USE_MEMCPY_FOR_VECTOR_ACCESS
X
tmp
=
x
;
__builtin_memcpy
(
&
(
p_data_
[
i
]),
&
tmp
,
sizeof
(
X
));
__builtin_memcpy
(
&
(
p_data_
[
i
+
linear_offset
]),
&
tmp
,
sizeof
(
X
));
#else
*
c_style_pointer_cast
<
X
*>
(
&
p_data_
[
i
])
=
x
;
*
c_style_pointer_cast
<
X
*>
(
&
p_data_
[
i
+
linear_offset
])
=
x
;
#endif
}
}
...
...
@@ -276,8 +278,10 @@ struct buffer_view<address_space_enum::global,
std
::
is_same
<
typename
vector_traits
<
remove_cvref_t
<
X
>
>::
scalar_type
,
typename
vector_traits
<
remove_cvref_t
<
T
>>::
scalar_type
>::
value
,
bool
>::
type
=
false
>
CK_TILE_DEVICE
constexpr
auto
get
(
index_t
i
,
bool
is_valid_element
,
bool_constant
<
oob_conditional_check
>
=
{})
const
CK_TILE_DEVICE
constexpr
auto
get
(
index_t
i
,
index_t
linear_offset
,
bool
is_valid_element
,
bool_constant
<
oob_conditional_check
>
=
{})
const
{
// X contains multiple T
constexpr
index_t
scalar_per_t_vector
=
vector_traits
<
remove_cvref_t
<
T
>>::
vector_size
;
...
...
@@ -303,7 +307,7 @@ struct buffer_view<address_space_enum::global,
t_per_x
,
Coherence
,
oob_conditional_check
>
(
p_data_
,
i
,
is_valid_element
,
buffer_size_
);
p_data_
,
i
+
linear_offset
,
is_valid_element
,
buffer_size_
);
}
else
{
...
...
@@ -311,8 +315,11 @@ struct buffer_view<address_space_enum::global,
remove_cvref_t
<
T
>
,
t_per_x
,
Coherence
,
oob_conditional_check
>
(
p_data_
,
i
,
is_valid_element
,
buffer_size_
,
invalid_element_value_
);
oob_conditional_check
>
(
p_data_
,
i
+
linear_offset
,
is_valid_element
,
buffer_size_
,
invalid_element_value_
);
}
}
else
...
...
@@ -322,11 +329,11 @@ struct buffer_view<address_space_enum::global,
#if CK_TILE_EXPERIMENTAL_USE_MEMCPY_FOR_VECTOR_ACCESS
X
tmp
;
__builtin_memcpy
(
&
tmp
,
&
(
p_data_
[
i
]),
sizeof
(
X
));
__builtin_memcpy
(
&
tmp
,
&
(
p_data_
[
i
+
linear_offset
]),
sizeof
(
X
));
return
tmp
;
#else
return
*
c_style_pointer_cast
<
const
X
*>
(
&
p_data_
[
i
]);
return
*
c_style_pointer_cast
<
const
X
*>
(
&
p_data_
[
i
+
linear_offset
]);
#endif
}
else
...
...
@@ -352,7 +359,8 @@ struct buffer_view<address_space_enum::global,
typename
vector_traits
<
remove_cvref_t
<
T
>>::
scalar_type
>::
value
,
bool
>::
type
=
false
>
CK_TILE_DEVICE
constexpr
auto
get_raw
(
remove_cvref_t
<
X
>&
dst
,
index_t
i
,
index_t
v_offset
,
index_t
i_offset
,
bool
is_valid_element
,
bool_constant
<
pre_nop
>
=
{})
const
{
...
...
@@ -366,7 +374,38 @@ struct buffer_view<address_space_enum::global,
constexpr
index_t
t_per_x
=
scalar_per_x_vector
/
scalar_per_t_vector
;
amd_buffer_load_raw
<
remove_cvref_t
<
T
>
,
t_per_x
,
Coherence
,
oob_conditional_check
,
pre_nop
>
(
dst
,
cached_buf_res_
,
i
,
is_valid_element
,
bool_constant
<
pre_nop
>
{});
dst
,
cached_buf_res_
,
v_offset
,
i_offset
,
is_valid_element
,
bool_constant
<
pre_nop
>
{});
}
// i is offset of T, not X. i should be aligned to X
template
<
typename
X
,
bool
oob_conditional_check
=
true
,
typename
std
::
enable_if
<
std
::
is_same
<
typename
vector_traits
<
remove_cvref_t
<
X
>
>::
scalar_type
,
typename
vector_traits
<
remove_cvref_t
<
T
>>::
scalar_type
>::
value
,
bool
>::
type
=
false
>
CK_TILE_DEVICE
constexpr
auto
async_get
(
CK_TILE_LDS_ADDR
remove_cvref_t
<
T
>*
smem
,
index_t
i
,
index_t
linear_offset
,
bool
is_valid_element
,
bool_constant
<
oob_conditional_check
>
=
{})
const
{
// X is vector of T
constexpr
index_t
scalar_per_t_vector
=
vector_traits
<
remove_cvref_t
<
T
>>::
vector_size
;
constexpr
index_t
scalar_per_x_vector
=
vector_traits
<
remove_cvref_t
<
X
>>::
vector_size
;
static_assert
(
scalar_per_x_vector
%
scalar_per_t_vector
==
0
,
"wrong! X should contain multiple T"
);
constexpr
index_t
t_per_x
=
scalar_per_x_vector
/
scalar_per_t_vector
;
amd_async_buffer_load_with_oob
<
remove_cvref_t
<
T
>
,
t_per_x
,
Coherence
>
(
smem
,
cached_buf_res_
,
i
,
linear_offset
,
is_valid_element
,
bool_constant
<
oob_conditional_check
>
{});
}
// i is offset of T, not X. i should be aligned to X
...
...
@@ -378,6 +417,7 @@ struct buffer_view<address_space_enum::global,
bool
>::
type
=
false
>
CK_TILE_DEVICE
constexpr
auto
async_get_raw
(
remove_cvref_t
<
T
>*
smem
,
index_t
i
,
index_t
linear_offset
,
bool
/*is_valid_element*/
,
bool_constant
<
pre_nop
>
=
{})
const
{
...
...
@@ -391,7 +431,7 @@ struct buffer_view<address_space_enum::global,
constexpr
index_t
t_per_x
=
scalar_per_x_vector
/
scalar_per_t_vector
;
amd_async_buffer_load_with_oob_raw
<
remove_cvref_t
<
T
>
,
t_per_x
,
Coherence
>
(
smem
,
cached_buf_res_
,
i
,
bool_constant
<
pre_nop
>
{});
smem
,
cached_buf_res_
,
i
,
linear_offset
,
bool_constant
<
pre_nop
>
{});
}
// i is offset of T, not X. i should be aligned to X
...
...
@@ -401,25 +441,25 @@ struct buffer_view<address_space_enum::global,
std
::
is_same
<
typename
vector_traits
<
remove_cvref_t
<
X
>
>::
scalar_type
,
typename
vector_traits
<
remove_cvref_t
<
T
>>::
scalar_type
>::
value
,
bool
>::
type
=
false
>
CK_TILE_DEVICE
void
update
(
index_t
i
,
bool
is_valid_element
,
const
X
&
x
)
CK_TILE_DEVICE
void
update
(
index_t
i
,
index_t
linear_offset
,
bool
is_valid_element
,
const
X
&
x
)
{
if
constexpr
(
Op
==
memory_operation_enum
::
set
)
{
this
->
template
set
<
X
>(
i
,
is_valid_element
,
x
);
this
->
template
set
<
X
>(
i
,
linear_offset
,
is_valid_element
,
x
);
}
else
if
constexpr
(
Op
==
memory_operation_enum
::
atomic_add
)
{
this
->
template
atomic_add
<
X
>(
i
,
is_valid_element
,
x
);
this
->
template
atomic_add
<
X
>(
i
,
linear_offset
,
is_valid_element
,
x
);
}
else
if
constexpr
(
Op
==
memory_operation_enum
::
atomic_max
)
{
this
->
template
atomic_max
<
X
>(
i
,
is_valid_element
,
x
);
this
->
template
atomic_max
<
X
>(
i
,
linear_offset
,
is_valid_element
,
x
);
}
// FIXME: remove memory_operation_enum::add
else
if
constexpr
(
Op
==
memory_operation_enum
::
add
)
{
auto
tmp
=
this
->
template
get
<
X
>(
i
,
is_valid_element
);
this
->
template
set
<
X
>(
i
,
is_valid_element
,
x
+
tmp
);
auto
tmp
=
this
->
template
get
<
X
>(
i
,
linear_offset
,
is_valid_element
);
this
->
template
set
<
X
>(
i
,
linear_offset
,
is_valid_element
,
x
+
tmp
);
// tmp += x;
// this->template set<X>(i, is_valid_element, tmp);
}
...
...
@@ -432,7 +472,7 @@ struct buffer_view<address_space_enum::global,
std
::
is_same
<
typename
vector_traits
<
remove_cvref_t
<
X
>
>::
scalar_type
,
typename
vector_traits
<
remove_cvref_t
<
T
>>::
scalar_type
>::
value
,
bool
>::
type
=
false
>
CK_TILE_DEVICE
void
set
(
index_t
i
,
bool
is_valid_element
,
const
X
&
x
)
CK_TILE_DEVICE
void
set
(
index_t
i
,
index_t
linear_offset
,
bool
is_valid_element
,
const
X
&
x
)
{
// X contains multiple T
constexpr
index_t
scalar_per_t_vector
=
vector_traits
<
remove_cvref_t
<
T
>>::
vector_size
;
...
...
@@ -453,7 +493,7 @@ struct buffer_view<address_space_enum::global,
constexpr
index_t
t_per_x
=
scalar_per_x_vector
/
scalar_per_t_vector
;
amd_buffer_store
<
remove_cvref_t
<
T
>
,
t_per_x
,
Coherence
>
(
x
,
p_data_
,
i
,
is_valid_element
,
buffer_size_
);
x
,
p_data_
,
i
+
linear_offset
,
is_valid_element
,
buffer_size_
);
}
else
{
...
...
@@ -462,9 +502,9 @@ struct buffer_view<address_space_enum::global,
#if CK_TILE_EXPERIMENTAL_USE_MEMCPY_FOR_VECTOR_ACCESS
X
tmp
=
x
;
__builtin_memcpy
(
&
(
p_data_
[
i
]),
&
tmp
,
sizeof
(
X
));
__builtin_memcpy
(
&
(
p_data_
[
i
+
linear_offset
]),
&
tmp
,
sizeof
(
X
));
#else
*
c_style_pointer_cast
<
X
*>
(
&
p_data_
[
i
])
=
x
;
*
c_style_pointer_cast
<
X
*>
(
&
p_data_
[
i
+
linear_offset
])
=
x
;
#endif
}
}
...
...
@@ -477,7 +517,7 @@ struct buffer_view<address_space_enum::global,
std
::
is_same
<
typename
vector_traits
<
remove_cvref_t
<
X
>
>::
scalar_type
,
typename
vector_traits
<
remove_cvref_t
<
T
>>::
scalar_type
>::
value
,
bool
>::
type
=
false
>
CK_TILE_DEVICE
void
set_raw
(
index_t
i
,
bool
is_valid_element
,
const
X
&
x
)
CK_TILE_DEVICE
void
set_raw
(
index_t
i
,
index_t
linear_offset
,
bool
is_valid_element
,
const
X
&
x
)
{
// X contains multiple T
constexpr
index_t
scalar_per_t_vector
=
vector_traits
<
remove_cvref_t
<
T
>>::
vector_size
;
...
...
@@ -489,7 +529,7 @@ struct buffer_view<address_space_enum::global,
constexpr
index_t
t_per_x
=
scalar_per_x_vector
/
scalar_per_t_vector
;
amd_buffer_store_raw
<
remove_cvref_t
<
T
>
,
t_per_x
,
Coherence
,
oob_conditional_check
>
(
x
,
p_data_
,
i
,
is_valid_element
,
buffer_size_
);
x
,
p_data_
,
i
,
linear_offset
,
is_valid_element
,
buffer_size_
);
}
template
<
typename
X
,
...
...
@@ -497,7 +537,8 @@ struct buffer_view<address_space_enum::global,
std
::
is_same
<
typename
vector_traits
<
remove_cvref_t
<
X
>
>::
scalar_type
,
typename
vector_traits
<
remove_cvref_t
<
T
>>::
scalar_type
>::
value
,
bool
>::
type
=
false
>
CK_TILE_DEVICE
void
atomic_add
(
index_t
i
,
bool
is_valid_element
,
const
X
&
x
)
CK_TILE_DEVICE
void
atomic_add
(
index_t
i
,
index_t
linear_offset
,
bool
is_valid_element
,
const
X
&
x
)
{
using
scalar_t
=
typename
vector_traits
<
remove_cvref_t
<
T
>>::
scalar_type
;
...
...
@@ -532,13 +573,13 @@ struct buffer_view<address_space_enum::global,
if
constexpr
(
use_amd_buffer_addressing
)
{
amd_buffer_atomic_add
<
remove_cvref_t
<
T
>
,
t_per_x
>
(
x
,
p_data_
,
i
,
is_valid_element
,
buffer_size_
);
x
,
p_data_
,
i
+
linear_offset
,
is_valid_element
,
buffer_size_
);
}
else
{
if
(
is_valid_element
)
{
atomic_add_g
<
remove_cvref_t
<
T
>
,
t_per_x
>
(
&
p_data_
[
i
],
x
);
atomic_add_g
<
remove_cvref_t
<
T
>
,
t_per_x
>
(
&
p_data_
[
i
+
linear_offset
],
x
);
}
}
}
...
...
@@ -548,7 +589,8 @@ struct buffer_view<address_space_enum::global,
std
::
is_same
<
typename
vector_traits
<
remove_cvref_t
<
X
>
>::
scalar_type
,
typename
vector_traits
<
remove_cvref_t
<
T
>>::
scalar_type
>::
value
,
bool
>::
type
=
false
>
CK_TILE_DEVICE
void
atomic_max
(
index_t
i
,
bool
is_valid_element
,
const
X
&
x
)
CK_TILE_DEVICE
void
atomic_max
(
index_t
i
,
index_t
linear_offset
,
bool
is_valid_element
,
const
X
&
x
)
{
// X contains multiple T
constexpr
index_t
scalar_per_t_vector
=
vector_traits
<
remove_cvref_t
<
T
>>::
vector_size
;
...
...
@@ -572,11 +614,11 @@ struct buffer_view<address_space_enum::global,
if
constexpr
(
use_amd_buffer_addressing
)
{
amd_buffer_atomic_max
<
remove_cvref_t
<
T
>
,
t_per_x
>
(
x
,
p_data_
,
i
,
is_valid_element
,
buffer_size_
);
x
,
p_data_
,
i
+
linear_offset
,
is_valid_element
,
buffer_size_
);
}
else
if
(
is_valid_element
)
{
atomic_max_g
<
remove_cvref_t
<
T
>
,
t_per_x
>
(
&
p_data_
[
i
],
x
);
atomic_max_g
<
remove_cvref_t
<
T
>
,
t_per_x
>
(
&
p_data_
[
i
+
linear_offset
],
x
);
}
}
...
...
@@ -668,8 +710,10 @@ struct buffer_view<address_space_enum::lds,
std
::
is_same
<
typename
vector_traits
<
remove_cvref_t
<
X
>
>::
scalar_type
,
typename
vector_traits
<
remove_cvref_t
<
T
>>::
scalar_type
>::
value
,
bool
>::
type
=
false
>
CK_TILE_DEVICE
constexpr
auto
get
(
index_t
i
,
bool
is_valid_element
,
bool_constant
<
oob_conditional_check
>
=
{})
const
CK_TILE_DEVICE
constexpr
auto
get
(
index_t
i
,
index_t
linear_offset
,
bool
is_valid_element
,
bool_constant
<
oob_conditional_check
>
=
{})
const
{
// X contains multiple T
constexpr
index_t
scalar_per_t_vector
=
vector_traits
<
remove_cvref_t
<
T
>>::
vector_size
;
...
...
@@ -684,14 +728,14 @@ struct buffer_view<address_space_enum::lds,
#if CK_TILE_EXPERIMENTAL_USE_MEMCPY_FOR_VECTOR_ACCESS
X
tmp
;
__builtin_memcpy
(
&
tmp
,
&
(
p_data_
[
i
]),
sizeof
(
X
));
__builtin_memcpy
(
&
tmp
,
&
(
p_data_
[
i
+
linear_offset
]),
sizeof
(
X
));
return
tmp
;
#else
using
buf_t
=
ext_vector_t
<
typename
vector_traits
<
remove_cvref_t
<
T
>>::
scalar_type
,
scalar_per_t_vector
*
scalar_per_x_vector
>
;
// using buf_t = ushort __attribute__((ext_vector_type(8)));
auto
rtn
=
*
c_style_pointer_cast
<
const
buf_t
*>
(
&
p_data_
[
i
]);
auto
rtn
=
*
c_style_pointer_cast
<
const
buf_t
*>
(
&
p_data_
[
i
+
linear_offset
]);
return
bit_cast
<
X
>
(
rtn
);
#endif
}
...
...
@@ -708,6 +752,23 @@ struct buffer_view<address_space_enum::lds,
}
}
// i is offset of T, not X. i should be aligned to X
template
<
typename
X
,
bool
oob_conditional_check
=
true
,
bool
pre_nop
=
false
,
typename
std
::
enable_if
<
std
::
is_same
<
typename
vector_traits
<
remove_cvref_t
<
X
>
>::
scalar_type
,
typename
vector_traits
<
remove_cvref_t
<
T
>>::
scalar_type
>::
value
,
bool
>::
type
=
false
>
CK_TILE_DEVICE
constexpr
auto
get_raw
(
remove_cvref_t
<
X
>&
dst
,
index_t
v_offset
,
index_t
i_offset
,
bool
/*is_valid_element*/
,
bool_constant
<
pre_nop
>
=
{})
const
{
smem_load
<
sizeof
(
X
)
>
{}(
dst
,
v_offset
*
sizeof
(
T
),
i_offset
*
sizeof
(
T
));
}
// i is offset of T, not X. i should be aligned to X
template
<
memory_operation_enum
Op
,
typename
X
,
...
...
@@ -715,17 +776,17 @@ struct buffer_view<address_space_enum::lds,
std
::
is_same
<
typename
vector_traits
<
remove_cvref_t
<
X
>
>::
scalar_type
,
typename
vector_traits
<
remove_cvref_t
<
T
>>::
scalar_type
>::
value
,
bool
>::
type
=
false
>
CK_TILE_DEVICE
void
update
(
index_t
i
,
bool
is_valid_element
,
const
X
&
x
)
CK_TILE_DEVICE
void
update
(
index_t
i
,
index_t
linear_offset
,
bool
is_valid_element
,
const
X
&
x
)
{
if
constexpr
(
Op
==
memory_operation_enum
::
set
)
{
this
->
template
set
<
X
>(
i
,
is_valid_element
,
x
);
this
->
template
set
<
X
>(
i
,
linear_offset
,
is_valid_element
,
x
);
}
// FIXME: remove memory_operation_enum::add
else
if
constexpr
(
Op
==
memory_operation_enum
::
add
)
{
auto
tmp
=
this
->
template
get
<
X
>(
i
,
is_valid_element
);
this
->
template
set
<
X
>(
i
,
is_valid_element
,
x
+
tmp
);
auto
tmp
=
this
->
template
get
<
X
>(
i
,
linear_offset
,
is_valid_element
);
this
->
template
set
<
X
>(
i
,
linear_offset
,
is_valid_element
,
x
+
tmp
);
}
}
...
...
@@ -735,7 +796,7 @@ struct buffer_view<address_space_enum::lds,
std
::
is_same
<
typename
vector_traits
<
remove_cvref_t
<
X
>
>::
scalar_type
,
typename
vector_traits
<
remove_cvref_t
<
T
>>::
scalar_type
>::
value
,
bool
>::
type
=
false
>
CK_TILE_DEVICE
void
set
(
index_t
i
,
bool
is_valid_element
,
const
X
&
x
)
CK_TILE_DEVICE
void
set
(
index_t
i
,
index_t
linear_offset
,
bool
is_valid_element
,
const
X
&
x
)
{
// X contains multiple T
constexpr
index_t
scalar_per_t_vector
=
vector_traits
<
remove_cvref_t
<
T
>>::
vector_size
;
...
...
@@ -751,6 +812,7 @@ struct buffer_view<address_space_enum::lds,
bool
constexpr
workaround_int8_ds_write_issue
=
false
;
#endif
i
+=
linear_offset
;
// simplicity
if
constexpr
(
std
::
is_same
<
typename
vector_traits
<
remove_cvref_t
<
T
>>::
scalar_type
,
int8_t
>::
value
&&
workaround_int8_ds_write_issue
)
...
...
@@ -952,8 +1014,10 @@ struct buffer_view<address_space_enum::vgpr,
std
::
is_same
<
typename
vector_traits
<
remove_cvref_t
<
X
>
>::
scalar_type
,
typename
vector_traits
<
remove_cvref_t
<
T
>>::
scalar_type
>::
value
,
bool
>::
type
=
false
>
CK_TILE_DEVICE
constexpr
auto
get
(
index_t
i
,
bool
is_valid_element
,
bool_constant
<
oob_conditional_check
>
=
{})
const
CK_TILE_DEVICE
constexpr
auto
get
(
index_t
i
,
index_t
/*linear_offset*/
,
bool
is_valid_element
,
bool_constant
<
oob_conditional_check
>
=
{})
const
{
// X contains multiple T
constexpr
index_t
scalar_per_t_vector
=
vector_traits
<
remove_cvref_t
<
T
>>::
vector_size
;
...
...
@@ -995,17 +1059,17 @@ struct buffer_view<address_space_enum::vgpr,
std
::
is_same
<
typename
vector_traits
<
remove_cvref_t
<
X
>
>::
scalar_type
,
typename
vector_traits
<
remove_cvref_t
<
T
>>::
scalar_type
>::
value
,
bool
>::
type
=
false
>
CK_TILE_DEVICE
void
update
(
index_t
i
,
bool
is_valid_element
,
const
X
&
x
)
CK_TILE_DEVICE
void
update
(
index_t
i
,
index_t
linear_offset
,
bool
is_valid_element
,
const
X
&
x
)
{
if
constexpr
(
Op
==
memory_operation_enum
::
set
)
{
this
->
template
set
<
X
>(
i
,
is_valid_element
,
x
);
this
->
template
set
<
X
>(
i
,
linear_offset
,
is_valid_element
,
x
);
}
// FIXME: remove memory_operation_enum::add
else
if
constexpr
(
Op
==
memory_operation_enum
::
add
)
{
auto
tmp
=
this
->
template
get
<
X
>(
i
,
is_valid_element
);
this
->
template
set
<
X
>(
i
,
is_valid_element
,
x
+
tmp
);
auto
tmp
=
this
->
template
get
<
X
>(
i
,
linear_offset
,
is_valid_element
);
this
->
template
set
<
X
>(
i
,
linear_offset
,
is_valid_element
,
x
+
tmp
);
}
}
...
...
@@ -1015,7 +1079,7 @@ struct buffer_view<address_space_enum::vgpr,
std
::
is_same
<
typename
vector_traits
<
remove_cvref_t
<
X
>
>::
scalar_type
,
typename
vector_traits
<
remove_cvref_t
<
T
>>::
scalar_type
>::
value
,
bool
>::
type
=
false
>
CK_TILE_DEVICE
void
set
(
index_t
i
,
bool
is_valid_element
,
const
X
&
x
)
CK_TILE_DEVICE
void
set
(
index_t
i
,
index_t
linear_offset
,
bool
is_valid_element
,
const
X
&
x
)
{
// X contains multiple T
constexpr
index_t
scalar_per_t_vector
=
vector_traits
<
remove_cvref_t
<
T
>>::
vector_size
;
...
...
@@ -1030,9 +1094,9 @@ struct buffer_view<address_space_enum::vgpr,
#if CK_TILE_EXPERIMENTAL_USE_MEMCPY_FOR_VECTOR_ACCESS
X
tmp
=
x
;
__builtin_memcpy
(
&
(
p_data_
[
i
]),
&
tmp
,
sizeof
(
X
));
__builtin_memcpy
(
&
(
p_data_
[
i
+
linear_offset
]),
&
tmp
,
sizeof
(
X
));
#else
*
c_style_pointer_cast
<
X
*>
(
&
p_data_
[
i
])
=
x
;
*
c_style_pointer_cast
<
X
*>
(
&
p_data_
[
i
+
linear_offset
])
=
x
;
#endif
}
}
...
...
include/ck_tile/core/tensor/load_tile.hpp
View file @
7d50244e
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-202
3
, Advanced Micro Devices, Inc. All rights reserved.
// Copyright (c) 2018-202
4
, Advanced Micro Devices, Inc. All rights reserved.
#pragma once
...
...
@@ -12,6 +12,7 @@
#include "ck_tile/core/tensor/tile_window.hpp"
#include "ck_tile/core/utility/type_traits.hpp"
#include "ck_tile/core/tensor/tile_window.hpp"
#include "ck_tile/core/tensor/tile_window_linear.hpp"
#include "ck_tile/core/tensor/null_tile_window.hpp"
#include "ck_tile/core/tensor/null_tensor.hpp"
...
...
@@ -28,9 +29,48 @@ CK_TILE_DEVICE auto load_tile(const tile_window_with_static_distribution<BottomT
NumCoord
>&
tile_window
,
bool_constant
<
oob_conditional_check
>
=
{})
{
return
tile_window
.
load
(
bool_constant
<
oob_conditional_check
>
{});
return
tile_window
.
load
(
number
<-
1
>
{},
bool_constant
<
oob_conditional_check
>
{});
}
template
<
typename
BottomTensorView_
,
typename
WindowLengths_
,
typename
TileDistribution_
,
typename
LinearBottomDims_
,
bool
oob_conditional_check
=
true
>
CK_TILE_DEVICE
auto
load_tile
(
const
tile_window_linear
<
BottomTensorView_
,
WindowLengths_
,
TileDistribution_
,
LinearBottomDims_
>&
tile_window
,
bool_constant
<
oob_conditional_check
>
=
{})
{
return
tile_window
.
load
(
number
<-
1
>
{},
bool_constant
<
oob_conditional_check
>
{});
}
template
<
typename
DistributedTensor_
,
typename
BottomTensorView_
,
typename
WindowLengths_
,
typename
TileDistribution_
,
index_t
NumCoord
,
bool
oob_conditional_check
=
true
>
CK_TILE_DEVICE
auto
load_tile
(
DistributedTensor_
&
dst_tile
,
const
tile_window_with_static_distribution
<
BottomTensorView_
,
WindowLengths_
,
TileDistribution_
,
NumCoord
>&
tile_window
,
bool_constant
<
oob_conditional_check
>
=
{})
{
return
tile_window
.
load
(
dst_tile
,
bool_constant
<
oob_conditional_check
>
{});
}
/**
* @brief Loads a tile of data using inline assembly.
*
* @note Bare in mind that loading data this way, you have to manually initialize your
* thread buffer and synchronize load afterwards in order to make sure it's done before
* using loaded data from registers
* @see `tile_window_with_static_distribution::init_raw()` and `buffer_view.hpp`
* @see `buffer_load_fence()`
*/
template
<
typename
T
,
typename
BottomTensorView_
,
typename
WindowLengths_
,
...
...
@@ -46,7 +86,27 @@ CK_TILE_DEVICE auto load_tile_raw(T& tile,
bool_constant
<
oob_conditional_check
>
=
{},
bool_constant
<
pre_nop
>
=
{})
{
tile_window
.
load_raw
(
tile
,
bool_constant
<
oob_conditional_check
>
{},
bool_constant
<
pre_nop
>
{});
tile_window
.
load_raw
(
tile
,
number
<-
1
>
{},
bool_constant
<
oob_conditional_check
>
{},
bool_constant
<
pre_nop
>
{});
}
template
<
typename
T
,
typename
BottomTensorView_
,
typename
WindowLengths_
,
typename
TileDistribution_
,
typename
LinearBottomDims_
,
bool
oob_conditional_check
=
true
,
bool
pre_nop
=
false
>
CK_TILE_DEVICE
auto
load_tile_raw
(
T
&
tile
,
const
tile_window_linear
<
BottomTensorView_
,
WindowLengths_
,
TileDistribution_
,
LinearBottomDims_
>&
tile_window
,
bool_constant
<
oob_conditional_check
>
=
{},
bool_constant
<
pre_nop
>
=
{})
{
tile_window
.
load_raw
(
tile
,
number
<-
1
>
{},
bool_constant
<
oob_conditional_check
>
{},
bool_constant
<
pre_nop
>
{});
}
template
<
typename
LdsTileWindow_
,
...
...
@@ -66,7 +126,26 @@ async_load_tile_raw(LdsTileWindow_&& lds_tile,
bool_constant
<
pre_nop
>
=
{})
{
return
tile_window
.
async_load_raw
(
lds_tile
,
bool_constant
<
oob_conditional_check
>
{},
bool_constant
<
pre_nop
>
{});
lds_tile
,
number
<-
1
>
{},
bool_constant
<
oob_conditional_check
>
{},
bool_constant
<
pre_nop
>
{});
}
template
<
typename
LdsTileWindow_
,
typename
BottomTensorView_
,
typename
WindowLengths_
,
typename
TileDistribution_
,
typename
LinearBottomDims_
,
bool
oob_conditional_check
=
true
,
bool
pre_nop
=
false
>
CK_TILE_DEVICE
auto
async_load_tile_raw
(
LdsTileWindow_
&&
lds_tile
,
const
tile_window_linear
<
BottomTensorView_
,
WindowLengths_
,
TileDistribution_
,
LinearBottomDims_
>&
tile_window
,
bool_constant
<
oob_conditional_check
>
=
{},
bool_constant
<
pre_nop
>
=
{})
{
return
tile_window
.
async_load_raw
(
lds_tile
,
number
<-
1
>
{},
bool_constant
<
oob_conditional_check
>
{},
bool_constant
<
pre_nop
>
{});
}
CK_TILE_DEVICE
auto
async_load_fence
(
index_t
cnt
=
0
)
...
...
include/ck_tile/core/tensor/null_tile_window.hpp
View file @
7d50244e
...
...
@@ -80,6 +80,13 @@ CK_TILE_DEVICE constexpr auto make_tile_window(null_tensor_view,
return
null_tile_window
<
remove_cvref_t
<
WindowLengths
>>
{
window_lengths
};
}
template
<
typename
WindowLengths
,
typename
StaticTileDistribution
>
CK_TILE_DEVICE
constexpr
auto
make_tile_window
(
const
null_tile_window
<
WindowLengths
>&
t
,
const
StaticTileDistribution
&
)
{
return
t
;
}
template
<
typename
WindowLengths
>
CK_TILE_DEVICE
void
move_tile_window
(
null_tile_window
<
WindowLengths
>&
,
...
...
include/ck_tile/core/tensor/shuffle_tile.hpp
View file @
7d50244e
...
...
@@ -109,7 +109,7 @@ CK_TILE_DEVICE void shuffle_tile_impl_in_thread(OutTensor& out_tensor, const InT
// get input vectors
static_for
<
0
,
num_vec_in
,
1
>
{}([
&
](
auto
i
)
{
constexpr
auto
idx_y_in
=
generate_
array
(
constexpr
auto
idx_y_in
=
generate_
tuple
(
[
&
](
auto
ii
)
{
return
ii
==
y_dim_vec_out
?
idx_y_start
[
ii
]
+
i
:
idx_y_start
[
ii
];
},
...
...
include/ck_tile/core/tensor/store_tile.hpp
View file @
7d50244e
...
...
@@ -10,6 +10,7 @@
#include "ck_tile/core/container/container_helper.hpp"
#include "ck_tile/core/numeric/math.hpp"
#include "ck_tile/core/tensor/tile_window.hpp"
#include "ck_tile/core/tensor/tile_window_linear.hpp"
#include "ck_tile/core/utility/type_traits.hpp"
namespace
ck_tile
{
...
...
@@ -72,7 +73,7 @@ store_tile(tile_window_with_static_distribution<BottomTensorView_,
NumCoord
>&
tile_window
,
const
static_distributed_tensor
<
DataType_
,
TileDistribution_
>&
dstr_tensor
)
{
tile_window
.
store
(
dstr_tensor
);
tile_window
.
store
(
dstr_tensor
,
number
<-
1
>
{}
);
}
template
<
typename
BottomTensorView_
,
...
...
@@ -87,7 +88,33 @@ store_tile_raw(tile_window_with_static_distribution<BottomTensorView_,
NumCoord
>&
tile_window
,
const
static_distributed_tensor
<
DataType_
,
TileDistribution_
>&
dstr_tensor
)
{
tile_window
.
store_raw
(
dstr_tensor
);
tile_window
.
store_raw
(
dstr_tensor
,
number
<-
1
>
{});
}
template
<
typename
BottomTensorView_
,
typename
WindowLengths_
,
typename
TileDistribution_
,
typename
LinearBottomDims_
,
typename
DataType_
>
CK_TILE_DEVICE
void
store_tile
(
tile_window_linear
<
BottomTensorView_
,
WindowLengths_
,
TileDistribution_
,
LinearBottomDims_
>&
tile_window
,
const
static_distributed_tensor
<
DataType_
,
TileDistribution_
>&
dstr_tensor
)
{
tile_window
.
store
(
dstr_tensor
,
number
<-
1
>
{});
}
template
<
typename
BottomTensorView_
,
typename
WindowLengths_
,
typename
TileDistribution_
,
typename
LinearBottomDims_
,
typename
DataType_
>
CK_TILE_DEVICE
void
store_tile_raw
(
tile_window_linear
<
BottomTensorView_
,
WindowLengths_
,
TileDistribution_
,
LinearBottomDims_
>&
tile_window
,
const
static_distributed_tensor
<
DataType_
,
TileDistribution_
>&
dstr_tensor
)
{
tile_window
.
store_raw
(
dstr_tensor
,
number
<-
1
>
{});
}
}
// namespace ck_tile
include/ck_tile/core/tensor/tensor_view.hpp
View file @
7d50244e
...
...
@@ -16,6 +16,24 @@
namespace
ck_tile
{
/*
* tensor_view
* abstract the underneath memory buffer(global, LDS, etc...)
* and provide a unified get/set function for access
*
* For addressing into the buffer we use 2 variable to control:
* coord : ND tensor coordinate, will calculate the actual offset inside
* linear_offset : 1D offset, will be used in the immediate field of
* the buffer instruction to help reduce register usage
*
* User can use either of the field, or both to indexing into the tensor
*
* We usually provide 2 set of API for buffer get/set, e.g.
* get_vectorized_elements()/get_vectorized_elements_raw()
* the former usually will call intrinsic or normal C function, the later
* usually will call inline-asm function
*
*/
template
<
typename
BufferView_
,
typename
TensorDesc_
,
memory_operation_enum
DstInMemOp_
=
memory_operation_enum
::
set
>
...
...
@@ -49,22 +67,6 @@ struct tensor_view
CK_TILE_HOST_DEVICE
constexpr
auto
&
get_buffer_view
()
{
return
buf_
;
}
#if 0
CK_TILE_HOST_DEVICE constexpr DataType get_element(const TensorCoord& coord) const
{
return buf_.template get<DataType>(
coord.get_offset(),
coordinate_has_valid_offset_assuming_top_index_is_valid(desc_, coord));
}
CK_TILE_HOST_DEVICE constexpr void set_element(const TensorCoord& coord, const DataType& x)
{
buf_.template set<DataType>(
coord.get_offset(),
coordinate_has_valid_offset_assuming_top_index_is_valid(desc_, coord),
x);
}
#endif
// X is vector of DataType.
// "coord" is coordinate of DataType, not X. "coord" should be aligned to X
template
<
typename
X
,
...
...
@@ -75,14 +77,34 @@ struct tensor_view
bool
>::
type
=
false
>
CK_TILE_HOST_DEVICE
constexpr
remove_cvref_t
<
X
>
get_vectorized_elements
(
const
TensorCoord
&
coord
,
index_t
linear_offset
,
bool_constant
<
oob_conditional_check
>
=
{})
const
{
return
buf_
.
template
get
<
X
>(
coord
.
get_offset
(),
linear_offset
,
coordinate_has_valid_offset_assuming_top_index_is_valid
(
desc_
,
coord
),
bool_constant
<
oob_conditional_check
>
{});
}
template
<
typename
X
,
bool
oob_conditional_check
=
true
,
typename
std
::
enable_if
<
std
::
is_same_v
<
typename
vector_traits
<
remove_cvref_t
<
X
>
>::
scalar_type
,
typename
vector_traits
<
remove_cvref_t
<
DataType
>>::
scalar_type
>
,
bool
>::
type
=
false
>
CK_TILE_HOST_DEVICE
constexpr
remove_cvref_t
<
X
>
get_vectorized_elements
(
const
TensorCoord
&
coord
,
index_t
linear_offset
,
bool
is_valid_element
,
// flag
bool_constant
<
oob_conditional_check
>
=
{})
const
{
return
buf_
.
template
get
<
X
>(
coord
.
get_offset
(),
linear_offset
,
is_valid_element
,
bool_constant
<
oob_conditional_check
>
{});
}
// X is vector of DataType.
// "coord" is coordinate of DataType, not X. "coord" should be aligned to X
template
<
typename
X
,
...
...
@@ -94,12 +116,90 @@ struct tensor_view
bool
>::
type
=
false
>
CK_TILE_HOST_DEVICE
void
get_vectorized_elements_raw
(
remove_cvref_t
<
X
>&
dst
,
const
TensorCoord
&
coord
,
index_t
linear_offset
,
bool_constant
<
oob_conditional_check
>
=
{},
bool_constant
<
pre_nop
>
=
{})
const
{
return
buf_
.
template
get_raw
<
X
,
oob_conditional_check
,
pre_nop
>(
dst
,
coord
.
get_offset
(),
linear_offset
,
coordinate_has_valid_offset_assuming_top_index_is_valid
(
desc_
,
coord
),
bool_constant
<
pre_nop
>
{});
}
template
<
typename
X
,
bool
oob_conditional_check
=
true
,
bool
pre_nop
=
false
,
typename
std
::
enable_if
<
std
::
is_same_v
<
typename
vector_traits
<
remove_cvref_t
<
X
>
>::
scalar_type
,
typename
vector_traits
<
remove_cvref_t
<
DataType
>>::
scalar_type
>
,
bool
>::
type
=
false
>
CK_TILE_HOST_DEVICE
void
get_vectorized_elements_raw
(
remove_cvref_t
<
X
>&
dst
,
const
TensorCoord
&
coord
,
index_t
linear_offset
,
bool
is_valid_element
,
bool_constant
<
oob_conditional_check
>
=
{},
bool_constant
<
pre_nop
>
=
{})
const
{
return
buf_
.
template
get_raw
<
X
,
oob_conditional_check
,
pre_nop
>(
dst
,
coord
.
get_offset
(),
linear_offset
,
is_valid_element
,
bool_constant
<
pre_nop
>
{});
}
template
<
typename
X
,
bool
oob_conditional_check
=
true
,
typename
std
::
enable_if
<
std
::
is_same_v
<
typename
vector_traits
<
remove_cvref_t
<
X
>
>::
scalar_type
,
typename
vector_traits
<
remove_cvref_t
<
DataType
>>::
scalar_type
>
,
bool
>::
type
=
false
>
CK_TILE_HOST_DEVICE
constexpr
void
async_get_vectorized_elements
(
CK_TILE_LDS_ADDR
remove_cvref_t
<
DataType
>*
smem
,
const
TensorCoord
&
coord
,
index_t
linear_offset
)
const
{
return
buf_
.
template
async_get
<
X
>(
smem
,
coord
.
get_offset
(),
linear_offset
,
coordinate_has_valid_offset_assuming_top_index_is_valid
(
desc_
,
coord
),
bool_constant
<
oob_conditional_check
>
{});
}
template
<
typename
X
,
bool
oob_conditional_check
=
true
,
typename
std
::
enable_if
<
std
::
is_same_v
<
typename
vector_traits
<
remove_cvref_t
<
X
>
>::
scalar_type
,
typename
vector_traits
<
remove_cvref_t
<
DataType
>>::
scalar_type
>
,
bool
>::
type
=
false
>
CK_TILE_HOST_DEVICE
constexpr
void
async_get_vectorized_elements
(
CK_TILE_LDS_ADDR
remove_cvref_t
<
DataType
>*
smem
,
const
TensorCoord
&
coord
,
index_t
linear_offset
,
bool
is_valid_element
)
const
{
return
buf_
.
template
async_get
<
X
>(
smem
,
coord
.
get_offset
(),
linear_offset
,
is_valid_element
,
bool_constant
<
oob_conditional_check
>
{});
}
template
<
typename
X
,
bool
pre_nop
=
false
,
typename
std
::
enable_if
<
std
::
is_same_v
<
typename
vector_traits
<
remove_cvref_t
<
X
>
>::
scalar_type
,
typename
vector_traits
<
remove_cvref_t
<
DataType
>>::
scalar_type
>
,
bool
>::
type
=
false
>
CK_TILE_HOST_DEVICE
constexpr
void
async_get_vectorized_elements_raw
(
remove_cvref_t
<
DataType
>*
smem
,
const
TensorCoord
&
coord
,
index_t
linear_offset
,
bool_constant
<
pre_nop
>
=
{})
const
{
return
buf_
.
template
async_get_raw
<
X
>(
smem
,
coord
.
get_offset
(),
linear_offset
,
coordinate_has_valid_offset_assuming_top_index_is_valid
(
desc_
,
coord
),
bool_constant
<
pre_nop
>
{});
}
...
...
@@ -110,11 +210,15 @@ struct tensor_view
std
::
is_same_v
<
typename
vector_traits
<
remove_cvref_t
<
X
>
>::
scalar_type
,
typename
vector_traits
<
remove_cvref_t
<
DataType
>>::
scalar_type
>
,
bool
>::
type
=
false
>
CK_TILE_HOST_DEVICE
constexpr
void
async_get_vectorized_elements_raw
(
remove_cvref_t
<
DataType
>*
smem
,
const
TensorCoord
&
coord
,
bool_constant
<
pre_nop
>
=
{})
const
CK_TILE_HOST_DEVICE
constexpr
void
async_get_vectorized_elements_raw
(
remove_cvref_t
<
DataType
>*
smem
,
const
TensorCoord
&
coord
,
index_t
linear_offset
,
bool
is_valid_element
,
bool_constant
<
pre_nop
>
=
{})
const
{
return
buf_
.
template
async_get_raw
<
X
>(
smem
,
coord
.
get_offset
(),
true
/*not used*/
,
bool_constant
<
pre_nop
>
{});
smem
,
coord
.
get_offset
(),
linear_offset
,
is_valid_element
,
bool_constant
<
pre_nop
>
{});
}
// X is vector of DataType.
...
...
@@ -125,11 +229,15 @@ struct tensor_view
std
::
is_same_v
<
typename
vector_traits
<
remove_cvref_t
<
X
>
>::
scalar_type
,
typename
vector_traits
<
remove_cvref_t
<
DataType
>>::
scalar_type
>
,
bool
>::
type
=
false
>
CK_TILE_HOST_DEVICE
constexpr
void
set_vectorized_elements
(
const
TensorCoord
&
coord
,
const
X
&
x
,
bool_constant
<
oob_conditional_check
>
=
{})
CK_TILE_HOST_DEVICE
constexpr
void
set_vectorized_elements
(
const
TensorCoord
&
coord
,
index_t
linear_offset
,
const
X
&
x
,
bool_constant
<
oob_conditional_check
>
=
{})
{
buf_
.
template
set
<
X
,
oob_conditional_check
>(
coord
.
get_offset
(),
linear_offset
,
coordinate_has_valid_offset_assuming_top_index_is_valid
(
desc_
,
coord
),
x
);
}
...
...
@@ -140,15 +248,53 @@ struct tensor_view
std
::
is_same_v
<
typename
vector_traits
<
remove_cvref_t
<
X
>
>::
scalar_type
,
typename
vector_traits
<
remove_cvref_t
<
DataType
>>::
scalar_type
>
,
bool
>::
type
=
false
>
CK_TILE_HOST_DEVICE
constexpr
void
set_vectorized_elements_raw
(
const
TensorCoord
&
coord
,
const
X
&
x
,
bool_constant
<
oob_conditional_check
>
=
{})
CK_TILE_HOST_DEVICE
constexpr
void
set_vectorized_elements
(
const
TensorCoord
&
coord
,
index_t
linear_offset
,
bool
is_valid_element
,
const
X
&
x
,
bool_constant
<
oob_conditional_check
>
=
{})
{
buf_
.
template
set
<
X
,
oob_conditional_check
>(
coord
.
get_offset
(),
linear_offset
,
is_valid_element
,
x
);
}
template
<
typename
X
,
bool
oob_conditional_check
=
true
,
typename
std
::
enable_if
<
std
::
is_same_v
<
typename
vector_traits
<
remove_cvref_t
<
X
>
>::
scalar_type
,
typename
vector_traits
<
remove_cvref_t
<
DataType
>>::
scalar_type
>
,
bool
>::
type
=
false
>
CK_TILE_HOST_DEVICE
constexpr
void
set_vectorized_elements_raw
(
const
TensorCoord
&
coord
,
index_t
linear_offset
,
const
X
&
x
,
bool_constant
<
oob_conditional_check
>
=
{})
{
buf_
.
template
set_raw
<
X
,
oob_conditional_check
>(
coord
.
get_offset
(),
linear_offset
,
coordinate_has_valid_offset_assuming_top_index_is_valid
(
desc_
,
coord
),
x
);
}
template
<
typename
X
,
bool
oob_conditional_check
=
true
,
typename
std
::
enable_if
<
std
::
is_same_v
<
typename
vector_traits
<
remove_cvref_t
<
X
>
>::
scalar_type
,
typename
vector_traits
<
remove_cvref_t
<
DataType
>>::
scalar_type
>
,
bool
>::
type
=
false
>
CK_TILE_HOST_DEVICE
constexpr
void
set_vectorized_elements_raw
(
const
TensorCoord
&
coord
,
index_t
linear_offset
,
bool
is_valid_element
,
const
X
&
x
,
bool_constant
<
oob_conditional_check
>
=
{})
{
buf_
.
template
set_raw
<
X
,
oob_conditional_check
>(
coord
.
get_offset
(),
linear_offset
,
is_valid_element
,
x
);
}
// X is vector of DataType.
// "coord" is coordinate of DataType, not X. "coord" should be aligned to X
template
<
typename
X
,
...
...
@@ -157,15 +303,36 @@ struct tensor_view
std
::
is_same_v
<
typename
vector_traits
<
remove_cvref_t
<
X
>
>::
scalar_type
,
typename
vector_traits
<
remove_cvref_t
<
DataType
>>::
scalar_type
>
,
bool
>::
type
=
false
>
CK_TILE_HOST_DEVICE
constexpr
void
update_vectorized_elements
(
const
TensorCoord
&
coord
,
const
X
&
x
,
bool_constant
<
oob_conditional_check
>
=
{})
CK_TILE_HOST_DEVICE
constexpr
void
update_vectorized_elements
(
const
TensorCoord
&
coord
,
index_t
linear_offset
,
const
X
&
x
,
bool_constant
<
oob_conditional_check
>
=
{})
{
buf_
.
template
update
<
DstInMemOp
,
X
,
oob_conditional_check
>(
coord
.
get_offset
(),
linear_offset
,
coordinate_has_valid_offset_assuming_top_index_is_valid
(
desc_
,
coord
),
x
);
}
template
<
typename
X
,
bool
oob_conditional_check
=
true
,
typename
std
::
enable_if
<
std
::
is_same_v
<
typename
vector_traits
<
remove_cvref_t
<
X
>
>::
scalar_type
,
typename
vector_traits
<
remove_cvref_t
<
DataType
>>::
scalar_type
>
,
bool
>::
type
=
false
>
CK_TILE_HOST_DEVICE
constexpr
void
update_vectorized_elements
(
const
TensorCoord
&
coord
,
index_t
linear_offset
,
bool
is_valid_element
,
const
X
&
x
,
bool_constant
<
oob_conditional_check
>
=
{})
{
buf_
.
template
update
<
DstInMemOp
,
X
,
oob_conditional_check
>(
coord
.
get_offset
(),
linear_offset
,
is_valid_element
,
x
);
}
CK_TILE_HOST_DEVICE
void
print
()
const
{
printf
(
"tensor_view{"
);
...
...
include/ck_tile/core/tensor/tile_window.hpp
View file @
7d50244e
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-202
3
, Advanced Micro Devices, Inc. All rights reserved.
// Copyright (c) 2018-202
4
, Advanced Micro Devices, Inc. All rights reserved.
#pragma once
...
...
@@ -18,6 +18,8 @@
namespace
ck_tile
{
// Note: this tile window do not support single issue
// you need to use tile_window_linear structure for this purpose
template
<
typename
BottomTensorView_
,
typename
WindowLengths_
,
typename
StaticTileDistribution_
,
...
...
@@ -41,6 +43,7 @@ struct tile_window_with_static_distribution
static
constexpr
auto
I0
=
number
<
0
>
{};
static
constexpr
auto
I1
=
number
<
1
>
{};
static_assert
(
NumCoord
==
1
);
// TODO: check WindowLengths and StaticTileDistribution are consistent
...
...
@@ -189,7 +192,8 @@ struct tile_window_with_static_distribution
constexpr
auto
idx_diff_ys
=
SFC_Ys
::
get_step_between
(
number
<
0
>
{},
number
<
iCoord
*
NumAccessPerCoord
>
{});
constexpr
auto
idx_diff_ps_ys
=
container_concat
(
array
<
index_t
,
NDimP
>
{
0
},
idx_diff_ys
);
constexpr
auto
idx_diff_ps_ys
=
container_concat
(
generate_tuple
([
&
](
auto
)
{
return
number
<
0
>
{};
},
number
<
NDimP
>
{}),
idx_diff_ys
);
move_window_adaptor_and_bottom_tensor_thread_coordinate
(
window_adaptor_thread_coord
,
bottom_tensor_thread_coord
,
idx_diff_ps_ys
);
...
...
@@ -222,10 +226,11 @@ struct tile_window_with_static_distribution
// move thread's window adaptor coordinate and bottom tensor coordinate
// [p0, p1, ..., y0, y1, ...] ==> [x0, x1, ...] ==> [x0', x1', ...] ==> [offset]
template
<
typename
ATopIndex
>
CK_TILE_DEVICE
void
move_window_adaptor_and_bottom_tensor_thread_coordinate
(
WindowAdaptorCoord
&
window_adaptor_thread_coord
,
BottomTensorCoord
&
bottom_tensor_thread_coord
,
const
A
daptor
TopIndex
&
idx_diff_adaptor_top
)
const
const
ATopIndex
&
idx_diff_adaptor_top
)
const
{
array
<
index_t
,
NDimBottomTensor
>
idx_diff_adaptor_bottom
;
...
...
@@ -279,20 +284,28 @@ struct tile_window_with_static_distribution
get_container_subset
(
window_adaptor_ps_ys_vector_strides
,
y_dims
));
}
CK_TILE_DEVICE
constexpr
auto
get_num_access
()
const
{
return
load_store_traits
::
NumAccess
;
}
CK_TILE_DEVICE
constexpr
auto
get_num_
of_
access
()
const
{
return
load_store_traits
::
NumAccess
;
}
template
<
bool
oob_conditional_check
=
true
>
CK_TILE_DEVICE
auto
load
(
bool_constant
<
oob_conditional_check
>
=
{})
const
template
<
index_t
i_access_unsupport_
=
-
1
,
bool
oob_conditional_check
=
true
>
CK_TILE_DEVICE
auto
load
(
number
<
i_access_unsupport_
>
=
{},
bool_constant
<
oob_conditional_check
>
=
{})
const
{
using
Traits
=
load_store_traits
;
constexpr
auto
tile_dstr
=
TileDstr
{};
auto
dst_tensor
=
make_static_distributed_tensor
<
DataType
>
(
tile_dstr
);
load
(
dst_tensor
,
bool_constant
<
oob_conditional_check
>
{});
return
dst_tensor
;
}
template
<
typename
DistributedTensor
,
bool
oob_conditional_check
=
true
>
CK_TILE_DEVICE
auto
load
(
DistributedTensor
&
dst_tensor
,
bool_constant
<
oob_conditional_check
>
=
{})
const
{
using
Traits
=
load_store_traits
;
using
vector_t
=
typename
Traits
::
vector_t
;
using
SFC_Ys
=
typename
Traits
::
SFC_Ys
;
constexpr
auto
tile_dstr
=
TileDstr
{};
auto
dst_tensor
=
make_static_distributed_tensor
<
DataType
>
(
tile_dstr
);
// loop over thread tensor space [y0, y1, ...]
static_for
<
0
,
NumCoord
,
1
>
{}([
&
](
auto
iCoord
)
{
/// TODO: use structure binding (to be captured later) if compiled in C++20
...
...
@@ -308,11 +321,11 @@ struct tile_window_with_static_distribution
// read from bottom tensor
const
vector_t
vec_value
=
get_bottom_tensor_view
().
template
get_vectorized_elements
<
vector_t
>(
bottom_tensor_thread_coord
,
bool_constant
<
oob_conditional_check
>
{});
bottom_tensor_thread_coord
,
0
,
bool_constant
<
oob_conditional_check
>
{});
#if 1
// write into distributed tensor
static_for
<
0
,
Traits
::
ScalarPerVector
,
1
>
{}([
&
](
auto
j
)
{
constexpr
auto
idx_ys
=
generate_
array
(
constexpr
auto
idx_ys
=
generate_
tuple
(
[
&
](
auto
jj
)
{
return
jj
==
Traits
::
VectorDimY
?
(
idx_ys_start
[
jj
]
+
j
)
:
idx_ys_start
[
jj
];
...
...
@@ -338,20 +351,23 @@ struct tile_window_with_static_distribution
{
constexpr
auto
idx_diff_ys
=
SFC_Ys
::
get_forward_step
(
iAccess
);
constexpr
auto
idx_diff_ps_ys
=
container_concat
(
array
<
index_t
,
NDimP
>
{
0
},
idx_diff_ys
);
constexpr
auto
idx_diff_ps_ys
=
container_concat
(
generate_tuple
([
&
](
auto
)
{
return
number
<
0
>
{};
},
number
<
NDimP
>
{}),
idx_diff_ys
);
move_window_adaptor_and_bottom_tensor_thread_coordinate
(
window_adaptor_thread_coord
,
bottom_tensor_thread_coord
,
idx_diff_ps_ys
);
}
});
});
return
dst_tensor
;
}
template
<
typename
DstTile
,
bool
oob_conditional_check
=
true
,
bool
pre_nop
=
false
>
template
<
typename
DstTile
,
index_t
i_access_unsupport_
=
-
1
,
bool
oob_conditional_check
=
true
,
bool
pre_nop
=
false
>
CK_TILE_DEVICE
void
load_raw
(
DstTile
&
dst_tensor
,
number
<
i_access_unsupport_
>
=
{},
bool_constant
<
oob_conditional_check
>
=
{},
bool_constant
<
pre_nop
>
=
{})
const
{
...
...
@@ -397,6 +413,7 @@ struct tile_window_with_static_distribution
get_bottom_tensor_view
().
template
get_vectorized_elements_raw
<
vector_t
>(
dst_vec_tbuf
.
template
at
<
d
/
Traits
::
ScalarPerVector
>(),
bottom_tensor_thread_coord
,
0
/**/
,
bool_constant
<
oob_conditional_check
>
{},
pre_nop_
);
#if CK_TILE_WORKAROUND_ROCM_6_1_SCRATCH_MEMORY_ISSUE || \
...
...
@@ -409,23 +426,24 @@ struct tile_window_with_static_distribution
{
constexpr
auto
idx_diff_ys
=
SFC_Ys
::
get_forward_step
(
iAccess
);
constexpr
auto
idx_diff_ps_ys
=
container_concat
(
array
<
index_t
,
NDimP
>
{
0
},
idx_diff_ys
);
constexpr
auto
idx_diff_ps_ys
=
container_concat
(
generate_tuple
([
&
](
auto
)
{
return
number
<
0
>
{};
},
number
<
NDimP
>
{}),
idx_diff_ys
);
move_window_adaptor_and_bottom_tensor_thread_coordinate
(
window_adaptor_thread_coord
,
bottom_tensor_thread_coord
,
idx_diff_ps_ys
);
}
});
});
#if CK_TILE_WORKAROUND_ROCM_6_1_SCRATCH_MEMORY_ISSUE
asm
volatile
(
"; this inline asm is workaround to prevent compiler from using too much "
"scratch memory"
::
);
#endif
}
// TODO: currently async load only implemented in inline asm
template
<
typename
LdsTileWindow_
,
bool
oob_conditional_check
=
true
,
bool
pre_nop
=
false
>
template
<
typename
LdsTileWindow_
,
index_t
i_access_unsupport_
=
-
1
,
bool
oob_conditional_check
=
true
,
bool
pre_nop
=
false
>
CK_TILE_DEVICE
auto
async_load_raw
(
LdsTileWindow_
&&
lds_tile
,
number
<
i_access_unsupport_
>
=
{},
bool_constant
<
oob_conditional_check
>
=
{},
bool_constant
<
pre_nop
>
=
{})
const
{
...
...
@@ -467,7 +485,7 @@ struct tile_window_with_static_distribution
// loop over thread tensor space [y0, y1, ...]
static_for
<
0
,
NumCoord
,
1
>
{}([
&
](
auto
iCoord
)
{
// TODO: use structure binding (to be captured later) if compiled in C++20
//
/
TODO: use structure binding (to be captured later) if compiled in C++20
auto
window_adaptor_thread_coord
=
pre_computed_coords_
[
iCoord
][
I0
];
auto
bottom_tensor_thread_coord
=
pre_computed_coords_
[
iCoord
][
I1
];
...
...
@@ -482,15 +500,16 @@ struct tile_window_with_static_distribution
// read from bottom tensor
get_bottom_tensor_view
().
template
async_get_vectorized_elements_raw
<
vector_t
>(
smem
,
bottom_tensor_thread_coord
,
pre_nop_
);
smem
,
bottom_tensor_thread_coord
,
0
,
pre_nop_
);
// move thread coordinate
if
constexpr
(
iCoordAccess
!=
(
NumAccessPerCoord
-
1
))
{
constexpr
auto
idx_diff_ys
=
SFC_Ys
::
get_forward_step
(
iAccess
);
constexpr
auto
idx_diff_ps_ys
=
container_concat
(
array
<
index_t
,
NDimP
>
{
0
},
idx_diff_ys
);
constexpr
auto
idx_diff_ps_ys
=
container_concat
(
generate_tuple
([
&
](
auto
)
{
return
number
<
0
>
{};
},
number
<
NDimP
>
{}),
idx_diff_ys
);
move_window_adaptor_and_bottom_tensor_thread_coordinate
(
window_adaptor_thread_coord
,
bottom_tensor_thread_coord
,
idx_diff_ps_ys
);
...
...
@@ -501,8 +520,81 @@ struct tile_window_with_static_distribution
});
}
template
<
bool
oob_conditional_check
=
true
>
template
<
typename
LdsTileWindow_
,
index_t
i_access_unsupport_
=
-
1
,
bool
oob_conditional_check
=
true
>
CK_TILE_DEVICE
auto
async_load
(
LdsTileWindow_
&&
lds_tile
,
number
<
i_access_unsupport_
>
=
{},
bool_constant
<
oob_conditional_check
>
=
{})
const
{
using
LdsTileWindow
=
remove_cvref_t
<
LdsTileWindow_
>
;
using
LdsDataType
=
typename
LdsTileWindow
::
DataType
;
// issues * warps * lanes
static_assert
(
LdsTileWindow
::
get_num_of_dimension
()
==
3
);
// TODO: hard coded
// TODO: LDS offset is not good for intrinsic based implementation(compiler can't figure out
// dependency) hence avoid use offset based solution. size_per_buf should be zero (how to
// check?)
constexpr
index_t
size_per_buf
=
lds_tile
.
get_bottom_tensor_view
().
get_tensor_descriptor
().
calculate_offset
(
make_tuple
(
number
<
0
>
{},
number
<
0
>
{},
number
<
0
>
{}));
constexpr
index_t
size_per_wave
=
lds_tile
.
get_bottom_tensor_view
().
get_tensor_descriptor
().
calculate_offset
(
make_tuple
(
number
<
0
>
{},
number
<
1
>
{},
number
<
0
>
{}))
-
size_per_buf
;
constexpr
index_t
size_per_issue
=
lds_tile
.
get_bottom_tensor_view
().
get_tensor_descriptor
().
calculate_offset
(
make_tuple
(
number
<
1
>
{},
number
<
0
>
{},
number
<
0
>
{}))
-
size_per_buf
;
const
index_t
m0_init_value
=
size_per_buf
+
size_per_wave
*
get_warp_id
();
using
Traits
=
load_store_traits
;
using
vector_t
=
typename
Traits
::
vector_t
;
using
SFC_Ys
=
typename
Traits
::
SFC_Ys
;
// TODO: we force CK_TILE_LDS_ADDR
CK_TILE_LDS_ADDR
LdsDataType
*
smem
=
lds_tile
.
get_bottom_tensor_view
().
get_buffer_view
().
p_data_
+
m0_init_value
;
// loop over thread tensor space [y0, y1, ...]
static_for
<
0
,
NumCoord
,
1
>
{}([
&
](
auto
iCoord
)
{
/// TODO: use structure binding (to be captured later) if compiled in C++20
auto
window_adaptor_thread_coord
=
pre_computed_coords_
[
iCoord
][
I0
];
auto
bottom_tensor_thread_coord
=
pre_computed_coords_
[
iCoord
][
I1
];
static_for
<
0
,
NumAccessPerCoord
,
1
>
{}([
&
](
auto
iCoordAccess
)
{
constexpr
auto
iAccess
=
number
<
iCoord
*
NumAccessPerCoord
+
iCoordAccess
>
{};
// read from bottom tensor
get_bottom_tensor_view
().
template
async_get_vectorized_elements
<
vector_t
>(
smem
,
bottom_tensor_thread_coord
,
0
,
bool_constant
<
oob_conditional_check
>
{});
// move thread coordinate
if
constexpr
(
iCoordAccess
!=
(
NumAccessPerCoord
-
1
))
{
constexpr
auto
idx_diff_ys
=
SFC_Ys
::
get_forward_step
(
iAccess
);
constexpr
auto
idx_diff_ps_ys
=
container_concat
(
generate_tuple
([
&
](
auto
)
{
return
number
<
0
>
{};
},
number
<
NDimP
>
{}),
idx_diff_ys
);
move_window_adaptor_and_bottom_tensor_thread_coordinate
(
window_adaptor_thread_coord
,
bottom_tensor_thread_coord
,
idx_diff_ps_ys
);
smem
+=
size_per_issue
;
// Note we manually increase the per-issue offset
}
});
});
}
template
<
index_t
i_access_unsupport_
=
-
1
,
bool
oob_conditional_check
=
true
>
CK_TILE_DEVICE
void
store
(
const
static_distributed_tensor
<
DataType
,
TileDstr
>&
dstr_tensor
,
number
<
i_access_unsupport_
>
=
{},
bool_constant
<
oob_conditional_check
>
=
{})
const
{
using
Traits
=
load_store_traits
;
...
...
@@ -515,7 +607,6 @@ struct tile_window_with_static_distribution
// loop over thread tensor space [y0, y1, ...]
static_for
<
0
,
NumCoord
,
1
>
{}([
&
](
auto
iCoord
)
{
/// TODO: use structure binding (to be captured later) if compiled in C++20
auto
window_adaptor_thread_coord
=
pre_computed_coords_
[
iCoord
][
I0
];
auto
bottom_tensor_thread_coord
=
pre_computed_coords_
[
iCoord
][
I1
];
...
...
@@ -530,7 +621,7 @@ struct tile_window_with_static_distribution
vector_t
vec_value
;
static_for
<
0
,
Traits
::
ScalarPerVector
,
1
>
{}([
&
](
auto
j
)
{
constexpr
auto
idx_ys
=
generate_
array
(
constexpr
auto
idx_ys
=
generate_
tuple
(
[
&
](
auto
jj
)
{
return
jj
==
Traits
::
VectorDimY
?
(
idx_ys_start
[
jj
]
+
j
)
:
idx_ys_start
[
jj
];
...
...
@@ -548,15 +639,19 @@ struct tile_window_with_static_distribution
// write into bottom tensor
get_bottom_tensor_view
().
template
set_vectorized_elements
<
vector_t
>(
bottom_tensor_thread_coord
,
vec_value
,
bool_constant
<
oob_conditional_check
>
{});
bottom_tensor_thread_coord
,
0
,
vec_value
,
bool_constant
<
oob_conditional_check
>
{});
// move thread coordinate
if
constexpr
(
iCoordAccess
!=
(
NumAccessPerCoord
-
1
))
{
constexpr
auto
idx_diff_ys
=
SFC_Ys
::
get_forward_step
(
iAccess
);
constexpr
auto
idx_diff_ps_ys
=
container_concat
(
array
<
index_t
,
NDimP
>
{
0
},
idx_diff_ys
);
constexpr
auto
idx_diff_ps_ys
=
container_concat
(
generate_tuple
([
&
](
auto
)
{
return
number
<
0
>
{};
},
number
<
NDimP
>
{}),
idx_diff_ys
);
move_window_adaptor_and_bottom_tensor_thread_coordinate
(
window_adaptor_thread_coord
,
bottom_tensor_thread_coord
,
idx_diff_ps_ys
);
...
...
@@ -565,8 +660,9 @@ struct tile_window_with_static_distribution
});
}
CK_TILE_DEVICE
void
store_raw
(
const
static_distributed_tensor
<
DataType
,
TileDstr
>&
dstr_tensor
)
const
template
<
index_t
i_access_unsupport_
=
-
1
>
CK_TILE_DEVICE
void
store_raw
(
const
static_distributed_tensor
<
DataType
,
TileDstr
>&
dstr_tensor
,
number
<
i_access_unsupport_
>
=
{})
const
{
using
Traits
=
load_store_traits
;
...
...
@@ -591,7 +687,7 @@ struct tile_window_with_static_distribution
// read from distributed tensor
vector_t
vec_value
;
static_for
<
0
,
Traits
::
ScalarPerVector
,
1
>
{}([
&
](
auto
j
)
{
constexpr
auto
idx_ys
=
generate_
array
(
constexpr
auto
idx_ys
=
generate_
tuple
(
[
&
](
auto
jj
)
{
return
jj
==
Traits
::
VectorDimY
?
(
idx_ys_start
[
jj
]
+
j
)
:
idx_ys_start
[
jj
];
...
...
@@ -606,15 +702,16 @@ struct tile_window_with_static_distribution
// write into bottom tensor
get_bottom_tensor_view
()
.
template
set_vectorized_elements_raw
<
vector_t
,
oob_conditional_check
>(
bottom_tensor_thread_coord
,
vec_value
);
bottom_tensor_thread_coord
,
0
,
vec_value
);
// move thread coordinate
if
constexpr
(
iCoordAccess
!=
(
NumAccessPerCoord
-
1
))
{
constexpr
auto
idx_diff_ys
=
SFC_Ys
::
get_forward_step
(
iAccess
);
constexpr
auto
idx_diff_ps_ys
=
container_concat
(
array
<
index_t
,
NDimP
>
{
0
},
idx_diff_ys
);
constexpr
auto
idx_diff_ps_ys
=
container_concat
(
generate_tuple
([
&
](
auto
)
{
return
number
<
0
>
{};
},
number
<
NDimP
>
{}),
idx_diff_ys
);
move_window_adaptor_and_bottom_tensor_thread_coordinate
(
window_adaptor_thread_coord
,
bottom_tensor_thread_coord
,
idx_diff_ps_ys
);
...
...
@@ -623,8 +720,9 @@ struct tile_window_with_static_distribution
});
}
template
<
bool
oob_conditional_check
=
true
>
template
<
index_t
i_access_unsupport_
=
-
1
,
bool
oob_conditional_check
=
true
>
CK_TILE_DEVICE
void
update
(
const
static_distributed_tensor
<
DataType
,
TileDstr
>&
dstr_tensor
,
number
<
i_access_unsupport_
>
=
{},
bool_constant
<
oob_conditional_check
>
=
{})
const
{
using
Traits
=
load_store_traits
;
...
...
@@ -650,7 +748,7 @@ struct tile_window_with_static_distribution
vector_t
vec_value
;
static_for
<
0
,
Traits
::
ScalarPerVector
,
1
>
{}([
&
](
auto
j
)
{
constexpr
auto
idx_ys
=
generate_
array
(
constexpr
auto
idx_ys
=
generate_
tuple
(
[
&
](
auto
jj
)
{
return
jj
==
Traits
::
VectorDimY
?
(
idx_ys_start
[
jj
]
+
j
)
:
idx_ys_start
[
jj
];
...
...
@@ -666,15 +764,19 @@ struct tile_window_with_static_distribution
// write into bottom tensor
get_bottom_tensor_view
().
template
update_vectorized_elements
<
vector_t
>(
bottom_tensor_thread_coord
,
vec_value
,
bool_constant
<
oob_conditional_check
>
{});
bottom_tensor_thread_coord
,
0
,
vec_value
,
bool_constant
<
oob_conditional_check
>
{});
// move thread coordinate
if
constexpr
(
iCoordAccess
!=
(
NumAccessPerCoord
-
1
))
{
constexpr
auto
idx_diff_ys
=
SFC_Ys
::
get_forward_step
(
iAccess
);
constexpr
auto
idx_diff_ps_ys
=
container_concat
(
array
<
index_t
,
NDimP
>
{
0
},
idx_diff_ys
);
constexpr
auto
idx_diff_ps_ys
=
container_concat
(
generate_tuple
([
&
](
auto
)
{
return
number
<
0
>
{};
},
number
<
NDimP
>
{}),
idx_diff_ys
);
move_window_adaptor_and_bottom_tensor_thread_coordinate
(
window_adaptor_thread_coord
,
bottom_tensor_thread_coord
,
idx_diff_ps_ys
);
...
...
@@ -746,7 +848,8 @@ struct tile_window_with_static_distribution
constexpr
auto
idx_diff_ys
=
SFC_Ys
::
get_step_between
(
number
<
0
>
{},
number
<
iCoord
*
NumAccessPerCoord
>
{});
constexpr
auto
idx_diff_ps_ys
=
container_concat
(
array
<
index_t
,
NDimP
>
{
0
},
idx_diff_ys
);
constexpr
auto
idx_diff_ps_ys
=
container_concat
(
generate_tuple
([
&
](
auto
)
{
return
number
<
0
>
{};
},
number
<
NDimP
>
{}),
idx_diff_ys
);
move_window_adaptor_and_bottom_tensor_thread_coordinate
(
window_adaptor_thread_coord
,
bottom_tensor_thread_coord
,
idx_diff_ps_ys
);
...
...
@@ -798,6 +901,27 @@ make_tile_window(const TensorView_& tensor_view,
tensor_view
,
window_lengths
,
origin
,
tile_distribution
};
}
// this version can't be called in a constexpr context
template
<
typename
TensorView_
,
typename
WindowLengths_
,
typename
StaticTileDistribution_
,
index_t
NumCoord
=
1
>
CK_TILE_DEVICE
auto
make_tile_window_raw
(
const
TensorView_
&
tensor_view
,
const
WindowLengths_
&
window_lengths
,
const
multi_index
<
TensorView_
::
get_num_of_dimension
()
>&
origin
,
const
StaticTileDistribution_
&
tile_distribution
,
number
<
NumCoord
>
=
{})
{
auto
w
=
tile_window_with_static_distribution
<
remove_cvref_t
<
TensorView_
>
,
remove_cvref_t
<
WindowLengths_
>
,
remove_cvref_t
<
StaticTileDistribution_
>
,
NumCoord
>
{
tensor_view
,
window_lengths
,
origin
,
tile_distribution
};
w
.
init_raw
();
return
w
;
}
template
<
typename
TensorView_
,
typename
WindowLengths_
,
typename
StaticTileDistribution_
,
...
...
@@ -922,6 +1046,19 @@ make_tile_window(const tile_window_with_static_lengths<TensorView, WindowLengths
tile_distribution
);
}
template
<
typename
TensorView
,
typename
WindowLengths
,
typename
StaticTileDistribution
>
CK_TILE_DEVICE
constexpr
auto
make_tile_window_raw
(
const
tile_window_with_static_lengths
<
TensorView
,
WindowLengths
>&
tile_window
,
const
StaticTileDistribution
&
tile_distribution
)
{
auto
w
=
make_tile_window
(
tile_window
.
get_bottom_tensor_view
(),
tile_window
.
get_window_lengths
(),
tile_window
.
get_window_origin
(),
tile_distribution
);
w
.
init_raw
();
return
w
;
}
template
<
typename
TensorView_
,
typename
WindowLengths_
>
CK_TILE_DEVICE
void
move_tile_window
(
tile_window_with_static_lengths
<
TensorView_
,
WindowLengths_
>&
window
,
...
...
include/ck_tile/core/tensor/tile_window_linear.hpp
0 → 100644
View file @
7d50244e
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2023, Advanced Micro Devices, Inc. All rights reserved.
#pragma once
#include "ck_tile/core/arch/arch.hpp"
#include "ck_tile/core/arch/utility.hpp"
#include "ck_tile/core/algorithm/space_filling_curve.hpp"
#include "ck_tile/core/config.hpp"
#include "ck_tile/core/container/array.hpp"
#include "ck_tile/core/container/sequence.hpp"
#include "ck_tile/core/container/tuple.hpp"
#include "ck_tile/core/container/container_helper.hpp"
#include "ck_tile/core/tensor/static_distributed_tensor.hpp"
#include "ck_tile/core/tensor/tensor_adaptor.hpp"
#include "ck_tile/core/tensor/tile_distribution.hpp"
#include "ck_tile/core/utility/functional.hpp"
#include "ck_tile/core/utility/type_traits.hpp"
namespace
ck_tile
{
#define WINDOW_DISPATCH_ISSUE() \
if constexpr(i_access < 0) \
{ \
static_for<0, NumAccess, 1>{}([&](auto ia) { issue(ia); }); \
} \
else \
{ \
static_assert(i_access < NumAccess); \
issue(number<i_access>{}); \
}
//
// This version of tile window will pre-cache offset/flags based on need
//
// LinearBottomDims_, e.g seq<0, 1> for 2d tensor, the last one is linear dim
// so last dim can use immediate offset to indexing, can save register
// TODO: if using this struct, better use load_raw()/store_raw(), can control
// the the immediate offset on the fly
// space-filing-curve is non-snaked here!
//
template
<
typename
BottomTensorView_
,
typename
WindowLengths_
,
typename
StaticTileDistribution_
,
typename
LinearBottomDims_
>
struct
tile_window_linear
{
using
BottomTensorView
=
remove_reference_t
<
BottomTensorView_
>
;
using
WindowLengths
=
remove_cvref_t
<
WindowLengths_
>
;
using
TileDstr
=
remove_cvref_t
<
StaticTileDistribution_
>
;
using
WindowAdaptor
=
typename
TileDstr
::
PsYs2XsAdaptor
;
using
BottomTensorDesc
=
typename
BottomTensorView
::
TensorDesc
;
using
DataType
=
remove_cvref_t
<
typename
BottomTensorView
::
DataType
>
;
using
LinearBottomDims
=
remove_cvref_t
<
LinearBottomDims_
>
;
static_assert
(
LinearBottomDims
::
size
()
==
BottomTensorView
::
get_num_of_dimension
());
static
constexpr
index_t
NDimWindowAdaptorTop
=
WindowAdaptor
::
get_num_of_top_dimension
();
static
constexpr
index_t
NDimBottomTensor
=
BottomTensorDesc
::
get_num_of_dimension
();
static
constexpr
index_t
NDimP
=
TileDstr
::
get_num_of_dimension_p
();
static
constexpr
index_t
NDimY
=
TileDstr
::
get_num_of_dimension_y
();
static
constexpr
auto
I0
=
number
<
0
>
{};
static
constexpr
auto
I1
=
number
<
1
>
{};
// TODO: check WindowLengths and StaticTileDistribution are consistent
static_assert
(
ck_tile
::
is_known_at_compile_time
<
WindowLengths
>::
value
,
"wrong! lengths should be static"
);
static_assert
(
TileDstr
::
is_static
(),
"wrong!"
);
static_assert
(
NDimBottomTensor
==
WindowAdaptor
::
get_num_of_bottom_dimension
(),
"wrong! inconsistent # of diemsnions"
);
using
AdaptorTopIndex
=
array
<
index_t
,
NDimWindowAdaptorTop
>
;
using
BottomTensorIndex
=
array
<
index_t
,
NDimBottomTensor
>
;
using
WindowAdaptorCoord
=
decltype
(
make_tensor_adaptor_coordinate
(
WindowAdaptor
{},
AdaptorTopIndex
{}));
using
BottomTensorCoord
=
decltype
(
make_tensor_coordinate
(
BottomTensorDesc
{},
BottomTensorIndex
{}));
struct
traits
{
private:
// return vector dimension among [y0, y1, ...]
CK_TILE_DEVICE
static
constexpr
auto
get_window_adaptor_ys_safe_vector_length_strides
()
{
// bottom tensor top dimension vector lengths and strides
const
auto
[
bottom_tensor_top_dim_vector_lengths
,
bottom_tensor_top_dim_vector_strides
]
=
BottomTensorDesc
::
get_top_dimension_safe_vector_length_strides
();
// window vector lengths/strides
const
auto
window_adaptor_bottom_dim_vector_lengths
=
bottom_tensor_top_dim_vector_lengths
;
const
auto
window_adaptor_bottom_dim_vector_strides
=
bottom_tensor_top_dim_vector_strides
;
// window adaptor [p0, p1, ..., y0, y1, ...]
array
<
index_t
,
WindowAdaptor
::
get_num_of_hidden_dimension
()
>
window_adaptor_vector_lengths
{
-
1
};
array
<
index_t
,
WindowAdaptor
::
get_num_of_hidden_dimension
()
>
window_adaptor_vector_strides
{
-
1
};
constexpr
auto
window_adaptor_bottom_dims
=
WindowAdaptor
::
get_bottom_dimension_hidden_ids
();
set_container_subset
(
window_adaptor_vector_lengths
,
window_adaptor_bottom_dims
,
window_adaptor_bottom_dim_vector_lengths
);
set_container_subset
(
window_adaptor_vector_strides
,
window_adaptor_bottom_dims
,
window_adaptor_bottom_dim_vector_strides
);
const
auto
[
window_adaptor_ps_ys_vector_lengths
,
window_adaptor_ps_ys_vector_strides
]
=
WindowAdaptor
{}.
get_top_dimension_safe_vector_length_strides
(
window_adaptor_vector_lengths
,
window_adaptor_vector_strides
);
// [y0, y1, ...]
constexpr
auto
y_dims
=
typename
arithmetic_sequence_gen
<
TileDstr
::
get_num_of_dimension_p
(),
NDimWindowAdaptorTop
,
1
>::
type
{};
return
make_tuple
(
get_container_subset
(
window_adaptor_ps_ys_vector_lengths
,
y_dims
),
get_container_subset
(
window_adaptor_ps_ys_vector_strides
,
y_dims
));
}
static
constexpr
auto
get_vector_dim_y_scalar_per_vector
()
{
const
auto
[
ys_vector_lengths
,
ys_vector_strides
]
=
get_window_adaptor_ys_safe_vector_length_strides
();
index_t
VectorDimY_
=
0
;
index_t
ScalarPerVector_
=
1
;
for
(
index_t
i
=
0
;
i
<
NDimY
;
++
i
)
{
if
(
ys_vector_strides
[
i
]
==
1
&&
ys_vector_lengths
[
i
]
>
ScalarPerVector_
)
{
ScalarPerVector_
=
ys_vector_lengths
[
i
];
VectorDimY_
=
i
;
}
}
return
make_tuple
(
VectorDimY_
,
ScalarPerVector_
);
}
public:
static
constexpr
index_t
VectorDimY
=
get_vector_dim_y_scalar_per_vector
().
template
at
<
0
>();
static
constexpr
index_t
ScalarPerVector
=
get_vector_dim_y_scalar_per_vector
().
template
at
<
1
>();
using
vector_t
=
thread_buffer
<
DataType
,
ScalarPerVector
>
;
private:
static
constexpr
auto
scalars_per_access_
=
[]
{
constexpr
auto
scalars_per_access_arr
=
generate_array
(
[
&
](
auto
i
)
{
return
(
i
==
VectorDimY
)
?
ScalarPerVector
:
1
;
},
number
<
NDimY
>
{});
/// TODO: add non-automatic storage argument support to macro TO_SEQUENCE()
constexpr
auto
NDimY_
=
NDimY
;
return
TO_SEQUENCE
(
scalars_per_access_arr
,
NDimY_
);
}();
static
constexpr
auto
get_space_filling_curve
()
{
constexpr
auto
thread_tensor_lengths_ys
=
to_sequence
(
TileDstr
{}.
get_ys_to_d_descriptor
().
get_lengths
());
// FIXME: need logic to judge dim access order
using
DimAccessOrder
=
typename
arithmetic_sequence_gen
<
0
,
NDimY
,
1
>::
type
;
return
space_filling_curve
<
decltype
(
thread_tensor_lengths_ys
),
DimAccessOrder
,
decltype
(
scalars_per_access_
),
false
/*!!! no snaked curve! */
>
{};
}
public:
using
SFC_Ys
=
decltype
(
get_space_filling_curve
());
static
constexpr
index_t
NumAccess
=
SFC_Ys
::
get_num_of_access
();
static_assert
(
0
<
NumAccess
,
"Wrong! NumAccess should be larger than 0"
);
private:
static
constexpr
auto
get_num_non_linear_access
()
{
constexpr
auto
sfc_access_lens
=
SFC_Ys
::
access_lengths
;
using
ys_to_rhs_major
=
typename
decltype
(
TileDstr
{}.
get_static_tile_distribution_encoding
())
::
Ys2RHsMajor
;
constexpr
auto
non_linear
=
[
&
]()
{
index_t
cnt
=
1
;
static_for
<
0
,
NDimY
,
1
>
{}([
&
](
auto
i_dim_y
)
{
constexpr
auto
rhs_major
=
ys_to_rhs_major
{}[
i_dim_y
];
constexpr
auto
target_h_dim
=
number
<
rhs_major
-
1
>
{};
// no r dim here!
if
constexpr
(
LinearBottomDims
{}[
target_h_dim
]
==
0
)
{
cnt
*=
sfc_access_lens
[
i_dim_y
];
}
});
return
cnt
;
}();
return
non_linear
;
}
// example:
// non_linear_access_map: sequence<0, 0, 0, 0, 1, 1, 1, 1> for 8 access, totally 2 register
// used
// -> histogram : sequence<4, 4>
// -> prefixsum : seqneuce<0, 4, 8>
// non_linear_access_map: sequence<0, 1, 2, 3, 4, 5, 6, 7> for 8 access, totally 8 register
// used, will pre-cache 8
// -> histogram : sequence<1, 1, 1, 1, 1, 1, 1, 1>
// -> prefixsum : seqneuce<0, 1, 2, 3, 4, 5, 6, 7, 8>
// non_linear_access_map: sequence<0, 0, 1, 1, 2, 2, 3, 3> for 8 access, totally 4 register
// used, will pre-cache 4
// -> histogram : sequence<2, 2, 2, 2>
// -> prefixsum : seqneuce<0, 2, 4, 6, 8>
static
constexpr
auto
get_non_linear_access_map
()
{
constexpr
auto
sfc_access_lens
=
SFC_Ys
::
access_lengths
;
using
ys_to_rhs_major
=
typename
decltype
(
TileDstr
{}.
get_static_tile_distribution_encoding
())
::
Ys2RHsMajor
;
constexpr
auto
non_linear_map
=
[
&
]()
{
array
<
index_t
,
NumAccess
>
m_
{
0
};
index_t
cumulative_len_
=
1
;
index_t
cumulative_non_linear_len_
=
1
;
static_for
<
0
,
NDimY
,
1
>
{}([
&
](
auto
i_y
)
{
constexpr
auto
i_dim_y
=
number
<
NDimY
-
i_y
-
1
>
{};
// from right to left
constexpr
auto
rhs_major
=
ys_to_rhs_major
{}[
i_dim_y
];
constexpr
auto
target_h_dim
=
number
<
rhs_major
-
1
>
{};
// no r dim here!
constexpr
auto
is_linear_dim
=
LinearBottomDims
{}[
target_h_dim
];
array
<
index_t
,
NumAccess
>
current_m_
{
0
};
constexpr
auto
current_len_
=
sfc_access_lens
[
i_dim_y
];
// copy cumulative length as current pattern
for
(
auto
i_
=
0
;
i_
<
cumulative_len_
;
i_
++
)
{
current_m_
(
i_
)
=
m_
[
i_
];
}
for
(
auto
j_
=
0
;
j_
<
current_len_
;
j_
++
)
{
auto
j_offset_
=
is_linear_dim
?
0
:
j_
*
cumulative_non_linear_len_
;
for
(
auto
i_
=
0
;
i_
<
cumulative_len_
;
i_
++
)
{
m_
(
j_
*
cumulative_len_
+
i_
)
=
current_m_
[
i_
]
+
j_offset_
;
}
}
cumulative_len_
*=
current_len_
;
if
(
!
is_linear_dim
)
cumulative_non_linear_len_
*=
current_len_
;
});
return
m_
;
}();
return
TO_SEQUENCE
(
non_linear_map
,
NumAccess
);
}
static
constexpr
auto
get_non_linear_access_histogram
()
{
constexpr
auto
m_
=
get_non_linear_access_map
();
// m_.foo();
constexpr
auto
r_
=
typename
arithmetic_sequence_gen
<
0
,
get_num_non_linear_access
()
+
1
,
1
>::
type
{};
constexpr
auto
h_
=
histogram_sorted_sequence
(
m_
,
r_
);
return
h_
;
}
static
constexpr
auto
get_non_linear_access_histogram_prefix_sum
()
{
constexpr
auto
h_
=
get_non_linear_access_histogram
();
constexpr
auto
h_prefix_sum_
=
prefix_sum_sequence
(
h_
);
return
h_prefix_sum_
;
}
public:
static
constexpr
index_t
NumAccess_NonLinear
=
get_num_non_linear_access
();
using
AccessMap_NonLinear
=
decltype
(
get_non_linear_access_map
());
// sequence
using
AccessHistogram_NonLinear
=
decltype
(
get_non_linear_access_histogram
());
using
AccessPrefixSum_NonLinear
=
decltype
(
get_non_linear_access_histogram_prefix_sum
());
};
static
constexpr
index_t
NumAccess
=
traits
::
NumAccess
;
static
constexpr
index_t
NumAccess_NonLinear
=
traits
::
NumAccess_NonLinear
;
using
AccessMap_NonLinear
=
typename
traits
::
AccessMap_NonLinear
;
using
AccessHistogram_NonLinear
=
typename
traits
::
AccessHistogram_NonLinear
;
using
AccessPrefixSum_NonLinear
=
typename
traits
::
AccessPrefixSum_NonLinear
;
CK_TILE_DEVICE
constexpr
tile_window_linear
()
=
default
;
CK_TILE_DEVICE
constexpr
tile_window_linear
(
const
BottomTensorView
&
bottom_tensor_view
,
const
WindowLengths
&
window_lengths
,
const
BottomTensorIndex
&
window_origin
,
const
TileDstr
&
tile_distribution
)
:
bottom_tensor_view_
{
bottom_tensor_view
},
window_lengths_
{
window_lengths
},
window_origin_
{
window_origin
},
tile_dstr_
{
tile_distribution
},
cached_coords_
{},
cached_flags_
{}
{
auto
window_adaptor_thread_coord_tmp
=
make_tensor_adaptor_coordinate
(
tile_distribution
.
get_ps_ys_to_xs_adaptor
(),
container_concat
(
make_tuple
(
get_warp_id
(),
get_lane_id
()),
generate_tuple
([
&
](
auto
)
{
return
number
<
0
>
{};
},
number
<
NDimY
>
{})));
BottomTensorIndex
bottom_tensor_thread_origin_idx_tmp
=
window_origin
+
window_adaptor_thread_coord_tmp
.
get_bottom_index
();
auto
bottom_tensor_thread_coord_tmp
=
make_tensor_coordinate
(
bottom_tensor_view_
.
get_tensor_descriptor
(),
bottom_tensor_thread_origin_idx_tmp
);
// future load/store() calls (might allocate more registers)
using
SFC_Ys
=
typename
traits
::
SFC_Ys
;
static_for
<
0
,
NumAccess
,
1
>
{}([
&
](
auto
i_access
)
{
constexpr
auto
non_linear_id
=
number
<
AccessMap_NonLinear
{}[
i_access
]
>
{};
constexpr
auto
need_save_non_linear_coord
=
bool_constant
<
AccessPrefixSum_NonLinear
{}[
non_linear_id
]
==
i_access
>
{};
if
constexpr
(
need_save_non_linear_coord
)
{
cached_coords_
(
non_linear_id
)
=
bottom_tensor_thread_coord_tmp
;
}
// TODO: need pad_tensor_view to check which dim need use flag to check
// cached flag is independent from non-linear-coord
// but need be updated in move_tile, with proper dims
cached_flags_
(
i_access
)
=
coordinate_has_valid_offset_assuming_top_index_is_valid
(
bottom_tensor_view_
.
get_tensor_descriptor
(),
bottom_tensor_thread_coord_tmp
);
if
constexpr
(
i_access
!=
(
NumAccess
-
1
))
{
constexpr
auto
idx_diff_ys
=
SFC_Ys
::
get_forward_step
(
i_access
);
// tuple of number
constexpr
auto
idx_diff_ps_ys
=
container_concat
(
generate_tuple
([
&
](
auto
)
{
return
number
<
0
>
{};
},
number
<
NDimP
>
{}),
idx_diff_ys
);
move_window_adaptor_and_bottom_tensor_thread_coordinate
(
window_adaptor_thread_coord_tmp
,
bottom_tensor_thread_coord_tmp
,
idx_diff_ps_ys
);
}
});
}
CK_TILE_DEVICE
static
constexpr
index_t
get_num_of_dimension
()
{
return
NDimBottomTensor
;
}
CK_TILE_DEVICE
static
constexpr
bool
has_static_tile_distribution
()
{
return
TileDstr
::
is_static
();
}
CK_TILE_DEVICE
constexpr
auto
get_window_lengths
()
const
{
return
window_lengths_
;
}
CK_TILE_DEVICE
constexpr
auto
get_tile_distribution
()
const
{
return
tile_dstr_
;
}
CK_TILE_DEVICE
constexpr
auto
get_bottom_tensor_view
()
const
{
return
bottom_tensor_view_
;
}
CK_TILE_DEVICE
constexpr
auto
get_window_origin
()
const
{
return
window_origin_
;
}
CK_TILE_DEVICE
constexpr
void
set_bottom_tensor_view_data_ptr
(
typename
BottomTensorView
::
DataType
*
data
)
{
bottom_tensor_view_
.
buf_
.
p_data_
=
data
;
}
// move thread's window adaptor coordinate and bottom tensor coordinate
// [p0, p1, ..., y0, y1, ...] ==> [x0, x1, ...] ==> [x0', x1', ...] ==> [offset]
template
<
typename
ATopIndex
>
CK_TILE_DEVICE
void
move_window_adaptor_and_bottom_tensor_thread_coordinate
(
WindowAdaptorCoord
&
window_adaptor_thread_coord
,
BottomTensorCoord
&
bottom_tensor_thread_coord
,
const
ATopIndex
&
idx_diff_adaptor_top
)
const
{
array
<
index_t
,
NDimBottomTensor
>
idx_diff_adaptor_bottom
;
move_tensor_adaptor_coordinate
(
tile_dstr_
.
get_ps_ys_to_xs_adaptor
(),
window_adaptor_thread_coord
,
idx_diff_adaptor_top
,
idx_diff_adaptor_bottom
);
move_tensor_coordinate
(
bottom_tensor_view_
.
get_tensor_descriptor
(),
bottom_tensor_thread_coord
,
idx_diff_adaptor_bottom
);
}
template
<
index_t
i_access
>
CK_TILE_DEVICE
static
constexpr
auto
get_bottom_linear_coordinate
(
number
<
i_access
>
)
{
using
SFC_Ys
=
typename
traits
::
SFC_Ys
;
constexpr
auto
idx_ys
=
SFC_Ys
::
get_index
(
number
<
i_access
>
{});
using
ys_to_rhs_major
=
typename
decltype
(
TileDstr
{}.
get_static_tile_distribution_encoding
())
::
Ys2RHsMajor
;
constexpr
auto
modified_idx_ys
=
generate_tuple
(
[
&
](
auto
i_dim_y
)
{
constexpr
auto
rhs_major
=
ys_to_rhs_major
{}[
i_dim_y
];
constexpr
auto
target_h_dim
=
number
<
rhs_major
-
1
>
{};
// no r dim here!
if
constexpr
(
LinearBottomDims
{}[
target_h_dim
]
==
0
)
{
return
number
<
0
>
{};
}
else
{
return
number
<
idx_ys
[
i_dim_y
]
>
{};
}
},
number
<
NDimY
>
{});
constexpr
auto
adaptor_
=
TileDstr
{}.
get_ps_ys_to_xs_adaptor
();
constexpr
auto
idx_
=
container_concat
(
make_tuple
(
number
<
0
>
{},
number
<
0
>
{}),
modified_idx_ys
);
return
adaptor_
.
calculate_bottom_index
(
idx_
);
}
template
<
index_t
i_access
>
CK_TILE_DEVICE
static
constexpr
index_t
get_bottom_linear_offset
(
number
<
i_access
>
)
{
constexpr
auto
linear_coord
=
get_bottom_linear_coordinate
(
number
<
i_access
>
{});
// since this is linear offset, we assum bottom X tensor is always linear
constexpr
index_t
linear_offset
=
[
&
]()
{
constexpr
auto
x_idx_
=
linear_coord
;
constexpr
auto
x_len_
=
TileDstr
{}.
get_lengths
();
static_assert
(
x_idx_
.
size
()
==
x_len_
.
size
());
constexpr
index_t
x_dims_
=
x_idx_
.
size
();
index_t
cu_stride_
=
1
;
index_t
cu_offset_
=
0
;
static_for
<
0
,
x_dims_
,
1
>
{}([
&
](
auto
i_
)
{
auto
r_i_
=
number
<
x_dims_
-
i_
-
1
>
{};
cu_offset_
+=
x_idx_
[
r_i_
]
*
cu_stride_
;
cu_stride_
*=
x_len_
[
r_i_
];
});
return
cu_offset_
;
}();
return
linear_offset
;
}
CK_TILE_DEVICE
constexpr
auto
get_num_of_access
()
const
{
return
traits
::
NumAccess
;
}
template
<
index_t
i_access
=
-
1
,
bool
oob_conditional_check
=
true
>
CK_TILE_DEVICE
auto
load
(
number
<
i_access
>
=
{},
bool_constant
<
oob_conditional_check
>
=
{})
const
{
using
vector_t
=
typename
traits
::
vector_t
;
using
SFC_Ys
=
typename
traits
::
SFC_Ys
;
constexpr
auto
tile_dstr
=
TileDstr
{};
auto
dst_tensor
=
make_static_distributed_tensor
<
DataType
>
(
tile_dstr
);
auto
issue
=
[
&
](
auto
i_access_
)
{
constexpr
auto
IAccess
=
number
<
i_access_
>
{};
constexpr
auto
non_linear_id
=
number
<
AccessMap_NonLinear
{}[
IAccess
]
>
{};
auto
bottom_tensor_thread_coord
=
cached_coords_
[
non_linear_id
];
auto
bottom_tensor_flag
=
cached_flags_
[
IAccess
];
constexpr
auto
linear_offset
=
get_bottom_linear_offset
(
IAccess
);
// read from bottom tensor
const
vector_t
vec_value
=
get_bottom_tensor_view
().
template
get_vectorized_elements
<
vector_t
>(
bottom_tensor_thread_coord
,
linear_offset
,
bottom_tensor_flag
,
bool_constant
<
oob_conditional_check
>
{});
#if 1
// data index [y0, y1, ...]
constexpr
auto
idx_diff_ys
=
SFC_Ys
::
get_index
(
IAccess
);
// write into distributed tensor
static_for
<
0
,
traits
::
ScalarPerVector
,
1
>
{}([
&
](
auto
j
)
{
constexpr
auto
idx_ys
=
generate_tuple
(
[
&
](
auto
jj
)
{
return
jj
==
traits
::
VectorDimY
?
(
idx_diff_ys
[
jj
]
+
j
)
:
idx_diff_ys
[
jj
];
},
number
<
NDimY
>
{});
constexpr
index_t
d
=
tile_dstr
.
get_ys_to_d_descriptor
().
calculate_offset
(
idx_ys
);
dst_tensor
.
get_thread_buffer
().
template
at
<
d
>()
=
vec_value
.
template
get_as
<
DataType
>()[
j
];
});
#else
constexpr
index_t
d
=
tile_dstr
.
get_ys_to_d_descriptor
().
calculate_offset
(
idx_ys_start
);
static_assert
(
d
%
traits
::
ScalarPerVector
==
0
);
dst_tensor
.
get_thread_buffer
().
template
get_as
<
vector_t
>()(
number
<
d
/
traits
::
ScalarPerVector
>
{})
=
bit_cast
<
vector_t
>
(
vec_value
);
#endif
};
WINDOW_DISPATCH_ISSUE
();
return
dst_tensor
;
}
template
<
typename
DstTile
,
index_t
i_access
=
-
1
,
bool
oob_conditional_check
=
true
,
bool
pre_nop
=
false
>
CK_TILE_DEVICE
void
load_raw
(
DstTile
&
dst_tensor
,
number
<
i_access
>
=
{},
// negative means loop over all num_access
bool_constant
<
oob_conditional_check
>
=
{},
bool_constant
<
pre_nop
>
=
{})
const
{
using
vector_t
=
typename
traits
::
vector_t
;
using
SFC_Ys
=
typename
traits
::
SFC_Ys
;
static
constexpr
index_t
YElementSize
=
TileDstr
{}.
get_ys_to_d_descriptor
().
get_element_space_size
();
static_assert
(
YElementSize
%
traits
::
ScalarPerVector
==
0
);
using
vectorized_tbuf
=
array
<
vector_t
,
YElementSize
/
traits
::
ScalarPerVector
>
;
constexpr
auto
tile_dstr
=
TileDstr
{};
auto
&
dst_vec_tbuf
=
reinterpret_cast
<
vectorized_tbuf
&>
(
dst_tensor
.
get_thread_buffer
());
auto
issue
=
[
&
](
auto
i_access_
)
{
constexpr
auto
IAccess
=
number
<
i_access_
>
{};
constexpr
auto
pre_nop_
=
[
&
]()
{
if
constexpr
(
pre_nop
&&
i_access_
==
0
&&
BottomTensorView
::
buffer_view
::
get_address_space
()
==
address_space_enum
::
global
)
return
bool_constant
<
true
>
{};
else
return
bool_constant
<
false
>
{};
}();
constexpr
auto
non_linear_id
=
number
<
AccessMap_NonLinear
{}[
IAccess
]
>
{};
auto
bottom_tensor_thread_coord
=
cached_coords_
[
non_linear_id
];
constexpr
auto
linear_offset
=
get_bottom_linear_offset
(
IAccess
);
auto
bottom_tensor_flag
=
cached_flags_
[
IAccess
];
// data index [y0, y1, ...]
constexpr
auto
idx_ys_start
=
SFC_Ys
::
get_index
(
IAccess
);
constexpr
index_t
d
=
tile_dstr
.
get_ys_to_d_descriptor
().
calculate_offset
(
idx_ys_start
);
static_assert
(
d
%
traits
::
ScalarPerVector
==
0
);
get_bottom_tensor_view
().
template
get_vectorized_elements_raw
<
vector_t
>(
dst_vec_tbuf
.
template
at
<
d
/
traits
::
ScalarPerVector
>(),
bottom_tensor_thread_coord
,
linear_offset
/**/
,
bottom_tensor_flag
,
bool_constant
<
oob_conditional_check
>
{},
pre_nop_
);
#if CK_TILE_WORKAROUND_ROCM_6_1_SCRATCH_MEMORY_ISSUE || \
CK_TILE_WORKAROUND_ROCM_6_2_SCRATCH_MEMORY_ISSUE
asm
volatile
(
""
);
// this is starting from rocm-6.2, but same sympton, reuse this flag
#endif
};
WINDOW_DISPATCH_ISSUE
();
}
// TODO: currently async load only implemented in inline asm
template
<
typename
LdsTileWindow_
,
index_t
i_access
=
-
1
,
bool
oob_conditional_check
=
true
,
bool
pre_nop
=
false
>
CK_TILE_DEVICE
auto
async_load_raw
(
LdsTileWindow_
&&
lds_tile
,
number
<
i_access
>
=
{},
bool_constant
<
oob_conditional_check
>
=
{},
bool_constant
<
pre_nop
>
=
{})
const
{
using
LdsTileWindow
=
remove_cvref_t
<
LdsTileWindow_
>
;
using
LdsDataType
=
typename
LdsTileWindow
::
DataType
;
// currently we only support everything is non linear dim
// actually it's not performant if we have linear dim(e.g. fast changing)
static_assert
(
NumAccess_NonLinear
==
NumAccess
);
static_assert
(
BottomTensorView
::
buffer_view
::
get_address_space
()
==
address_space_enum
::
global
);
// issues * warps * lanes
static_assert
(
LdsTileWindow
::
get_num_of_dimension
()
==
3
);
// TODO: hard coded
const
index_t
size_per_buf
=
lds_tile
.
get_bottom_tensor_view
().
get_tensor_descriptor
().
calculate_offset
(
make_tuple
(
number
<
0
>
{},
number
<
0
>
{},
number
<
0
>
{}))
*
sizeof
(
LdsDataType
);
const
index_t
size_per_wave
=
lds_tile
.
get_bottom_tensor_view
().
get_tensor_descriptor
().
calculate_offset
(
make_tuple
(
number
<
0
>
{},
number
<
1
>
{},
number
<
0
>
{}))
*
sizeof
(
LdsDataType
)
-
size_per_buf
;
const
index_t
size_per_issue
=
lds_tile
.
get_bottom_tensor_view
().
get_tensor_descriptor
().
calculate_offset
(
make_tuple
(
number
<
1
>
{},
number
<
0
>
{},
number
<
0
>
{}))
*
sizeof
(
LdsDataType
)
-
size_per_buf
;
const
index_t
m0_init_value
=
size_per_buf
+
size_per_wave
*
get_warp_id
();
m0_set_with_memory
(
m0_init_value
);
// This should be wave independent
using
vector_t
=
typename
traits
::
vector_t
;
LdsDataType
*
smem
=
lds_tile
.
get_bottom_tensor_view
().
get_buffer_view
().
p_data_
;
// loop over thread tensor space [y0, y1, ...]
auto
issue
=
[
&
](
auto
i_access_
)
{
constexpr
auto
IAccess
=
number
<
i_access_
>
{};
constexpr
auto
pre_nop_
=
[
&
]()
{
if
constexpr
(
pre_nop
&&
i_access_
==
0
)
return
bool_constant
<
true
>
{};
else
return
bool_constant
<
false
>
{};
}();
constexpr
auto
non_linear_id
=
number
<
AccessMap_NonLinear
{}[
IAccess
]
>
{};
auto
bottom_tensor_thread_coord
=
cached_coords_
[
non_linear_id
];
auto
bottom_tensor_flag
=
cached_flags_
[
IAccess
];
// get this flag anyway
// read from bottom tensor
get_bottom_tensor_view
().
template
async_get_vectorized_elements_raw
<
vector_t
>(
smem
,
bottom_tensor_thread_coord
,
0
,
bottom_tensor_flag
,
pre_nop_
);
// move thread coordinate
if
constexpr
(
i_access_
!=
(
NumAccess
-
1
))
{
m0_inc_with_memory
(
size_per_issue
);
}
};
WINDOW_DISPATCH_ISSUE
();
}
template
<
typename
LdsTileWindow_
,
index_t
i_access
=
-
1
,
bool
oob_conditional_check
=
true
>
CK_TILE_DEVICE
auto
async_load
(
LdsTileWindow_
&&
lds_tile
,
number
<
i_access
>
=
{},
bool_constant
<
oob_conditional_check
>
=
{})
const
{
using
LdsTileWindow
=
remove_cvref_t
<
LdsTileWindow_
>
;
using
LdsDataType
=
typename
LdsTileWindow
::
DataType
;
// currently we only support everything is non linear dim
// actually it's not performant if we have linear dim(e.g. fast changing)
static_assert
(
NumAccess_NonLinear
==
NumAccess
);
static_assert
(
BottomTensorView
::
buffer_view
::
get_address_space
()
==
address_space_enum
::
global
);
// issues * warps * lanes
static_assert
(
LdsTileWindow
::
get_num_of_dimension
()
==
3
);
// TODO: hard coded
// TODO: LDS offset is not good for intrinsic based implementation(compiler can't figure out
// dependency) hence avoid use offset based solution. size_per_buf should be zero (how to
// check?)
constexpr
index_t
size_per_buf
=
lds_tile
.
get_bottom_tensor_view
().
get_tensor_descriptor
().
calculate_offset
(
make_tuple
(
number
<
0
>
{},
number
<
0
>
{},
number
<
0
>
{}));
constexpr
index_t
size_per_wave
=
lds_tile
.
get_bottom_tensor_view
().
get_tensor_descriptor
().
calculate_offset
(
make_tuple
(
number
<
0
>
{},
number
<
1
>
{},
number
<
0
>
{}))
-
size_per_buf
;
constexpr
index_t
size_per_issue
=
lds_tile
.
get_bottom_tensor_view
().
get_tensor_descriptor
().
calculate_offset
(
make_tuple
(
number
<
1
>
{},
number
<
0
>
{},
number
<
0
>
{}))
-
size_per_buf
;
const
index_t
m0_init_value
=
size_per_buf
+
size_per_wave
*
get_warp_id
();
using
vector_t
=
typename
traits
::
vector_t
;
// TODO: we force CK_TILE_LDS_ADDR
CK_TILE_LDS_ADDR
LdsDataType
*
smem
=
lds_tile
.
get_bottom_tensor_view
().
get_buffer_view
().
p_data_
+
m0_init_value
;
// loop over thread tensor space [y0, y1, ...]
auto
issue
=
[
&
](
auto
i_access_
)
{
constexpr
auto
IAccess
=
number
<
i_access_
>
{};
constexpr
auto
non_linear_id
=
number
<
AccessMap_NonLinear
{}[
IAccess
]
>
{};
auto
bottom_tensor_thread_coord
=
cached_coords_
[
non_linear_id
];
auto
bottom_tensor_flag
=
cached_flags_
[
IAccess
];
// read from bottom tensor
get_bottom_tensor_view
().
template
async_get_vectorized_elements
<
vector_t
>(
smem
,
bottom_tensor_thread_coord
,
0
,
bottom_tensor_flag
,
bool_constant
<
oob_conditional_check
>
{});
// move thread coordinate
if
constexpr
(
i_access_
!=
(
NumAccess
-
1
))
{
smem
+=
size_per_issue
;
// Note we manually increase the per-issue offset
}
};
WINDOW_DISPATCH_ISSUE
();
}
template
<
index_t
i_access
=
-
1
,
bool
oob_conditional_check
=
true
>
CK_TILE_DEVICE
void
store
(
const
static_distributed_tensor
<
DataType
,
TileDstr
>&
dstr_tensor
,
number
<
i_access
>
=
{},
bool_constant
<
oob_conditional_check
>
=
{})
const
{
using
vector_t
=
typename
traits
::
vector_t
;
using
SFC_Ys
=
typename
traits
::
SFC_Ys
;
constexpr
auto
tile_dstr
=
TileDstr
{};
// loop over thread tensor space [y0, y1, ...]
auto
issue
=
[
&
](
auto
i_access_
)
{
constexpr
auto
IAccess
=
number
<
i_access_
>
{};
constexpr
auto
non_linear_id
=
number
<
AccessMap_NonLinear
{}[
IAccess
]
>
{};
auto
bottom_tensor_thread_coord
=
cached_coords_
[
non_linear_id
];
constexpr
auto
linear_offset
=
get_bottom_linear_offset
(
IAccess
);
auto
bottom_tensor_flag
=
cached_flags_
[
IAccess
];
// data index [y0, y1, ...]
constexpr
auto
idx_ys_start
=
SFC_Ys
::
get_index
(
IAccess
);
// read from distributed tensor
vector_t
vec_value
;
static_for
<
0
,
traits
::
ScalarPerVector
,
1
>
{}([
&
](
auto
j
)
{
constexpr
auto
idx_ys
=
generate_tuple
(
[
&
](
auto
jj
)
{
return
jj
==
traits
::
VectorDimY
?
(
idx_ys_start
[
jj
]
+
j
)
:
idx_ys_start
[
jj
];
},
number
<
NDimY
>
{});
constexpr
index_t
d
=
tile_dstr
.
get_ys_to_d_descriptor
().
calculate_offset
(
idx_ys
);
vec_value
.
template
get_as
<
DataType
>()(
j
)
=
dstr_tensor
.
get_thread_buffer
().
template
at
<
d
>();
});
// write into bottom tensor
get_bottom_tensor_view
().
template
set_vectorized_elements
<
vector_t
>(
bottom_tensor_thread_coord
,
linear_offset
,
bottom_tensor_flag
,
vec_value
,
bool_constant
<
oob_conditional_check
>
{});
};
WINDOW_DISPATCH_ISSUE
();
}
template
<
index_t
i_access
=
-
1
>
CK_TILE_DEVICE
void
store_raw
(
const
static_distributed_tensor
<
DataType
,
TileDstr
>&
dstr_tensor
,
number
<
i_access
>
=
{})
const
{
using
vector_t
=
typename
traits
::
vector_t
;
using
SFC_Ys
=
typename
traits
::
SFC_Ys
;
constexpr
auto
tile_dstr
=
TileDstr
{};
static
constexpr
bool
oob_conditional_check
=
true
;
// loop over thread tensor space [y0, y1, ...]
auto
issue
=
[
&
](
auto
i_access_
)
{
constexpr
auto
IAccess
=
number
<
i_access_
>
{};
constexpr
auto
non_linear_id
=
number
<
AccessMap_NonLinear
{}[
IAccess
]
>
{};
auto
bottom_tensor_thread_coord
=
cached_coords_
[
non_linear_id
];
constexpr
auto
linear_offset
=
get_bottom_linear_offset
(
IAccess
);
auto
bottom_tensor_flag
=
cached_flags_
[
IAccess
];
// data index [y0, y1, ...]
constexpr
auto
idx_ys_start
=
SFC_Ys
::
get_index
(
IAccess
);
// read from distributed tensor
vector_t
vec_value
;
static_for
<
0
,
traits
::
ScalarPerVector
,
1
>
{}([
&
](
auto
j
)
{
constexpr
auto
idx_ys
=
generate_tuple
(
[
&
](
auto
jj
)
{
return
jj
==
traits
::
VectorDimY
?
(
idx_ys_start
[
jj
]
+
j
)
:
idx_ys_start
[
jj
];
},
number
<
NDimY
>
{});
constexpr
index_t
d
=
tile_dstr
.
get_ys_to_d_descriptor
().
calculate_offset
(
idx_ys
);
vec_value
.
template
get_as
<
DataType
>()(
j
)
=
dstr_tensor
.
get_thread_buffer
().
template
at
<
d
>();
});
// write into bottom tensor
get_bottom_tensor_view
()
.
template
set_vectorized_elements_raw
<
vector_t
,
oob_conditional_check
>(
bottom_tensor_thread_coord
,
linear_offset
,
bottom_tensor_flag
,
vec_value
);
};
WINDOW_DISPATCH_ISSUE
();
}
template
<
index_t
i_access
=
-
1
,
bool
oob_conditional_check
=
true
>
CK_TILE_DEVICE
void
update
(
const
static_distributed_tensor
<
DataType
,
TileDstr
>&
dstr_tensor
,
number
<
i_access
>
=
{},
bool_constant
<
oob_conditional_check
>
=
{})
const
{
using
vector_t
=
typename
traits
::
vector_t
;
using
SFC_Ys
=
typename
traits
::
SFC_Ys
;
constexpr
auto
tile_dstr
=
TileDstr
{};
// loop over thread tensor space [y0, y1, ...]
auto
issue
=
[
&
](
auto
i_access_
)
{
constexpr
auto
IAccess
=
number
<
i_access_
>
{};
constexpr
auto
non_linear_id
=
number
<
AccessMap_NonLinear
{}[
IAccess
]
>
{};
auto
bottom_tensor_thread_coord
=
cached_coords_
[
non_linear_id
];
constexpr
auto
linear_offset
=
get_bottom_linear_offset
(
IAccess
);
auto
bottom_tensor_flag
=
cached_flags_
[
IAccess
];
// data index [y0, y1, ...]
constexpr
auto
idx_ys_start
=
SFC_Ys
::
get_index
(
IAccess
);
// read from distributed tensor
vector_t
vec_value
;
static_for
<
0
,
traits
::
ScalarPerVector
,
1
>
{}([
&
](
auto
j
)
{
constexpr
auto
idx_ys
=
generate_tuple
(
[
&
](
auto
jj
)
{
return
jj
==
traits
::
VectorDimY
?
(
idx_ys_start
[
jj
]
+
j
)
:
idx_ys_start
[
jj
];
},
number
<
NDimY
>
{});
constexpr
index_t
d
=
tile_dstr
.
get_ys_to_d_descriptor
().
calculate_offset
(
idx_ys
);
vec_value
.
template
get_as
<
DataType
>()(
j
)
=
dstr_tensor
.
get_thread_buffer
().
template
at
<
d
>();
});
// write into bottom tensor
get_bottom_tensor_view
().
template
update_vectorized_elements
<
vector_t
>(
bottom_tensor_thread_coord
,
linear_offset
,
bottom_tensor_flag
,
vec_value
,
bool_constant
<
oob_conditional_check
>
{});
};
WINDOW_DISPATCH_ISSUE
();
}
// move thread's botom tensor coordiante
// [x0', x1', ... ] ==> [offset]
// also move window-origin
CK_TILE_DEVICE
void
move
(
const
BottomTensorIndex
&
step
)
{
window_origin_
+=
step
;
static_for
<
0
,
NumAccess
,
1
>
{}([
&
](
auto
i_access
)
{
constexpr
auto
IAccess
=
number
<
i_access
>
{};
constexpr
auto
non_linear_id
=
number
<
AccessMap_NonLinear
{}[
i_access
]
>
{};
constexpr
auto
need_update_non_linear_coord
=
bool_constant
<
AccessPrefixSum_NonLinear
{}[
non_linear_id
]
==
i_access
>
{};
if
constexpr
(
need_update_non_linear_coord
)
{
move_tensor_coordinate
(
bottom_tensor_view_
.
get_tensor_descriptor
(),
cached_coords_
(
non_linear_id
),
step
);
}
// move the current coord with linear_coords
auto
tmp_coords
=
cached_coords_
[
non_linear_id
];
constexpr
auto
linear_coord
=
get_bottom_linear_coordinate
(
IAccess
);
move_tensor_coordinate
(
bottom_tensor_view_
.
get_tensor_descriptor
(),
tmp_coords
,
linear_coord
);
cached_flags_
(
IAccess
)
=
coordinate_has_valid_offset_assuming_top_index_is_valid
(
bottom_tensor_view_
.
get_tensor_descriptor
(),
tmp_coords
);
});
}
CK_TILE_DEVICE
void
set_window_origin
(
const
BottomTensorIndex
&
new_window_origin
)
{
window_origin_
=
new_window_origin
;
auto
window_adaptor_thread_coord_tmp
=
make_tensor_adaptor_coordinate
(
TileDstr
{}.
get_ps_ys_to_xs_adaptor
(),
container_concat
(
make_tuple
(
get_warp_id
(),
get_lane_id
()),
generate_tuple
([
&
](
auto
)
{
return
number
<
0
>
{};
},
number
<
NDimY
>
{})));
BottomTensorIndex
bottom_tensor_thread_origin_idx_tmp
=
window_origin_
+
window_adaptor_thread_coord_tmp
.
get_bottom_index
();
auto
bottom_tensor_thread_coord_tmp
=
make_tensor_coordinate
(
bottom_tensor_view_
.
get_tensor_descriptor
(),
bottom_tensor_thread_origin_idx_tmp
);
// future load/store() calls (might allocate more registers)
using
SFC_Ys
=
typename
traits
::
SFC_Ys
;
static_for
<
0
,
NumAccess
,
1
>
{}([
&
](
auto
i_access
)
{
constexpr
auto
non_linear_id
=
number
<
AccessMap_NonLinear
{}[
i_access
]
>
{};
constexpr
auto
need_save_non_linear_coord
=
bool_constant
<
AccessPrefixSum_NonLinear
{}[
non_linear_id
]
==
i_access
>
{};
if
constexpr
(
need_save_non_linear_coord
)
{
cached_coords_
(
non_linear_id
)
=
bottom_tensor_thread_coord_tmp
;
}
if
constexpr
(
i_access
!=
(
NumAccess
-
1
))
{
constexpr
auto
idx_diff_ys
=
SFC_Ys
::
get_forward_step
(
i_access
);
// tuple of number
constexpr
auto
idx_diff_ps_ys
=
container_concat
(
generate_tuple
([
&
](
auto
)
{
return
number
<
0
>
{};
},
number
<
NDimP
>
{}),
idx_diff_ys
);
move_window_adaptor_and_bottom_tensor_thread_coordinate
(
window_adaptor_thread_coord_tmp
,
bottom_tensor_thread_coord_tmp
,
idx_diff_ps_ys
);
}
});
}
CK_TILE_HOST_DEVICE
void
init_raw
()
{
bottom_tensor_view_
.
init_raw
();
}
// this is the bottom tensor view
// [x0', x1', ...] ==> [offset]
BottomTensorView
bottom_tensor_view_
;
//
WindowLengths
window_lengths_
;
// origin ([x0', x1', ...]) of window on bottom tensor
BottomTensorIndex
window_origin_
;
// Tile tensor distribution, which contains:
// 1. adaptor for window: [p0, p1, ..., y0, y1, ...] ==> [x0, x1, ...]
// 2. thread descriptor for thread tensor in register: [y0, y1, ...] ==> [d]
TileDstr
tile_dstr_
;
// this contains:
array
<
BottomTensorCoord
,
traits
::
NumAccess_NonLinear
>
cached_coords_
;
array
<
bool
,
traits
::
NumAccess
>
cached_flags_
;
};
#undef WINDOW_DISPATCH_ISSUE
namespace
impl
{
template
<
address_space_enum
,
index_t
len_
>
struct
default_linear_bottom_dims_impl
{
using
type
=
typename
uniform_sequence_gen
<
len_
,
0
>::
type
;
};
template
<
index_t
len_
>
struct
default_linear_bottom_dims_impl
<
address_space_enum
::
global
,
len_
>
{
// global default to seq<0,0,....1>
using
type
=
typename
sequence_merge
<
typename
uniform_sequence_gen
<
len_
-
1
,
0
>::
type
,
sequence
<
1
>>::
type
;
};
template
<
index_t
len_
>
struct
default_linear_bottom_dims_impl
<
address_space_enum
::
lds
,
len_
>
{
// lds default to seq<1,1.....1>
using
type
=
typename
uniform_sequence_gen
<
len_
,
1
>::
type
;
};
}
// namespace impl
template
<
typename
TensorView_
>
using
default_linear_bottom_dims
=
typename
impl
::
default_linear_bottom_dims_impl
<
TensorView_
::
buffer_view
::
get_address_space
(),
TensorView_
::
get_num_of_dimension
()
>::
type
;
// if using this API, will create a tile_window_linear
// this structure can have the chance to use immediate value, save register
// need pass in LinearBottomDims_ properly to control which dim is linear
// so to generate a constexpr offset as linear_offset for this dim
// (and finally pass to the immediate offset of buffer/lds instruction)
//
// Note: there is no internal check for which dim is OK to use linear offset
// user must make sure by themselves
//
// e.g.
// 2d global matrix, set LinearBottomDims_=seq<0, 1>, the last dim will generate
// immediate offset if each thread has multiple issue along last dim
//
// 2d LDS buffer, set LinearBottomDims_=seq<1, 1>, then only one vgpr used as offset
// everything else is just using immediate offset.
//
template
<
typename
TensorView_
,
typename
WindowLengths_
,
typename
StaticTileDistribution_
,
typename
LinearBottomDims_
=
default_linear_bottom_dims
<
TensorView_
>
>
CK_TILE_DEVICE
constexpr
auto
make_tile_window_linear
(
const
TensorView_
&
tensor_view
,
const
WindowLengths_
&
window_lengths
,
const
multi_index
<
TensorView_
::
get_num_of_dimension
()
>&
origin
,
const
StaticTileDistribution_
&
tile_distribution
,
LinearBottomDims_
=
{})
{
static_assert
(
LinearBottomDims_
::
size
()
==
TensorView_
::
get_num_of_dimension
());
return
tile_window_linear
<
remove_cvref_t
<
TensorView_
>
,
remove_cvref_t
<
WindowLengths_
>
,
remove_cvref_t
<
StaticTileDistribution_
>
,
remove_cvref_t
<
LinearBottomDims_
>>
{
tensor_view
,
window_lengths
,
origin
,
tile_distribution
};
}
template
<
typename
TileWindow_
,
typename
StaticTileDistribution_
,
typename
LinearBottomDims_
=
default_linear_bottom_dims
<
typename
TileWindow_
::
BottomTensorView
>
>
CK_TILE_DEVICE
constexpr
auto
make_tile_window_linear
(
const
TileWindow_
&
tile_window
,
const
StaticTileDistribution_
&
tile_distribution
,
LinearBottomDims_
=
{})
{
return
make_tile_window_linear
(
tile_window
.
get_bottom_tensor_view
(),
tile_window
.
get_window_lengths
(),
tile_window
.
get_window_origin
(),
tile_distribution
,
LinearBottomDims_
{});
}
// this version must not be called under a constexpr context
template
<
typename
TensorView_
,
typename
WindowLengths_
,
typename
StaticTileDistribution_
,
typename
LinearBottomDims_
=
default_linear_bottom_dims
<
TensorView_
>
>
CK_TILE_DEVICE
auto
make_tile_window_linear_raw
(
const
TensorView_
&
tensor_view
,
const
WindowLengths_
&
window_lengths
,
const
multi_index
<
TensorView_
::
get_num_of_dimension
()
>&
origin
,
const
StaticTileDistribution_
&
tile_distribution
,
LinearBottomDims_
=
{})
{
static_assert
(
LinearBottomDims_
::
size
()
==
TensorView_
::
get_num_of_dimension
());
auto
w
=
tile_window_linear
<
remove_cvref_t
<
TensorView_
>
,
remove_cvref_t
<
WindowLengths_
>
,
remove_cvref_t
<
StaticTileDistribution_
>
,
remove_cvref_t
<
LinearBottomDims_
>>
{
tensor_view
,
window_lengths
,
origin
,
tile_distribution
};
w
.
init_raw
();
return
w
;
}
template
<
typename
TileWindow_
,
typename
StaticTileDistribution_
,
typename
LinearBottomDims_
=
default_linear_bottom_dims
<
typename
TileWindow_
::
BottomTensorView
>
>
CK_TILE_DEVICE
constexpr
auto
make_tile_window_linear_raw
(
const
TileWindow_
&
tile_window
,
const
StaticTileDistribution_
&
tile_distribution
,
LinearBottomDims_
=
{})
{
return
make_tile_window_linear_raw
(
tile_window
.
get_bottom_tensor_view
(),
tile_window
.
get_window_lengths
(),
tile_window
.
get_window_origin
(),
tile_distribution
,
LinearBottomDims_
{});
}
template
<
typename
TensorView_
,
typename
WindowLengths_
,
typename
StaticTileDistribution_
,
typename
LinearBottomDims_
>
CK_TILE_DEVICE
void
move_tile_window
(
tile_window_linear
<
TensorView_
,
WindowLengths_
,
StaticTileDistribution_
,
LinearBottomDims_
>&
window
,
const
typename
tile_window_linear
<
TensorView_
,
WindowLengths_
,
StaticTileDistribution_
,
LinearBottomDims_
>::
BottomTensorIndex
&
step
)
{
window
.
move
(
step
);
}
}
// namespace ck_tile
include/ck_tile/core/utility/literals.hpp
0 → 100644
View file @
7d50244e
// SPDX-License-Identifier: MIT
// Copyright (c) 2024, Advanced Micro Devices, Inc. All rights reserved.
#pragma once
#include <cstdlib>
namespace
ck_tile
{
namespace
literals
{
// [P0330] Literal Suffix for (signed) size_t (C++23)
// ref: https://wg21.link/p0330r8
inline
constexpr
std
::
size_t
operator
""
_uz
(
unsigned
long
long
size
)
{
return
static_cast
<
std
::
size_t
>
(
size
);
}
inline
constexpr
std
::
size_t
operator
""
_zu
(
unsigned
long
long
size
)
{
return
static_cast
<
std
::
size_t
>
(
size
);
}
}
// namespace literals
}
// namespace ck_tile
include/ck_tile/core/utility/magic_div.hpp
View file @
7d50244e
...
...
@@ -59,8 +59,16 @@ struct magic_division32_bit_range
CK_TILE_DEVICE
static
constexpr
uint32_t
do_magic_division
(
uint32_t
dividend
,
uint32_t
multiplier
,
uint32_t
shift
)
{
uint32_t
tmp
=
__umulhi
(
dividend
,
multiplier
);
return
(
tmp
+
dividend
)
>>
shift
;
if
(
__builtin_is_constant_evaluated
())
{
uint32_t
tmp
=
(
static_cast
<
uint64_t
>
(
dividend
)
*
multiplier
)
>>
32
;
return
(
tmp
+
dividend
)
>>
shift
;
}
else
{
uint32_t
tmp
=
__umulhi
(
dividend
,
multiplier
);
return
(
tmp
+
dividend
)
>>
shift
;
}
}
CK_TILE_HOST
static
constexpr
uint32_t
...
...
@@ -77,9 +85,18 @@ struct magic_division32_bit_range
CK_TILE_DEVICE
static
constexpr
int32_t
do_magic_division
(
int32_t
dividend_i32
,
uint32_t
multiplier
,
uint32_t
shift
)
{
uint32_t
dividend_u32
=
bit_cast
<
uint32_t
>
(
dividend_i32
);
uint32_t
tmp
=
__umulhi
(
dividend_u32
,
multiplier
);
return
(
tmp
+
dividend_u32
)
>>
shift
;
if
(
__builtin_is_constant_evaluated
())
{
uint32_t
dividend_u32
=
bit_cast
<
uint32_t
>
(
dividend_i32
);
uint32_t
tmp
=
(
static_cast
<
uint64_t
>
(
dividend_u32
)
*
multiplier
)
>>
32
;
return
(
tmp
+
dividend_u32
)
>>
shift
;
}
else
{
uint32_t
dividend_u32
=
bit_cast
<
uint32_t
>
(
dividend_i32
);
uint32_t
tmp
=
__umulhi
(
dividend_u32
,
multiplier
);
return
(
tmp
+
dividend_u32
)
>>
shift
;
}
}
CK_TILE_HOST
static
constexpr
int32_t
...
...
include/ck_tile/core/utility/reduce_operator.hpp
0 → 100644
View file @
7d50244e
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2024, Advanced Micro Devices, Inc. All rights reserved.
#pragma once
#include "ck_tile/core/config.hpp"
namespace
ck_tile
{
namespace
ReduceOp
{
// y = ReduceOp(y, x);
struct
Add
{
template
<
typename
T
>
CK_TILE_HOST_DEVICE
static
constexpr
T
GetIdentityValue
()
{
return
type_convert
<
T
>
(
0.0
f
);
};
template
<
typename
T
,
typename
=
std
::
enable_if_t
<
std
::
is_same_v
<
T
,
float
>
||
std
::
is_same_v
<
T
,
double
>
||
std
::
is_same_v
<
T
,
int32_t
>
||
std
::
is_same_v
<
T
,
int8_t
>>>
CK_TILE_HOST_DEVICE
constexpr
T
operator
()(
const
T
&
y
,
const
T
x
)
const
{
return
y
+
x
;
}
template
<
typename
T
,
typename
=
std
::
enable_if_t
<
std
::
is_same_v
<
T
,
half_t
>
||
std
::
is_same_v
<
T
,
bf16_t
>>>
CK_TILE_HOST_DEVICE
constexpr
T
operator
()(
T
&
y
,
T
x
)
const
{
float
y_
=
type_convert
<
float
>
(
y
);
float
x_
=
type_convert
<
float
>
(
x
);
return
type_convert
<
T
>
(
y_
+
x_
);
}
};
struct
SquareAdd
{
template
<
typename
T
>
CK_TILE_HOST_DEVICE
static
constexpr
T
GetIdentityValue
()
{
return
type_convert
<
T
>
(
0.0
f
);
};
template
<
typename
T
,
typename
=
std
::
enable_if_t
<
std
::
is_same_v
<
T
,
float
>
||
std
::
is_same_v
<
T
,
double
>
||
std
::
is_same_v
<
T
,
int32_t
>
||
std
::
is_same_v
<
T
,
int8_t
>>>
CK_TILE_HOST_DEVICE
constexpr
T
operator
()(
const
T
&
y
,
const
T
x
)
const
{
return
y
+
(
x
*
x
);
}
};
struct
Max
{
template
<
typename
T
,
typename
=
std
::
enable_if_t
<
std
::
is_same_v
<
T
,
float
>
||
std
::
is_same_v
<
T
,
double
>
||
std
::
is_same_v
<
T
,
int32_t
>
||
std
::
is_same_v
<
T
,
int8_t
>>>
CK_TILE_HOST_DEVICE
static
constexpr
T
GetIdentityValue
()
{
return
numeric
<
T
>::
min
();
};
template
<
typename
T
,
typename
=
std
::
enable_if_t
<
std
::
is_same_v
<
T
,
float
>
||
std
::
is_same_v
<
T
,
double
>
||
std
::
is_same_v
<
T
,
int32_t
>
||
std
::
is_same_v
<
T
,
int8_t
>>>
CK_TILE_HOST_DEVICE
constexpr
T
operator
()(
const
T
&
y
,
const
T
x
)
const
{
return
max
(
y
,
x
);
}
};
struct
AbsMax
{
template
<
typename
T
,
typename
=
std
::
enable_if_t
<
std
::
is_same_v
<
T
,
float
>
||
std
::
is_same_v
<
T
,
double
>
||
std
::
is_same_v
<
T
,
int32_t
>
||
std
::
is_same_v
<
T
,
int8_t
>>>
CK_TILE_HOST_DEVICE
static
constexpr
T
GetIdentityValue
()
{
return
numeric
<
T
>::
min
();
};
template
<
typename
T
,
typename
=
std
::
enable_if_t
<
std
::
is_same_v
<
T
,
float
>
||
std
::
is_same_v
<
T
,
double
>
||
std
::
is_same_v
<
T
,
int32_t
>
||
std
::
is_same_v
<
T
,
int8_t
>>>
CK_TILE_HOST_DEVICE
constexpr
T
operator
()(
const
T
&
y
,
const
T
x
)
const
{
return
max
(
y
,
abs
(
x
));
}
};
}
// namespace ReduceOp
}
// namespace ck_tile
include/ck_tile/host.hpp
View file @
7d50244e
...
...
@@ -19,10 +19,15 @@
#include "ck_tile/host/reference/reference_batched_masking.hpp"
#include "ck_tile/host/reference/reference_batched_rotary_position_embedding.hpp"
#include "ck_tile/host/reference/reference_batched_softmax.hpp"
#include "ck_tile/host/reference/reference_elementwise.hpp"
#include "ck_tile/host/reference/reference_gemm.hpp"
#include "ck_tile/host/reference/reference_im2col.hpp"
#include "ck_tile/host/reference/reference_layernorm2d_fwd.hpp"
#include "ck_tile/host/reference/reference_permute.hpp"
#include "ck_tile/host/reference/reference_reduce.hpp"
#include "ck_tile/host/reference/reference_rmsnorm2d_fwd.hpp"
#include "ck_tile/host/reference/reference_rowwise_quantization2d.hpp"
#include "ck_tile/host/reference/reference_softmax.hpp"
#include "ck_tile/host/reference/reference_topk.hpp"
#include "ck_tile/host/stream_config.hpp"
#include "ck_tile/host/timer.hpp"
Prev
1
…
4
5
6
7
8
9
10
11
12
…
15
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment