Skip to content

Fix mock on Windows, add logging of adapter load/unload #1868

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/adapters/mock/ur_mock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ ur_result_t mock_urPlatformGetInfo(void *pParams) {
}

if (*params.ppropName == UR_PLATFORM_INFO_NAME) {
const char mock_platform_name[] = "UR_PLATFORM_MOCK";
const char mock_platform_name[] = "Mock Platform";
if (*params.ppPropSizeRet) {
**params.ppPropSizeRet = sizeof(mock_platform_name);
}
Expand Down
6 changes: 5 additions & 1 deletion source/common/windows/ur_lib_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@ void LibLoader::freeAdapterLibrary(HMODULE handle) {
logger::error(
"Failed to unload the library with the handle at address {}",
handle);
} else {
logger::info("unloaded adapter 0x{}", handle);
}
}
}

std::unique_ptr<HMODULE, LibLoader::lib_dtor>
LibLoader::loadAdapterLibrary(const char *name) {
return std::unique_ptr<HMODULE, LibLoader::lib_dtor>(
auto handle = std::unique_ptr<HMODULE, LibLoader::lib_dtor>(
LoadLibraryExA(name, nullptr, 0));
logger::info("loaded adapter 0x{} ({})", handle, name);
return handle;
}

void *LibLoader::getFunctionPtr(HMODULE handle, const char *func_name) {
Expand Down
5 changes: 2 additions & 3 deletions source/loader/ur_adapter_registry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,9 @@ class AdapterRegistry {
adaptersLoadPaths.clear();

std::vector<fs::path> loadPaths;
auto adapterNamePathOpt = getAdapterNameAsPath(mockAdapterName);
auto adapterNamePath = fs::path{mockAdapterName};
auto loaderLibPathOpt = getLoaderLibPath();
if (adapterNamePathOpt.has_value() && loaderLibPathOpt.has_value()) {
const auto &adapterNamePath = adapterNamePathOpt.value();
if (loaderLibPathOpt.has_value()) {
const auto &loaderLibPath = loaderLibPathOpt.value();
loadPaths.emplace_back(loaderLibPath / adapterNamePath);
}
Expand Down
2 changes: 1 addition & 1 deletion test/loader/platforms/null_platform.match
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<TEST>[INFO]: urLoaderInit succeeded.
<TEST>[INFO]: urPlatformGet found 1 platforms
<TEST>[INFO]: Found UR_PLATFORM_MOCK
<TEST>[INFO]: Found Mock Platform