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
Commits
dea4506e
Commit
dea4506e
authored
May 17, 2023
by
Po-Yen, Chen
Browse files
Add overloaded version of __builtin_amdgcn_readfirstlane()
parent
642d5e91
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
0 deletions
+80
-0
include/ck/utility/common_header.hpp
include/ck/utility/common_header.hpp
+1
-0
include/ck/utility/readfirstlane.hpp
include/ck/utility/readfirstlane.hpp
+79
-0
No files found.
include/ck/utility/common_header.hpp
View file @
dea4506e
...
@@ -40,6 +40,7 @@
...
@@ -40,6 +40,7 @@
#include "ck/utility/amd_address_space.hpp"
#include "ck/utility/amd_address_space.hpp"
#include "ck/utility/static_buffer.hpp"
#include "ck/utility/static_buffer.hpp"
#include "ck/utility/dynamic_buffer.hpp"
#include "ck/utility/dynamic_buffer.hpp"
#include "ck/utility/readfirstlane.hpp"
// TODO: remove this
// TODO: remove this
#if CK_USE_AMD_INLINE_ASM
#if CK_USE_AMD_INLINE_ASM
...
...
include/ck/utility/readfirstlane.hpp
0 → 100644
View file @
dea4506e
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#pragma once
#include "ck/ck.hpp"
#include "ck/utility/functional2.hpp"
#include "ck/utility/math.hpp"
#include <cstdint>
#include <type_traits>
namespace
ck
{
namespace
detail
{
template
<
std
::
size_t
Size
>
struct
get_signed_int
;
template
<
>
struct
get_signed_int
<
1
>
{
using
type
=
std
::
int8_t
;
};
template
<
>
struct
get_signed_int
<
2
>
{
using
type
=
std
::
int16_t
;
};
template
<
>
struct
get_signed_int
<
4
>
{
using
type
=
std
::
int32_t
;
};
template
<
std
::
size_t
Size
>
using
get_signed_int_t
=
typename
get_signed_int
<
Size
>::
type
;
}
// namespace detail
__device__
std
::
int32_t
readfirstlane
(
std
::
int32_t
value
)
{
return
__builtin_amdgcn_readfirstlane
(
value
);
}
template
<
typename
Object
,
typename
=
std
::
enable_if_t
<
std
::
is_class_v
<
Object
>
&&
std
::
is_trivially_copyable_v
<
Object
>>>
__device__
auto
readfirstlane
(
const
Object
&
obj
)
{
static
constexpr
std
::
size_t
SgprSize
=
4
;
static
constexpr
std
::
size_t
ObjectSize
=
sizeof
(
Object
);
using
Sgpr
=
detail
::
get_signed_int_t
<
SgprSize
>
;
alignas
(
Object
)
unsigned
char
memory
[
ObjectSize
];
const
auto
*
from
=
reinterpret_cast
<
const
unsigned
char
*>
(
&
obj
);
static_for
<
0
,
ObjectSize
,
SgprSize
>
{}([
&
](
auto
offset
)
{
*
reinterpret_cast
<
Sgpr
*>
(
memory
+
offset
)
=
readfirstlane
(
*
reinterpret_cast
<
const
Sgpr
*>
(
from
+
offset
));
});
static
constexpr
std
::
size_t
RemainedSize
=
ObjectSize
%
SgprSize
;
if
constexpr
(
0
<
RemainedSize
)
{
using
Carrier
=
detail
::
get_signed_int_t
<
RemainedSize
>
;
constexpr
std
::
size_t
offset
=
SgprSize
*
math
::
integer_divide_floor
(
ObjectSize
,
SgprSize
);
*
reinterpret_cast
<
Carrier
>
(
memory
+
offset
)
=
readfirstlane
(
*
reinterpret_cast
<
const
Carrier
*>
(
from
+
offset
));
}
return
*
reinterpret_cast
<
Object
*>
(
memory
);
}
}
// namespace ck
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