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
12142253
Commit
12142253
authored
Feb 13, 2025
by
Aleksander Dudek
Browse files
[CK_TILE] Add EnvLogging - refactor IsSupported error messages
parent
0e5e29c4
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
197 additions
and
0 deletions
+197
-0
include/ck_tile/core.hpp
include/ck_tile/core.hpp
+1
-0
include/ck_tile/core/config.hpp
include/ck_tile/core/config.hpp
+6
-0
include/ck_tile/core/utility/env.hpp
include/ck_tile/core/utility/env.hpp
+185
-0
include/ck_tile/ops/gemm/kernel/gemm_kernel.hpp
include/ck_tile/ops/gemm/kernel/gemm_kernel.hpp
+5
-0
No files found.
include/ck_tile/core.hpp
View file @
12142253
...
@@ -58,6 +58,7 @@
...
@@ -58,6 +58,7 @@
#include "ck_tile/core/tensor/transpose_tile.hpp"
#include "ck_tile/core/tensor/transpose_tile.hpp"
#include "ck_tile/core/tensor/update_tile.hpp"
#include "ck_tile/core/tensor/update_tile.hpp"
#include "ck_tile/core/utility/bit_cast.hpp"
#include "ck_tile/core/utility/bit_cast.hpp"
#include "ck_tile/core/utility/env.hpp"
#include "ck_tile/core/utility/functional.hpp"
#include "ck_tile/core/utility/functional.hpp"
#include "ck_tile/core/utility/functional_with_tuple.hpp"
#include "ck_tile/core/utility/functional_with_tuple.hpp"
#include "ck_tile/core/utility/ignore.hpp"
#include "ck_tile/core/utility/ignore.hpp"
...
...
include/ck_tile/core/config.hpp
View file @
12142253
...
@@ -29,6 +29,12 @@
...
@@ -29,6 +29,12 @@
#include "hip/hip_fp16.h"
#include "hip/hip_fp16.h"
#endif
#endif
#include "ck_tile/core/utility/env.hpp"
// environment variable to enable logging:
// export CK_TILE_LOGGING=ON or CK_TILE_LOGGING=1 or CK_TILE_LOGGING=ENABLED
CK_TILE_DECLARE_ENV_VAR_BOOL
(
CK_TILE_LOGGING
)
#ifdef __HIPCC__
#ifdef __HIPCC__
#define CK_TILE_HOST inline __host__
#define CK_TILE_HOST inline __host__
#define CK_TILE_DEVICE inline __device__
#define CK_TILE_DEVICE inline __device__
...
...
include/ck_tile/core/utility/env.hpp
0 → 100644
View file @
12142253
// SPDX-License-Identifier: MIT
// Copyright (c) 2025, Advanced Micro Devices, Inc. All rights reserved.
#pragma once
#include <iostream>
#include <string>
namespace
ck_tile
{
namespace
internal
{
template
<
typename
T
>
struct
ParseEnvVal
{
};
template
<
>
struct
ParseEnvVal
<
bool
>
{
static
bool
parse_env_var_value
(
const
char
*
vp
)
{
std
::
string
value_env_str
{
vp
};
for
(
auto
&
c
:
value_env_str
)
{
if
(
std
::
isalpha
(
c
)
!=
0
)
{
c
=
std
::
tolower
(
static_cast
<
unsigned
char
>
(
c
));
}
}
if
(
value_env_str
==
"disable"
||
value_env_str
==
"disabled"
||
value_env_str
==
"0"
||
value_env_str
==
"no"
||
value_env_str
==
"off"
||
value_env_str
==
"false"
)
{
return
false
;
}
else
if
(
value_env_str
==
"enable"
||
value_env_str
==
"enabled"
||
value_env_str
==
"1"
||
value_env_str
==
"yes"
||
value_env_str
==
"on"
||
value_env_str
==
"true"
)
{
return
true
;
}
else
{
throw
std
::
runtime_error
(
"Invalid value for env variable"
);
}
return
false
;
// shouldn't reach here
}
};
// Supports hexadecimals (with leading "0x"), octals (if prefix is "0") and decimals (default).
// Returns 0 if environment variable is in wrong format (strtoull fails to parse the string).
template
<
>
struct
ParseEnvVal
<
uint64_t
>
{
static
uint64_t
parse_env_var_value
(
const
char
*
vp
)
{
return
std
::
strtoull
(
vp
,
nullptr
,
0
);
}
};
template
<
>
struct
ParseEnvVal
<
std
::
string
>
{
static
std
::
string
parse_env_var_value
(
const
char
*
vp
)
{
return
std
::
string
{
vp
};
}
};
template
<
typename
T
>
struct
EnvVar
{
private:
T
value
{};
bool
is_unset
=
true
;
public:
const
T
&
GetValue
()
const
{
return
value
;
}
bool
IsUnset
()
const
{
return
is_unset
;
}
void
Unset
()
{
is_unset
=
true
;
}
void
UpdateValue
(
const
T
&
val
)
{
is_unset
=
false
;
value
=
val
;
}
explicit
EnvVar
(
const
char
*
const
name
,
const
T
&
def_val
)
{
// NOLINTNEXTLINE (concurrency-mt-unsafe)
const
char
*
vp
=
std
::
getenv
(
name
);
if
(
vp
!=
nullptr
)
// a value was provided
{
is_unset
=
false
;
value
=
ParseEnvVal
<
T
>::
parse_env_var_value
(
vp
);
}
else
// no value provided, use default value
{
value
=
def_val
;
}
}
};
}
// end namespace internal
// static inside function hides the variable and provides
// thread-safety/locking
// Used in global namespace
#define CK_TILE_DECLARE_ENV_VAR(name, type, default_val) \
namespace ck_tile::env { \
struct name \
{ \
static_assert(std::is_same_v<name, ::ck_tile::env::name>, \
"CK_TILE_DECLARE_ENV* must be used in the global namespace"); \
using value_type = type; \
static ck_tile::internal::EnvVar<type>& Ref() \
{ \
static ck_tile::internal::EnvVar<type> var{#name, default_val}; \
return var; \
} \
}; \
}
#define CK_TILE_DECLARE_ENV_VAR_BOOL(name) CK_TILE_DECLARE_ENV_VAR(name, bool, false)
#define CK_TILE_DECLARE_ENV_VAR_UINT64(name) CK_TILE_DECLARE_ENV_VAR(name, uint64_t, 0)
#define CK_TILE_DECLARE_ENV_VAR_STR(name) CK_TILE_DECLARE_ENV_VAR(name, std::string, "")
#define CK_TILE_ENV(name) \
ck_tile::env::name {}
template
<
class
EnvVar
>
inline
const
std
::
string
&
EnvGetString
(
EnvVar
)
{
static_assert
(
std
::
is_same_v
<
typename
EnvVar
::
value_type
,
std
::
string
>
);
return
EnvVar
::
Ref
().
GetValue
();
}
template
<
class
EnvVar
>
inline
bool
EnvIsEnabled
(
EnvVar
)
{
static_assert
(
std
::
is_same_v
<
typename
EnvVar
::
value_type
,
bool
>
);
return
!
EnvVar
::
Ref
().
IsUnset
()
&&
EnvVar
::
Ref
().
GetValue
();
}
template
<
class
EnvVar
>
inline
bool
EnvIsDisabled
(
EnvVar
)
{
static_assert
(
std
::
is_same_v
<
typename
EnvVar
::
value_type
,
bool
>
);
return
!
EnvVar
::
Ref
().
IsUnset
()
&&
!
EnvVar
::
Ref
().
GetValue
();
}
template
<
class
EnvVar
>
inline
uint64_t
EnvValue
(
EnvVar
)
{
static_assert
(
std
::
is_same_v
<
typename
EnvVar
::
value_type
,
uint64_t
>
);
return
EnvVar
::
Ref
().
GetValue
();
}
template
<
class
EnvVar
>
inline
bool
EnvIsUnset
(
EnvVar
)
{
return
EnvVar
::
Ref
().
IsUnset
();
}
template
<
class
EnvVar
>
void
EnvUnset
(
EnvVar
)
{
EnvVar
::
Ref
().
Unset
();
}
/// updates the cached value of an environment variable
template
<
typename
EnvVar
,
typename
ValueType
>
void
UpdateEnvVar
(
EnvVar
,
const
ValueType
&
val
)
{
static_assert
(
std
::
is_same_v
<
typename
EnvVar
::
value_type
,
ValueType
>
);
EnvVar
::
Ref
().
UpdateValue
(
val
);
}
template
<
typename
EnvVar
>
void
UpdateEnvVar
(
EnvVar
,
const
std
::
string_view
&
val
)
{
EnvVar
::
Ref
().
UpdateValue
(
ck_tile
::
internal
::
ParseEnvVal
<
typename
EnvVar
::
value_type
>::
parse_env_var_value
(
val
.
data
()));
}
}
// namespace ck_tile
include/ck_tile/ops/gemm/kernel/gemm_kernel.hpp
View file @
12142253
...
@@ -167,6 +167,11 @@ struct GemmKernel
...
@@ -167,6 +167,11 @@ struct GemmKernel
CK_TILE_HOST
static
bool
IsSupportedArgument
(
const
GemmKernelArgs
&
kargs
)
CK_TILE_HOST
static
bool
IsSupportedArgument
(
const
GemmKernelArgs
&
kargs
)
{
{
if
(
ck_tile
::
EnvIsEnabled
(
CK_TILE_ENV
(
CK_TILE_LOGGING
)))
{
std
::
cout
<<
"Testing CK_TILE_ENV logging... "
<<
__FILE__
<<
":"
<<
__LINE__
<<
", in function: "
<<
__func__
<<
std
::
endl
;
}
if
constexpr
(
EpiloguePipeline
::
template
GetVectorSizeC
<
CDataType
>()
%
2
!=
0
&&
if
constexpr
(
EpiloguePipeline
::
template
GetVectorSizeC
<
CDataType
>()
%
2
!=
0
&&
is_any_of
<
CDataType
,
fp16_t
,
bf16_t
>::
value
)
is_any_of
<
CDataType
,
fp16_t
,
bf16_t
>::
value
)
{
{
...
...
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