Skip to content

Commit 80cf11c

Browse files
authored
[SYCL] Fix 'move instead of copy' Coverity hits (#17619)
Avoid copying by: - Making the `Queue` parameter of `completeSpecConstMaterialization` passed by a const reference. Also changes `materializeSpecConstants`, `getTargetInfo` and `getTargetFormat` to accomodate this change. - Makes returned `DefaultValue` string non const so that the move ctor is called automatically in two `get` functions. - Remove dead if statement that copied value for a function call.
1 parent 8e7ec0f commit 80cf11c

File tree

5 files changed

+11
-14
lines changed

5 files changed

+11
-14
lines changed

sycl/source/detail/config.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ template <> class SYCLConfig<SYCL_JIT_AMDGCN_PTX_TARGET_CPU> {
647647

648648
public:
649649
static std::string get() {
650-
const std::string DefaultValue{""};
650+
std::string DefaultValue{""};
651651

652652
const char *ValStr = getCachedValue();
653653

@@ -675,7 +675,7 @@ template <> class SYCLConfig<SYCL_JIT_AMDGCN_PTX_TARGET_FEATURES> {
675675

676676
public:
677677
static std::string get() {
678-
const std::string DefaultValue{""};
678+
std::string DefaultValue{""};
679679

680680
const char *ValStr = getCachedValue();
681681

sycl/source/detail/jit_compiler.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ translateBinaryImageFormat(ur::DeviceBinaryType Type) {
137137
}
138138
}
139139

140-
::jit_compiler::BinaryFormat getTargetFormat(QueueImplPtr &Queue) {
140+
::jit_compiler::BinaryFormat getTargetFormat(const QueueImplPtr &Queue) {
141141
auto Backend = Queue->getDeviceImplPtr()->getBackend();
142142
switch (Backend) {
143143
case backend::ext_oneapi_level_zero:
@@ -154,7 +154,7 @@ ::jit_compiler::BinaryFormat getTargetFormat(QueueImplPtr &Queue) {
154154
}
155155
}
156156

157-
::jit_compiler::TargetInfo getTargetInfo(QueueImplPtr &Queue) {
157+
::jit_compiler::TargetInfo getTargetInfo(const QueueImplPtr &Queue) {
158158
::jit_compiler::BinaryFormat Format = getTargetFormat(Queue);
159159
return ::jit_compiler::TargetInfo::get(
160160
Format, static_cast<::jit_compiler::DeviceArchitecture>(
@@ -659,7 +659,7 @@ updatePromotedArgs(const ::jit_compiler::SYCLKernelInfo &FusedKernelInfo,
659659
}
660660

661661
ur_kernel_handle_t jit_compiler::materializeSpecConstants(
662-
QueueImplPtr Queue, const RTDeviceBinaryImage *BinImage,
662+
const QueueImplPtr &Queue, const RTDeviceBinaryImage *BinImage,
663663
const std::string &KernelName,
664664
const std::vector<unsigned char> &SpecConstBlob) {
665665
#ifndef _WIN32
@@ -1042,16 +1042,13 @@ jit_compiler::fuseKernels(QueueImplPtr Queue,
10421042
FusedOrCachedKernelName);
10431043

10441044
std::shared_ptr<detail::kernel_bundle_impl> KernelBundleImplPtr;
1045-
if (TargetFormat == ::jit_compiler::BinaryFormat::SPIRV) {
1046-
detail::getSyclObjImpl(get_kernel_bundle<bundle_state::executable>(
1047-
Queue->get_context(), {Queue->get_device()}, {FusedKernelId}));
1048-
}
10491045

10501046
std::unique_ptr<detail::CG> FusedCG;
10511047
FusedCG.reset(new detail::CGExecKernel(
10521048
NDRDesc, nullptr, nullptr, std::move(KernelBundleImplPtr),
1053-
std::move(CGData), std::move(FusedArgs), FusedOrCachedKernelName, {}, {},
1054-
CGType::Kernel, KernelCacheConfig, false /* KernelIsCooperative */,
1049+
std::move(CGData), std::move(FusedArgs),
1050+
std::move(FusedOrCachedKernelName), {}, {}, CGType::Kernel,
1051+
KernelCacheConfig, false /* KernelIsCooperative */,
10551052
false /* KernelUsesClusterLaunch*/, 0 /* KernelWorkGroupMemorySize */));
10561053
return FusedCG;
10571054
}

sycl/source/detail/jit_compiler.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class jit_compiler {
4444
fuseKernels(QueueImplPtr Queue, std::vector<ExecCGCommand *> &InputKernels,
4545
const property_list &);
4646
ur_kernel_handle_t
47-
materializeSpecConstants(QueueImplPtr Queue,
47+
materializeSpecConstants(const QueueImplPtr &Queue,
4848
const RTDeviceBinaryImage *BinImage,
4949
const std::string &KernelName,
5050
const std::vector<unsigned char> &SpecConstBlob);

sycl/source/detail/scheduler/scheduler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ void Scheduler::cleanupAuxiliaryResources(BlockingT Blocking) {
587587
}
588588

589589
ur_kernel_handle_t Scheduler::completeSpecConstMaterialization(
590-
[[maybe_unused]] QueueImplPtr Queue,
590+
[[maybe_unused]] const QueueImplPtr &Queue,
591591
[[maybe_unused]] const RTDeviceBinaryImage *BinImage,
592592
[[maybe_unused]] const std::string &KernelName,
593593
[[maybe_unused]] std::vector<unsigned char> &SpecConstBlob) {

sycl/source/detail/scheduler/scheduler.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ class Scheduler {
453453
void deferMemObjRelease(const std::shared_ptr<detail::SYCLMemObjI> &MemObj);
454454

455455
ur_kernel_handle_t completeSpecConstMaterialization(
456-
QueueImplPtr Queue, const RTDeviceBinaryImage *BinImage,
456+
const QueueImplPtr &Queue, const RTDeviceBinaryImage *BinImage,
457457
const std::string &KernelName, std::vector<unsigned char> &SpecConstBlob);
458458

459459
void releaseResources(BlockingT Blocking = BlockingT::BLOCKING);

0 commit comments

Comments
 (0)