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
3c3d701e
Commit
3c3d701e
authored
Dec 05, 2024
by
Astha Rai
Browse files
updated functionality in type utility file
parent
1694c70c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
316 additions
and
307 deletions
+316
-307
include/ck/utility/type.hpp
include/ck/utility/type.hpp
+316
-307
No files found.
include/ck/utility/type.hpp
View file @
3c3d701e
// SPDX-License-Identifier: MIT
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2024, Advanced Micro Devices, Inc. All rights reserved.
// Copyright (c) 2018-2024, Advanced Micro Devices, Inc. All rights reserved.
#pragma once
#pragma once
#include "ck/ck.hpp"
#include "ck/ck.hpp"
#include "ck/utility/enable_if.hpp"
#include "ck/utility/enable_if.hpp"
#include "ck/utility/integral_constant.hpp"
#include "ck/utility/integral_constant.hpp"
namespace
ck
{
namespace
ck
{
#ifdef CK_CODE_GEN_RTC
#ifdef CK_CODE_GEN_RTC
// NOLINTNEXTLINE
// NOLINTNEXTLINE
#define CK_BUILTIN_TYPE_TRAIT1(name) \
#define CK_BUILTIN_TYPE_TRAIT1(name) \
template <class T> \
template
<
class
T
>
\
struct name : bool_constant<__##name(T)> \
struct
name
:
bool_constant
<
__
##
name
(
T
)
>
\
{ \
{
\
}
}
// NOLINTNEXTLINE
// NOLINTNEXTLINE
#define CK_BUILTIN_TYPE_TRAIT2(name) \
#define CK_BUILTIN_TYPE_TRAIT2(name) \
template <class T, class U> \
template
<
class
T
,
class
U
>
\
struct name : bool_constant<__##name(T, U)> \
struct
name
:
bool_constant
<
__
##
name
(
T
,
U
)
>
\
{ \
{
\
}
}
// NOLINTNEXTLINE
// NOLINTNEXTLINE
#define CK_BUILTIN_TYPE_TRAITN(name) \
#define CK_BUILTIN_TYPE_TRAITN(name) \
template <class... Ts> \
template
<
class
...
Ts
>
\
struct name : bool_constant<__##name(Ts...)> \
struct
name
:
bool_constant
<
__
##
name
(
Ts
...)
>
\
{ \
{
\
}
}
CK_BUILTIN_TYPE_TRAIT1
(
is_class
);
CK_BUILTIN_TYPE_TRAIT1
(
is_class
);
CK_BUILTIN_TYPE_TRAIT1
(
is_pointer
);
CK_BUILTIN_TYPE_TRAIT1
(
is_pointer
);
CK_BUILTIN_TYPE_TRAIT1
(
is_reference
);
CK_BUILTIN_TYPE_TRAIT1
(
is_reference
);
CK_BUILTIN_TYPE_TRAIT1
(
is_trivially_copyable
);
CK_BUILTIN_TYPE_TRAIT1
(
is_trivially_copyable
);
CK_BUILTIN_TYPE_TRAIT1
(
is_unsigned
);
CK_BUILTIN_TYPE_TRAIT1
(
is_unsigned
);
CK_BUILTIN_TYPE_TRAIT2
(
is_base_of
);
CK_BUILTIN_TYPE_TRAIT2
(
is_base_of
);
template
<
class
T
>
template
<
class
T
>
struct
remove_cv
struct
remove_cv
{
{
using
type
=
T
;
using
type
=
T
;
};
};
template
<
class
T
>
template
<
class
T
>
struct
remove_cv
<
const
T
>
:
remove_cv
<
T
>
struct
remove_cv
<
const
T
>
:
remove_cv
<
T
>
{
{
};
};
template
<
class
T
>
template
<
class
T
>
struct
remove_cv
<
volatile
T
>
:
remove_cv
<
T
>
struct
remove_cv
<
volatile
T
>
:
remove_cv
<
T
>
{
{
};
};
template
<
class
T
>
template
<
class
T
>
struct
remove_reference
struct
remove_reference
{
{
typedef
T
type
;
typedef
T
type
;
};
};
template
<
class
T
>
template
<
class
T
>
struct
remove_reference
<
T
&>
struct
remove_reference
<
T
&>
{
{
typedef
T
type
;
typedef
T
type
;
};
};
template
<
class
T
>
template
<
class
T
>
struct
remove_reference
<
T
&&>
struct
remove_reference
<
T
&&>
{
{
typedef
T
type
;
typedef
T
type
;
};
};
template
<
class
T
>
template
<
class
T
>
struct
remove_pointer
struct
remove_pointer
{
{
typedef
T
type
;
typedef
T
type
;
};
};
template
<
class
T
>
template
<
class
T
>
struct
remove_pointer
<
T
*>
struct
remove_pointer
<
T
*>
{
{
typedef
T
type
;
typedef
T
type
;
};
};
template
<
class
T
>
template
<
class
T
>
struct
remove_pointer
<
T
*
const
>
struct
remove_pointer
<
T
*
const
>
{
{
typedef
T
type
;
typedef
T
type
;
};
};
template
<
class
T
>
template
<
class
T
>
struct
remove_pointer
<
T
*
volatile
>
struct
remove_pointer
<
T
*
volatile
>
{
{
typedef
T
type
;
typedef
T
type
;
};
};
template
<
class
T
>
template
<
class
T
>
struct
remove_pointer
<
T
*
const
volatile
>
struct
remove_pointer
<
T
*
const
volatile
>
{
{
typedef
T
type
;
typedef
T
type
;
};
};
template
<
class
T
>
template
<
typename
T
>
struct
remove_const
constexpr
T
&&
forward
(
typename
remove_reference
<
T
>::
type
&
t_
)
noexcept
{
{
typedef
T
type
;
return
static_cast
<
T
&&>
(
t_
);
};
}
template
<
class
T
>
template
<
typename
T
>
struct
remove_const
<
const
T
>
constexpr
T
&&
forward
(
typename
remove_reference
<
T
>::
type
&&
t_
)
noexcept
{
{
typedef
T
type
;
return
static_cast
<
T
&&>
(
t_
);
};
}
template
<
typename
T
>
template
<
class
T
>
constexpr
T
&&
forward
(
typename
remove_reference
<
T
>::
type
&
t_
)
noexcept
struct
is_const
:
public
integral_constant
<
bool
,
false
>
{
{
return
static_cast
<
T
&&>
(
t_
);
};
}
template
<
class
T
>
struct
is_const
<
const
T
>
:
public
integral_constant
<
bool
,
true
>
template
<
typename
T
>
{
constexpr
T
&&
forward
(
typename
remove_reference
<
T
>::
type
&&
t_
)
noexcept
};
{
template
<
class
T
>
return
static_cast
<
T
&&>
(
t_
);
inline
constexpr
bool
is_const_v
=
is_const
<
T
>::
value
;
}
template
<
typename
T
>
template
<
typename
T
>
inline
constexpr
bool
is_reference_v
=
is_reference
<
T
>::
value
;
T
&&
declval
()
noexcept
;
template
<
class
T
>
template
<
typename
...
Ts
>
struct
remove_const
using
void_t
=
void
;
{
#else
typedef
T
type
;
#include <utility>
};
#include <type_traits>
template
<
class
T
>
using
std
::
declval
;
struct
remove_const
<
const
T
>
using
std
::
forward
;
{
using
std
::
is_base_of
;
typedef
T
type
;
using
std
::
is_class
;
};
using
std
::
is_pointer
;
template
<
class
T
>
using
std
::
is_reference
;
using
remove_const_t
=
typename
remove_const
<
T
>::
type
;
using
std
::
is_trivially_copyable
;
template
<
class
T
>
using
std
::
is_unsigned
;
inline
constexpr
bool
is_class_v
=
is_class
<
T
>::
value
;
using
std
::
remove_const
;
using
std
::
remove_cv
;
template
<
class
T
>
using
std
::
remove_pointer
;
inline
constexpr
bool
is_trivially_copyable_v
=
is_trivially_copyable
<
T
>::
value
;
using
std
::
remove_reference
;
// template <typename T>
using
std
::
void_t
;
// T&& declval() noexcept;
#endif
template
<
class
T
,
class
U
=
T
&&
>
template
<
typename
X
,
typename
Y
>
U
private_declval
(
int
);
struct
is_same
:
public
integral_constant
<
bool
,
false
>
{
template
<
class
T
>
};
T
private_declval
(
long
);
template
<
typename
X
>
template
<
class
T
>
struct
is_same
<
X
,
X
>
:
public
integral_constant
<
bool
,
true
>
auto
declval
()
noexcept
->
decltype
(
private_declval
<
T
>
(
0
));
{
};
template
<
class
...
>
using
void_t
=
void
;
template
<
typename
X
>
#else
struct
is_const
:
public
integral_constant
<
bool
,
false
>
#include <utility>
{
#include <type_traits>
};
using
std
::
declval
;
using
std
::
forward
;
template
<
typename
X
>
using
std
::
is_base_of
;
struct
is_const
<
const
X
>
:
public
integral_constant
<
bool
,
true
>
using
std
::
is_class
;
{
using
std
::
is_class_v
;
};
using
std
::
is_const_v
;
using
std
::
is_pointer
;
template
<
typename
X
>
using
std
::
is_reference
;
struct
is_floating_point
:
public
integral_constant
<
bool
,
false
>
using
std
::
is_reference_v
;
{
using
std
::
is_trivially_copyable
;
};
using
std
::
is_trivially_copyable_v
;
using
std
::
is_unsigned
;
template
<
>
using
std
::
remove_const
;
struct
is_floating_point
<
float
>
:
public
integral_constant
<
bool
,
true
>
using
std
::
remove_cv
;
{
using
std
::
remove_pointer
;
};
using
std
::
remove_reference
;
using
std
::
void_t
;
template
<
>
#endif
struct
is_floating_point
<
double
>
:
public
integral_constant
<
bool
,
true
>
{
template
<
typename
X
,
typename
Y
>
};
struct
is_same
:
public
integral_constant
<
bool
,
false
>
{
template
<
>
};
struct
is_floating_point
<
long
double
>
:
public
integral_constant
<
bool
,
true
>
{
template
<
typename
X
>
};
struct
is_same
<
X
,
X
>
:
public
integral_constant
<
bool
,
true
>
{
template
<
typename
X
>
};
struct
is_integral
:
public
integral_constant
<
bool
,
false
>
{
template
<
typename
X
>
};
struct
is_floating_point
:
public
integral_constant
<
bool
,
false
>
{
template
<
>
};
struct
is_integral
<
int
>
:
public
integral_constant
<
bool
,
true
>
{
template
<
>
};
struct
is_floating_point
<
float
>
:
public
integral_constant
<
bool
,
true
>
{
template
<
>
};
struct
is_integral
<
unsigned
int
>
:
public
integral_constant
<
bool
,
true
>
{
template
<
>
};
struct
is_floating_point
<
double
>
:
public
integral_constant
<
bool
,
true
>
{
template
<
>
};
struct
is_integral
<
long
>
:
public
integral_constant
<
bool
,
true
>
template
<
>
{
struct
is_floating_point
<
long
double
>
:
public
integral_constant
<
bool
,
true
>
};
{
};
template
<
>
struct
is_integral
<
unsigned
long
>
:
public
integral_constant
<
bool
,
true
>
template
<
typename
X
>
{
struct
is_integral
:
public
integral_constant
<
bool
,
false
>
};
{
};
template
<
>
struct
is_integral
<
short
>
:
public
integral_constant
<
bool
,
true
>
template
<
>
{
struct
is_integral
<
int
>
:
public
integral_constant
<
bool
,
true
>
};
{
};
template
<
>
struct
is_integral
<
unsigned
short
>
:
public
integral_constant
<
bool
,
true
>
template
<
>
{
struct
is_integral
<
unsigned
int
>
:
public
integral_constant
<
bool
,
true
>
};
{
};
template
<
>
struct
is_integral
<
long
long
>
:
public
integral_constant
<
bool
,
true
>
template
<
>
{
struct
is_integral
<
long
>
:
public
integral_constant
<
bool
,
true
>
};
{
};
template
<
>
struct
is_integral
<
unsigned
long
long
>
:
public
integral_constant
<
bool
,
true
>
template
<
>
{
struct
is_integral
<
unsigned
long
>
:
public
integral_constant
<
bool
,
true
>
};
{
};
template
<
>
struct
is_integral
<
char
>
:
public
integral_constant
<
bool
,
true
>
template
<
>
{
struct
is_integral
<
short
>
:
public
integral_constant
<
bool
,
true
>
};
{
};
template
<
>
template
<
>
struct
is_integral
<
signed
char
>
:
public
integral_constant
<
bool
,
true
>
struct
is_integral
<
unsigned
short
>
:
public
integral_constant
<
bool
,
true
>
{
{
};
};
template
<
>
template
<
>
struct
is_integral
<
unsigned
char
>
:
public
integral_constant
<
bool
,
true
>
struct
is_integral
<
long
long
>
:
public
integral_constant
<
bool
,
true
>
{
{
};
};
template
<
>
template
<
>
struct
is_integral
<
wchar_t
>
:
public
integral_constant
<
bool
,
true
>
struct
is_integral
<
unsigned
long
long
>
:
public
integral_constant
<
bool
,
true
>
{
{
};
};
template
<
>
template
<
>
struct
is_integral
<
char16_t
>
:
public
integral_constant
<
bool
,
true
>
struct
is_integral
<
char
>
:
public
integral_constant
<
bool
,
true
>
{
{
};
};
template
<
>
template
<
>
struct
is_integral
<
char32_t
>
:
public
integral_constant
<
bool
,
true
>
struct
is_integral
<
signed
char
>
:
public
integral_constant
<
bool
,
true
>
{
{
};
};
template
<
>
template
<
>
struct
is_integral
<
bool
>
:
public
integral_constant
<
bool
,
true
>
struct
is_integral
<
unsigned
char
>
:
public
integral_constant
<
bool
,
true
>
{
{
};
};
template
<
typename
T
>
template
<
>
inline
constexpr
bool
is_reference_v
=
is_reference
<
T
>::
value
;
struct
is_integral
<
wchar_t
>
:
public
integral_constant
<
bool
,
true
>
{
template
<
typename
X
,
typename
Y
>
};
inline
constexpr
bool
is_same_v
=
is_same
<
X
,
Y
>::
value
;
template
<
>
struct
is_integral
<
char16_t
>
:
public
integral_constant
<
bool
,
true
>
template
<
typename
X
>
{
inline
constexpr
bool
is_const_v
=
is_const
<
X
>::
value
;
};
template
<
typename
X
,
typename
Y
>
template
<
>
inline
constexpr
bool
is_base_of_v
=
is_base_of
<
X
,
Y
>::
value
;
struct
is_integral
<
char32_t
>
:
public
integral_constant
<
bool
,
true
>
{
template
<
typename
T
>
};
inline
constexpr
bool
is_unsigned_v
=
is_unsigned
<
T
>::
value
;
template
<
>
template
<
typename
T
>
struct
is_integral
<
bool
>
:
public
integral_constant
<
bool
,
true
>
using
remove_reference_t
=
typename
remove_reference
<
T
>::
type
;
{
};
template
<
typename
T
>
using
remove_reference_t
=
typename
remove_reference
<
T
>::
type
;
template
<
typename
X
,
typename
Y
>
inline
constexpr
bool
is_same_v
=
is_same
<
X
,
Y
>::
value
;
template
<
typename
T
>
using
remove_cv_t
=
typename
remove_cv
<
T
>::
type
;
template
<
typename
X
,
typename
Y
>
inline
constexpr
bool
is_base_of_v
=
is_base_of
<
X
,
Y
>::
value
;
template
<
typename
T
>
using
remove_cvref_t
=
remove_cv_t
<
remove_reference_t
<
T
>>
;
template
<
typename
T
>
inline
constexpr
bool
is_unsigned_v
=
is_unsigned
<
T
>::
value
;
template
<
typename
T
>
using
remove_pointer_t
=
typename
remove_pointer
<
T
>::
type
;
template
<
typename
T
>
using
remove_reference_t
=
typename
remove_reference
<
T
>::
type
;
template
<
typename
T
>
using
remove_const_t
=
typename
remove_const
<
T
>::
type
;
template
<
typename
T
>
using
remove_reference_t
=
typename
remove_reference
<
T
>::
type
;
template
<
typename
T
>
inline
constexpr
bool
is_pointer_v
=
is_pointer
<
T
>::
value
;
template
<
typename
T
>
using
remove_cv_t
=
typename
remove_cv
<
T
>::
type
;
template
<
typename
Y
,
typename
X
,
typename
enable_if
<
sizeof
(
X
)
==
sizeof
(
Y
),
bool
>
::
type
=
false
>
template
<
typename
T
>
__host__
__device__
constexpr
Y
bit_cast
(
const
X
&
x
)
using
remove_cvref_t
=
remove_cv_t
<
remove_reference_t
<
T
>>
;
{
static_assert
(
__has_builtin
(
__builtin_bit_cast
),
""
);
template
<
typename
T
>
static_assert
(
sizeof
(
X
)
==
sizeof
(
Y
),
"Do not support cast between different size of type"
);
using
remove_pointer_t
=
typename
remove_pointer
<
T
>::
type
;
return
__builtin_bit_cast
(
Y
,
x
);
template
<
typename
T
>
}
inline
constexpr
bool
is_pointer_v
=
is_pointer
<
T
>::
value
;
}
// namespace ck
template
<
typename
Y
,
typename
X
,
typename
enable_if
<
sizeof
(
X
)
==
sizeof
(
Y
),
bool
>
::
type
=
false
>
__host__
__device__
constexpr
Y
bit_cast
(
const
X
&
x
)
{
static_assert
(
__has_builtin
(
__builtin_bit_cast
),
""
);
static_assert
(
sizeof
(
X
)
==
sizeof
(
Y
),
"Do not support cast between different size of type"
);
return
__builtin_bit_cast
(
Y
,
x
);
}
}
// namespace ck
\ No newline at end of file
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