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
42199670
"...composable_kernel_rocm.git" did not exist on "850144a0d3237ea1f0e0f64422358e8b49cc8810"
Commit
42199670
authored
Sep 12, 2024
by
Jun Liu
Browse files
Legacy support: customized filesystem
parent
e07f1108
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
190 additions
and
11 deletions
+190
-11
codegen/test/rtc/include/rtc/compile_kernel.hpp
codegen/test/rtc/include/rtc/compile_kernel.hpp
+2
-2
codegen/test/rtc/include/rtc/tmp_dir.hpp
codegen/test/rtc/include/rtc/tmp_dir.hpp
+2
-2
codegen/test/rtc/src/compile_kernel.cpp
codegen/test/rtc/src/compile_kernel.cpp
+4
-4
codegen/test/rtc/src/tmp_dir.cpp
codegen/test/rtc/src/tmp_dir.cpp
+3
-3
include/ck/filesystem.hpp
include/ck/filesystem.hpp
+179
-0
No files found.
codegen/test/rtc/include/rtc/compile_kernel.hpp
View file @
42199670
...
...
@@ -2,14 +2,14 @@
#define GUARD_HOST_TEST_RTC_INCLUDE_RTC_COMPILE_KERNEL
#include <rtc/kernel.hpp>
#include <filesystem>
#include <
ck/
filesystem
.hpp
>
#include <string>
namespace
rtc
{
struct
src_file
{
s
td
::
filesystem
::
path
path
;
f
s
::
path
path
;
std
::
string_view
content
;
};
...
...
codegen/test/rtc/include/rtc/tmp_dir.hpp
View file @
42199670
...
...
@@ -2,13 +2,13 @@
#define GUARD_HOST_TEST_RTC_INCLUDE_RTC_TMP_DIR
#include <string>
#include <filesystem>
#include <
ck/
filesystem
.hpp
>
namespace
rtc
{
struct
tmp_dir
{
s
td
::
filesystem
::
path
path
;
f
s
::
path
path
;
tmp_dir
(
const
std
::
string
&
prefix
=
""
);
void
execute
(
const
std
::
string
&
cmd
)
const
;
...
...
codegen/test/rtc/src/compile_kernel.cpp
View file @
42199670
...
...
@@ -70,9 +70,9 @@ kernel compile_kernel(const std::vector<src_file>& srcs, compile_options options
for
(
const
auto
&
src
:
srcs
)
{
s
td
::
filesystem
::
path
full_path
=
td
.
path
/
src
.
path
;
s
td
::
filesystem
::
path
parent_path
=
full_path
.
parent_path
();
s
td
::
filesystem
::
create_directories
(
parent_path
);
f
s
::
path
full_path
=
td
.
path
/
src
.
path
;
f
s
::
path
parent_path
=
full_path
.
parent_path
();
f
s
::
create_directories
(
parent_path
);
write_string
(
full_path
.
string
(),
src
.
content
);
if
(
src
.
path
.
extension
().
string
()
==
".cpp"
)
{
...
...
@@ -86,7 +86,7 @@ kernel compile_kernel(const std::vector<src_file>& srcs, compile_options options
td
.
execute
(
compiler
()
+
options
.
flags
);
auto
out_path
=
td
.
path
/
out
;
if
(
not
s
td
::
filesystem
::
exists
(
out_path
))
if
(
not
f
s
::
exists
(
out_path
))
throw
std
::
runtime_error
(
"Output file missing: "
+
out
);
auto
obj
=
read_buffer
(
out_path
.
string
());
...
...
codegen/test/rtc/src/tmp_dir.cpp
View file @
42199670
...
...
@@ -31,10 +31,10 @@ std::string unique_string(const std::string& prefix)
}
tmp_dir
::
tmp_dir
(
const
std
::
string
&
prefix
)
:
path
(
s
td
::
filesystem
::
temp_directory_path
()
/
:
path
(
f
s
::
temp_directory_path
()
/
unique_string
(
prefix
.
empty
()
?
"ck-rtc"
:
"ck-rtc-"
+
prefix
))
{
s
td
::
filesystem
::
create_directories
(
this
->
path
);
f
s
::
create_directories
(
this
->
path
);
}
void
tmp_dir
::
execute
(
const
std
::
string
&
cmd
)
const
...
...
@@ -43,6 +43,6 @@ void tmp_dir::execute(const std::string& cmd) const
std
::
system
(
s
.
c_str
());
}
tmp_dir
::~
tmp_dir
()
{
s
td
::
filesystem
::
remove_all
(
this
->
path
);
}
tmp_dir
::~
tmp_dir
()
{
f
s
::
remove_all
(
this
->
path
);
}
}
// namespace rtc
include/ck/filesystem.hpp
0 → 100644
View file @
42199670
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2024, Advanced Micro Devices, Inc. All rights reserved.
#ifndef GUARD_CK_FILESYSTEM_HPP_
#define GUARD_CK_FILESYSTEM_HPP_
#include <string>
#include <string_view>
// clang-format off
#if defined(CPPCHECK)
#define CK_HAS_FILESYSTEM 1
#define CK_HAS_FILESYSTEM_TS 1
#elif defined(_WIN32)
#if _MSC_VER >= 1920
#define CK_HAS_FILESYSTEM 1
#define CK_HAS_FILESYSTEM_TS 0
#elif _MSC_VER >= 1900
#define CK_HAS_FILESYSTEM 0
#define CK_HAS_FILESYSTEM_TS 1
#else
#define CK_HAS_FILESYSTEM 0
#define CK_HAS_FILESYSTEM_TS 0
#endif
#elif defined(__has_include)
#if __has_include(<filesystem>) && __cplusplus >= 201703L
#define CK_HAS_FILESYSTEM 1
#else
#define CK_HAS_FILESYSTEM 0
#endif
#if __has_include(<experimental/filesystem>) && __cplusplus >= 201103L
#define CK_HAS_FILESYSTEM_TS 1
#else
#define CK_HAS_FILESYSTEM_TS 0
#endif
#else
#define CK_HAS_FILESYSTEM 0
#define CK_HAS_FILESYSTEM_TS 0
#endif
// clang-format on
#if CK_WORKAROUND_USE_BOOST_FILESYSTEM
#undef CK_HAS_FILESYSTEM
#undef CK_HAS_FILESYSTEM_TS
#define CK_HAS_FILESYSTEM 0
#define CK_HAS_FILESYSTEM_TS 0
#endif
#if CK_HAS_FILESYSTEM
#include <filesystem>
#elif CK_HAS_FILESYSTEM_TS
#include <experimental/filesystem>
#elif CK_WORKAROUND_USE_BOOST_FILESYSTEM
/// Explicit inclusion of <boost/container_hash/hash.hpp> is a workaround for the Boost 1.83 issue.
///
/// Boost doc is saying:
/// When writing template classes, you might not want to include the main hash.hpp header as it's
/// quite an expensive include that brings in a lot of other headers, so instead you can include
/// the <boost/container_hash/hash_fwd.hpp> header which forward declares boost::hash,
/// boost::hash_combine, boost::hash_range, and boost::hash_unordered_range. You'll need to
/// include the main header before instantiating boost::hash.
///
/// \ref https://www.boost.org/doc/libs/1_83_0/libs/container_hash/doc/html/hash.html#combine
///
/// It seems like boost::filesystem uses boost::hash_range but misses to include hash.hpp, so we
/// have to include it explicitly. Otherwise an error like this happens at runtime (!):
///
/// \code
/// ...symbol lookup error: .../libCK.so.1: undefined symbol:
/// _ZN5boost10hash_rangeIN9__gnu_cxx17__normal_iteratorIPKcNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEEEmT_SC_
/// \endcode
#include <boost/container_hash/hash.hpp>
#define BOOST_FILESYSTEM_NO_DEPRECATED 1
#include <boost/filesystem.hpp>
#else
#error "No filesystem include available"
#endif
namespace
CK
{
#if CK_HAS_FILESYSTEM
namespace
fs
=
::
std
::
filesystem
;
#elif CK_HAS_FILESYSTEM_TS
namespace
fs
=
::
std
::
experimental
::
filesystem
;
#elif CK_WORKAROUND_USE_BOOST_FILESYSTEM
namespace
fs
=
::
boost
::
filesystem
;
#endif
}
// namespace CK
inline
std
::
string
operator
+
(
const
std
::
string_view
s
,
const
CK
::
fs
::
path
&
path
)
{
#if CK_WORKAROUND_USE_BOOST_FILESYSTEM
return
std
::
string
(
path
.
native
()).
insert
(
0
,
s
);
#else
return
path
.
string
().
insert
(
0
,
s
);
#endif
}
inline
std
::
string
operator
+
(
const
CK
::
fs
::
path
&
path
,
const
std
::
string_view
s
)
{
#if CK_WORKAROUND_USE_BOOST_FILESYSTEM
return
std
::
string
(
path
.
native
()).
append
(
s
);
#else
return
path
.
string
().
append
(
s
);
#endif
}
// Hack to minimize changes for boost fs.
#if CK_WORKAROUND_USE_BOOST_FILESYSTEM
#define FS_ENUM_PERMS_ALL fs::perms::all_all
#else
#define FS_ENUM_PERMS_ALL fs::perms::all
#endif
#if CK_HAS_FILESYSTEM_TS
#ifdef __linux__
#include <linux/limits.h>
namespace
CK
{
inline
fs
::
path
weakly_canonical
(
const
fs
::
path
&
path
)
{
std
::
string
result
(
PATH_MAX
,
'\0'
);
std
::
string
p
{
path
.
is_relative
()
?
(
fs
::
current_path
()
/
path
).
string
()
:
path
.
string
()};
char
*
retval
=
realpath
(
p
.
c_str
(),
&
result
[
0
]);
return
(
retval
==
nullptr
)
?
path
:
fs
::
path
{
result
};
}
}
// namespace CK
#else
#error "Not implmeneted!"
#endif
#else
namespace
CK
{
inline
fs
::
path
weakly_canonical
(
const
fs
::
path
&
path
)
{
return
fs
::
weakly_canonical
(
path
);
}
}
// namespace CK
#endif
namespace
CK
{
#ifdef _WIN32
constexpr
std
::
string_view
executable_postfix
{
".exe"
};
constexpr
std
::
string_view
library_prefix
{
""
};
constexpr
std
::
string_view
dynamic_library_postfix
{
".dll"
};
constexpr
std
::
string_view
static_library_postfix
{
".lib"
};
constexpr
std
::
string_view
object_file_postfix
{
".obj"
};
#else
constexpr
std
::
string_view
executable_postfix
{
""
};
constexpr
std
::
string_view
library_prefix
{
"lib"
};
constexpr
std
::
string_view
dynamic_library_postfix
{
".so"
};
constexpr
std
::
string_view
static_library_postfix
{
".a"
};
constexpr
std
::
string_view
object_file_postfix
{
".o"
};
#endif
inline
fs
::
path
make_executable_name
(
const
fs
::
path
&
path
)
{
return
path
.
parent_path
()
/
(
path
.
filename
()
+
executable_postfix
);
}
inline
fs
::
path
make_dynamic_library_name
(
const
fs
::
path
&
path
)
{
return
path
.
parent_path
()
/
(
library_prefix
+
path
.
filename
()
+
dynamic_library_postfix
);
}
inline
fs
::
path
make_object_file_name
(
const
fs
::
path
&
path
)
{
return
path
.
parent_path
()
/
(
path
.
filename
()
+
object_file_postfix
);
}
inline
fs
::
path
make_static_library_name
(
const
fs
::
path
&
path
)
{
return
path
.
parent_path
()
/
(
library_prefix
+
path
.
filename
()
+
static_library_postfix
);
}
struct
FsPathHash
{
std
::
size_t
operator
()(
const
fs
::
path
&
path
)
const
{
return
fs
::
hash_value
(
path
);
}
};
}
// namespace CK
#endif // GUARD_CK_FILESYSTEM_HPP_
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