-
Notifications
You must be signed in to change notification settings - Fork 769
[SYCL] Emit program build logs for warning levels >= 2 #5319
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
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -438,6 +438,17 @@ std::pair<RT::PiProgram, bool> ProgramManager::getOrCreatePIProgram( | |
return {NativePrg, BinProg.size()}; | ||
} | ||
|
||
/// Emits information about built programs if the appropriate contitions are | ||
/// met, namely when SYCL_RT_WARNING_LEVEL is greater than or equal to 2. | ||
static void emitBuiltProgramInfo(const pi_program &Prog, | ||
const ContextImplPtr &Context) { | ||
if (SYCLConfig<SYCL_RT_WARNING_LEVEL>::get() >= 2) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: |
||
std::string ProgramBuildLog = | ||
ProgramManager::getProgramBuildLog(Prog, Context); | ||
std::clog << ProgramBuildLog << std::endl; | ||
} | ||
} | ||
|
||
RT::PiProgram ProgramManager::getBuiltPIProgram( | ||
OSModuleHandle M, const ContextImplPtr &ContextImpl, | ||
const DeviceImplPtr &DeviceImpl, const std::string &KernelName, | ||
|
@@ -511,6 +522,8 @@ RT::PiProgram ProgramManager::getBuiltPIProgram( | |
getRawSyclObjImpl(Device)->getHandleRef(), | ||
ContextImpl->getCachedLibPrograms(), DeviceLibReqMask); | ||
|
||
emitBuiltProgramInfo(BuiltProgram.get(), ContextImpl); | ||
|
||
{ | ||
std::lock_guard<std::mutex> Lock(MNativeProgramsMutex); | ||
NativePrograms[BuiltProgram.get()] = &Img; | ||
|
@@ -1785,6 +1798,8 @@ device_image_plain ProgramManager::build(const device_image_plain &DeviceImage, | |
getRawSyclObjImpl(Devs[0])->getHandleRef(), | ||
ContextImpl->getCachedLibPrograms(), DeviceLibReqMask); | ||
|
||
emitBuiltProgramInfo(BuiltProgram.get(), ContextImpl); | ||
|
||
{ | ||
std::lock_guard<std::mutex> Lock(MNativeProgramsMutex); | ||
NativePrograms[BuiltProgram.get()] = &Img; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
//==----------------- BuildLog.cpp --- Build log tests ---------------------==// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "gtest/internal/gtest-internal.h" | ||
#define SYCL2020_DISABLE_DEPRECATION_WARNINGS | ||
|
||
#include <CL/sycl.hpp> | ||
#include <detail/config.hpp> | ||
#include <detail/context_impl.hpp> | ||
#include <detail/program_manager/program_manager.hpp> | ||
#include <helpers/CommonRedefinitions.hpp> | ||
#include <helpers/PiImage.hpp> | ||
#include <helpers/PiMock.hpp> | ||
#include <helpers/ScopedEnvVar.hpp> | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include <cstring> | ||
#include <stdlib.h> | ||
|
||
#include <helpers/TestKernel.hpp> | ||
|
||
// Same as defined in config.def | ||
static constexpr auto WarningLevelEnvVar = "SYCL_RT_WARNING_LEVEL"; | ||
|
||
static bool LogRequested = false; | ||
|
||
static pi_result redefinedProgramGetBuildInfo( | ||
pi_program program, pi_device device, cl_program_build_info param_name, | ||
size_t param_value_size, void *param_value, size_t *param_value_size_ret) { | ||
|
||
if (param_value_size_ret) { | ||
*param_value_size_ret = 1; | ||
} | ||
if (param_value) { | ||
*static_cast<char *>(param_value) = '1'; | ||
} | ||
|
||
if (param_name == PI_PROGRAM_BUILD_INFO_LOG) { | ||
LogRequested = true; | ||
} | ||
|
||
return PI_SUCCESS; | ||
} | ||
|
||
static pi_result redefinedDeviceGetInfo(pi_device device, | ||
pi_device_info param_name, | ||
size_t param_value_size, | ||
void *param_value, | ||
size_t *param_value_size_ret) { | ||
if (param_name == PI_DEVICE_INFO_NAME) { | ||
const std::string name = "Test Device"; | ||
if (param_value_size_ret) { | ||
*param_value_size_ret = name.size(); | ||
} | ||
if (param_value) { | ||
auto *val = static_cast<char *>(param_value); | ||
strcpy(val, name.data()); | ||
} | ||
} | ||
if (param_name == PI_DEVICE_INFO_COMPILER_AVAILABLE) { | ||
if (param_value_size_ret) { | ||
*param_value_size_ret = sizeof(cl_bool); | ||
} | ||
if (param_value) { | ||
auto *val = static_cast<cl_bool *>(param_value); | ||
*val = 1; | ||
} | ||
} | ||
return PI_SUCCESS; | ||
} | ||
|
||
static void setupCommonTestAPIs(sycl::unittest::PiMock &Mock) { | ||
using namespace sycl::detail; | ||
Mock.redefine<PiApiKind::piProgramGetBuildInfo>(redefinedProgramGetBuildInfo); | ||
Mock.redefine<PiApiKind::piDeviceGetInfo>(redefinedDeviceGetInfo); | ||
} | ||
|
||
TEST(BuildLog, OutputNothingOnLevel1) { | ||
using namespace sycl::detail; | ||
using namespace sycl::unittest; | ||
ScopedEnvVar var(WarningLevelEnvVar, "1", | ||
SYCLConfig<SYCL_RT_WARNING_LEVEL>::reset); | ||
|
||
sycl::platform Plt{sycl::default_selector()}; | ||
// TODO make sure unsupported platform is never selected | ||
if (Plt.is_host() || Plt.get_backend() == sycl::backend::ext_oneapi_cuda || | ||
Plt.get_backend() == sycl::backend::ext_oneapi_hip) { | ||
GTEST_SKIP_("Test is not supported on this platform"); | ||
} | ||
|
||
sycl::unittest::PiMock Mock{Plt}; | ||
setupDefaultMockAPIs(Mock); | ||
setupCommonTestAPIs(Mock); | ||
|
||
const sycl::device Dev = Plt.get_devices()[0]; | ||
|
||
sycl::queue Queue{Dev}; | ||
|
||
sycl::context Ctx = Queue.get_context(); | ||
auto ContextImpl = getSyclObjImpl(Ctx); | ||
// Make sure no kernels are cached | ||
ContextImpl->getKernelProgramCache().reset(); | ||
|
||
LogRequested = false; | ||
sycl::kernel_bundle KernelBundle = | ||
sycl::get_kernel_bundle<sycl::bundle_state::input>(Ctx, {Dev}); | ||
(void)sycl::build(KernelBundle); | ||
|
||
EXPECT_EQ(LogRequested, false); | ||
} | ||
|
||
TEST(BuildLog, OutputLogOnLevel2) { | ||
using namespace sycl::detail; | ||
using namespace sycl::unittest; | ||
ScopedEnvVar var(WarningLevelEnvVar, "2", | ||
SYCLConfig<SYCL_RT_WARNING_LEVEL>::reset); | ||
|
||
sycl::platform Plt{sycl::default_selector()}; | ||
// TODO make sure unsupported platform is never selected | ||
if (Plt.is_host() || Plt.get_backend() == sycl::backend::ext_oneapi_cuda || | ||
Plt.get_backend() == sycl::backend::ext_oneapi_hip) { | ||
GTEST_SKIP_("Test is not supported on this platform"); | ||
} | ||
|
||
sycl::unittest::PiMock Mock{Plt}; | ||
setupDefaultMockAPIs(Mock); | ||
setupCommonTestAPIs(Mock); | ||
|
||
const sycl::device Dev = Plt.get_devices()[0]; | ||
|
||
sycl::queue Queue{Dev}; | ||
|
||
const sycl::context Ctx = Queue.get_context(); | ||
auto ContextImpl = getSyclObjImpl(Ctx); | ||
// Make sure no kernels are cached | ||
ContextImpl->getKernelProgramCache().reset(); | ||
|
||
LogRequested = false; | ||
sycl::kernel_bundle KernelBundle = | ||
sycl::get_kernel_bundle<sycl::bundle_state::input>(Ctx, {Dev}); | ||
(void)sycl::build(KernelBundle); | ||
|
||
EXPECT_EQ(LogRequested, true); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.