Skip to content

Commit

Permalink
Merge pull request #159 from xiaomx32/zitai/next-dev
Browse files Browse the repository at this point in the history
use tools under the luisa namespace as much as possible
  • Loading branch information
shiinamiyuki authored Dec 8, 2024
2 parents 6b4bae7 + fd37ea0 commit 8ac5003
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 80 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/code-format-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: C++ Code Check
on: [ push, pull_request ]
jobs:
formatting-check:
name: Check C++ Code Formatting
runs-on: ubuntu-24.04
strategy:
matrix:
path:
- check: 'include'
- check: 'src'
exclude: 'ext'
steps:
- uses: actions/checkout@v4
- name: Run clang-format style check for C/C++/Protobuf programs.
uses: jidicula/[email protected]
with:
clang-format-version: '18'
check-path: ${{ matrix.path['check'] }}
exclude-regex: ${{ matrix.path['exclude'] }}
fallback-style: 'LLVM'
26 changes: 14 additions & 12 deletions include/luisa/core/dynamic_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace luisa {

/**
* @brief Dynamic module loader
*
*
*/
class LC_CORE_API DynamicModule : concepts::Noncopyable {

Expand All @@ -29,7 +29,7 @@ class LC_CORE_API DynamicModule : concepts::Noncopyable {
void dispose() noexcept;
/**
* @brief Return function pointer of given name
*
*
* @tparam F function type
* @param name name of function
* @return pointer to function
Expand All @@ -42,17 +42,17 @@ class LC_CORE_API DynamicModule : concepts::Noncopyable {

/**
* @brief Return address of given name
*
*
* @param name
* @return void*
* @return void*
*/
[[nodiscard]] void *address(std::string_view name) const noexcept {
return dynamic_module_find_symbol(_handle, name);
}

/**
* @brief Invoke function
*
*
* @tparam F function type
* @tparam Args function args
* @param name name of function
Expand All @@ -67,12 +67,12 @@ class LC_CORE_API DynamicModule : concepts::Noncopyable {

/**
* @brief Apply function to each element
*
*
* @tparam F function type
* @tparam Tuple tuple type
* @param name name of function
* @param t tuple to be applied
* @return decltype(auto)
* @return decltype(auto)
*/
template<concepts::function F, typename Tuple>
decltype(auto) apply(std::string_view name, Tuple &&t) const noexcept {
Expand All @@ -81,15 +81,15 @@ class LC_CORE_API DynamicModule : concepts::Noncopyable {

/**
* @brief Add dynamic module search path
*
* @param path
*
* @param path
*/
static void add_search_path(const std::filesystem::path &path) noexcept;

/**
* @brief Remove dynamic module search path
*
* @param path
*
* @param path
*/
static void remove_search_path(const std::filesystem::path &path) noexcept;

Expand All @@ -108,7 +108,9 @@ class LC_CORE_API DynamicModule : concepts::Noncopyable {
* @return The module if successfully loaded, otherwise a nullopt
*/
[[nodiscard]] static DynamicModule load(
const std::filesystem::path &folder, std::string_view name) noexcept;
const luisa::filesystem::path &folder,
std::string_view name
) noexcept;
};

}// namespace luisa
2 changes: 1 addition & 1 deletion include/luisa/runtime/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class LC_RUNTIME_API Context {
luisa::shared_ptr<detail::ContextImpl> _impl;

public:
explicit Context(luisa::shared_ptr<luisa::compute::detail::ContextImpl> impl) noexcept;
explicit Context(luisa::shared_ptr<detail::ContextImpl> impl) noexcept;
// program_path can be first arg from main entry
explicit Context(luisa::string_view program_path) noexcept;
explicit Context(const char *program_path) noexcept
Expand Down
40 changes: 25 additions & 15 deletions src/core/dynamic_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void DynamicModule::dispose() noexcept {
}

[[nodiscard]] static auto &dynamic_module_search_paths() noexcept {
static luisa::vector<std::pair<std::filesystem::path, size_t>> paths;
static luisa::vector<std::pair<luisa::filesystem::path, std::size_t>> paths;
return paths;
}

Expand All @@ -45,21 +45,27 @@ void DynamicModule::dispose() noexcept {
}
#endif

void DynamicModule::add_search_path(const std::filesystem::path &path) noexcept {
std::lock_guard lock{dynamic_module_search_path_mutex()};
auto canonical_path = std::filesystem::canonical(path);
void DynamicModule::add_search_path(const luisa::filesystem::path &path) noexcept {
std::lock_guard lock { dynamic_module_search_path_mutex() };
auto canonical_path = luisa::filesystem::canonical(path);
auto &&paths = dynamic_module_search_paths();
if (auto iter = std::find_if(paths.begin(), paths.end(), [&canonical_path](auto &&p) noexcept {
return p.first == canonical_path;
});
iter != paths.end()) {
if (
auto iter = std::find_if(
paths.begin(),
paths.end(),
[&canonical_path](auto &&p) noexcept {
return p.first == canonical_path;
}
);
iter != paths.end()
) {
iter->second++;
} else {
#ifdef LUISA_PLATFORM_WINDOWS
auto &&cookies = dynamic_module_search_path_cookies();
cookies.emplace_back(AddDllDirectory(canonical_path.c_str()));
#endif
paths.emplace_back(std::move(canonical_path), 0u);
paths.emplace_back(std::move(canonical_path), 0);
}
}

Expand Down Expand Up @@ -106,17 +112,21 @@ DynamicModule DynamicModule::load(std::string_view name) noexcept {
return DynamicModule{nullptr};
}

DynamicModule DynamicModule::load(const std::filesystem::path &folder, std::string_view name) noexcept {
DynamicModule DynamicModule::load(
const luisa::filesystem::path &folder,
luisa::string_view name
) noexcept {
Clock clock;
auto p = folder / dynamic_module_name(name);
if (auto handle = dynamic_module_load(p)) {
LUISA_INFO(
"Loaded dynamic module '{}' in {} ms.",
to_string(p), clock.toc());
return DynamicModule{handle};
to_string(p), clock.toc()
);
return DynamicModule { handle };
}
return DynamicModule{nullptr};
}

}// namespace luisa
return DynamicModule { nullptr };
}

} // namespace luisa end
4 changes: 3 additions & 1 deletion src/core/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,10 @@ void *dynamic_module_load(const luisa::filesystem::path &path) noexcept {
}
LUISA_WARNING_WITH_LOCATION(
"Failed to load dynamic module '{}', reason: {}.",
luisa::to_string(p), dlerror());
luisa::to_string(p), dlerror()
);
}

return nullptr;
}

Expand Down
Loading

0 comments on commit 8ac5003

Please sign in to comment.