Skip to content

Commit ac56e0a

Browse files
Make implicit local arg member const
1 parent 1a663ba commit ac56e0a

File tree

5 files changed

+28
-41
lines changed

5 files changed

+28
-41
lines changed

sycl/source/detail/device_kernel_info.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ namespace sycl {
1212
inline namespace _V1 {
1313
namespace detail {
1414

15-
DeviceKernelInfo::DeviceKernelInfo(const CompileTimeKernelInfoTy &Info)
16-
: CompileTimeKernelInfoTy(Info) {}
15+
DeviceKernelInfo::DeviceKernelInfo(std::string_view Name,
16+
std::optional<int> ImplicitLocalArgPos)
17+
: CompileTimeKernelInfoTy{Name}, MImplicitLocalArgPos{ImplicitLocalArgPos} {
18+
}
1719

1820
template <typename OtherTy>
1921
inline constexpr bool operator==(const CompileTimeKernelInfoTy &LHS,
@@ -42,11 +44,6 @@ void DeviceKernelInfo::setCompileTimeInfoIfNeeded(
4244
assert(isCompileTimeInfoSet());
4345
assert(Info == *this);
4446
}
45-
46-
void DeviceKernelInfo::setImplicitLocalArgPos(int Pos) {
47-
assert(!MImplicitLocalArgPos.has_value() || MImplicitLocalArgPos == Pos);
48-
MImplicitLocalArgPos = Pos;
49-
}
5047
} // namespace detail
5148
} // namespace _V1
5249
} // namespace sycl

sycl/source/detail/device_kernel_info.hpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ struct FastKernelSubcacheT {
8989
// into this structure and get rid of the other KernelName -> * maps.
9090
class DeviceKernelInfo : public CompileTimeKernelInfoTy {
9191
public:
92-
DeviceKernelInfo(const CompileTimeKernelInfoTy &Info);
92+
DeviceKernelInfo(std::string_view Name,
93+
std::optional<int> ImplicitLocalArgPos = {});
9394

94-
void init(std::string_view KernelName);
9595
void setCompileTimeInfoIfNeeded(const CompileTimeKernelInfoTy &Info);
9696

9797
FastKernelSubcacheT &getKernelSubcache() { return MFastKernelSubcache; }
@@ -100,13 +100,11 @@ class DeviceKernelInfo : public CompileTimeKernelInfoTy {
100100
return MImplicitLocalArgPos;
101101
}
102102

103-
void setImplicitLocalArgPos(int Pos);
104-
105103
private:
106104
bool isCompileTimeInfoSet() const { return KernelSize != 0; }
107105

108106
FastKernelSubcacheT MFastKernelSubcache;
109-
std::optional<int> MImplicitLocalArgPos;
107+
const std::optional<int> MImplicitLocalArgPos;
110108
};
111109

112110
} // namespace detail

sycl/source/detail/kernel_impl.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ namespace sycl {
1616
inline namespace _V1 {
1717
namespace detail {
1818

19-
static CompileTimeKernelInfoTy
20-
createCompileTimeKernelInfo(std::string_view KernelName = {}) {
21-
return CompileTimeKernelInfoTy{KernelName};
22-
}
23-
2419
kernel_impl::kernel_impl(Managed<ur_kernel_handle_t> &&Kernel,
2520
context_impl &Context,
2621
kernel_bundle_impl *KernelBundleImpl,
@@ -32,7 +27,7 @@ kernel_impl::kernel_impl(Managed<ur_kernel_handle_t> &&Kernel,
3227
MKernelBundleImpl(KernelBundleImpl ? KernelBundleImpl->shared_from_this()
3328
: nullptr),
3429
MIsInterop(true), MKernelArgMaskPtr{ArgMask}, MOwnsDeviceKernelInfo(true),
35-
MDeviceKernelInfo(createCompileTimeKernelInfo(getName())) {
30+
MDeviceKernelInfo(getName()) {
3631
ur_context_handle_t UrContext = nullptr;
3732
// Using the adapter from the passed ContextImpl
3833
getAdapter().call<UrApiKind::urKernelGetInfo>(
@@ -60,9 +55,8 @@ kernel_impl::kernel_impl(Managed<ur_kernel_handle_t> &&Kernel,
6055
MIsInterop(MDeviceImageImpl->getOriginMask() & ImageOriginInterop),
6156
MKernelArgMaskPtr{ArgMask}, MCacheMutex{CacheMutex},
6257
MOwnsDeviceKernelInfo(checkOwnsDeviceKernelInfo()),
63-
MDeviceKernelInfo(MOwnsDeviceKernelInfo
64-
? createCompileTimeKernelInfo(getName())
65-
: createCompileTimeKernelInfo()) {
58+
MDeviceKernelInfo(MOwnsDeviceKernelInfo ? getName()
59+
: std::string_view()) {
6660

6761
// Enable USM indirect access for interop and non-sycl-jit source kernels.
6862
// sycl-jit kernels will enable this if needed through the regular kernel

sycl/source/detail/program_manager/program_manager.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,18 +1788,6 @@ Managed<ur_program_handle_t> ProgramManager::build(
17881788
return LinkedProg;
17891789
}
17901790

1791-
void ProgramManager::cacheKernelImplicitLocalArg(
1792-
const RTDeviceBinaryImage &Img) {
1793-
const RTDeviceBinaryImage::PropertyRange &ImplicitLocalArgRange =
1794-
Img.getImplicitLocalArg();
1795-
if (ImplicitLocalArgRange.isAvailable())
1796-
for (auto Prop : ImplicitLocalArgRange) {
1797-
auto It = m_DeviceKernelInfoMap.find(Prop->Name);
1798-
assert(It != m_DeviceKernelInfoMap.end());
1799-
It->second.setImplicitLocalArgPos(DeviceBinaryProperty(Prop).asUint32());
1800-
}
1801-
}
1802-
18031791
DeviceKernelInfo &
18041792
ProgramManager::getDeviceKernelInfo(const CompileTimeKernelInfoTy &Info) {
18051793
std::lock_guard<std::mutex> Guard(m_DeviceKernelInfoMapMutex);
@@ -2000,6 +1988,16 @@ void ProgramManager::addImage(sycl_device_binary RawImg,
20001988
m_BinImg2KernelIDs[Img.get()];
20011989
KernelIDs.reset(new std::vector<kernel_id>);
20021990

1991+
std::unordered_map<std::string_view, int> ImplicitLocalArgPositions;
1992+
const RTDeviceBinaryImage::PropertyRange &ImplicitLocalArgRange =
1993+
Img->getImplicitLocalArg();
1994+
if (ImplicitLocalArgRange.isAvailable())
1995+
for (auto Prop : ImplicitLocalArgRange) {
1996+
auto Result = ImplicitLocalArgPositions.try_emplace(
1997+
Prop->Name, DeviceBinaryProperty(Prop).asUint32());
1998+
assert(Result.second && "Duplicate implicit arg property");
1999+
}
2000+
20032001
for (sycl_offload_entry EntriesIt = EntriesB; EntriesIt != EntriesE;
20042002
EntriesIt = EntriesIt->Increment()) {
20052003

@@ -2024,10 +2022,14 @@ void ProgramManager::addImage(sycl_device_binary RawImg,
20242022
m_KernelIDs2BinImage.insert(std::make_pair(It->second, Img.get()));
20252023
KernelIDs->push_back(It->second);
20262024

2027-
CompileTimeKernelInfoTy DefaultCompileTimeInfo{std::string_view(name)};
2028-
m_DeviceKernelInfoMap.try_emplace(std::string_view(name),
2029-
DefaultCompileTimeInfo);
2030-
2025+
std::optional<int> ImplicitLocalArgPos;
2026+
auto ImplicitLocalArgPosIt = ImplicitLocalArgPositions.find(name);
2027+
if (ImplicitLocalArgPosIt != ImplicitLocalArgPositions.end())
2028+
ImplicitLocalArgPos = ImplicitLocalArgPosIt->second;
2029+
auto Result =
2030+
m_DeviceKernelInfoMap.try_emplace(name, name, ImplicitLocalArgPos);
2031+
assert(ImplicitLocalArgPos == Result->first.getImplicitLocalArgPos() &&
2032+
"Conflicting values of implicit local arg positions");
20312033
// Keep track of image to kernel name reference count for cleanup.
20322034
m_KernelNameRefCount[name]++;
20332035
}
@@ -2048,8 +2050,6 @@ void ProgramManager::addImage(sycl_device_binary RawImg,
20482050
}
20492051
}
20502052

2051-
cacheKernelImplicitLocalArg(*Img);
2052-
20532053
// Sort kernel ids for faster search
20542054
std::sort(KernelIDs->begin(), KernelIDs->end(), LessByHash<kernel_id>{});
20552055

sycl/source/detail/program_manager/program_manager.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,6 @@ class ProgramManager {
393393

394394
SanitizerType kernelUsesSanitizer() const { return m_SanitizerFoundInImage; }
395395

396-
void cacheKernelImplicitLocalArg(const RTDeviceBinaryImage &Img);
397-
398396
DeviceKernelInfo &getDeviceKernelInfo(const CompileTimeKernelInfoTy &Info);
399397
DeviceKernelInfo &getDeviceKernelInfo(std::string_view KernelName);
400398
DeviceKernelInfo *tryGetDeviceKernelInfo(std::string_view KernelName);

0 commit comments

Comments
 (0)