Skip to content

Commit 28ef68e

Browse files
committed
Fix MSVC build error
Signed-off-by: Michael Aziz <[email protected]>
1 parent 43ff03a commit 28ef68e

File tree

1 file changed

+37
-20
lines changed

1 file changed

+37
-20
lines changed

sycl/source/detail/device_global_map_entry.cpp

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,26 @@ bool DeviceGlobalMapEntry::isProfileCounter() {
6666
return MUniqueId.substr(0, CounterPrefix.size()) == CounterPrefix;
6767
}
6868

69+
#ifdef _MSC_VER
70+
extern "C" void
71+
__sycl_increment_profile_counters(std::uint64_t FnHash, std::size_t NumCounters,
72+
const std::uint64_t *Increments);
73+
extern "C" void
74+
__sycl_increment_profile_counters_default(std::uint64_t FnHash,
75+
std::size_t NumCounters,
76+
const std::uint64_t *Increments) {
77+
(void)FnHash;
78+
(void)NumCounters;
79+
(void)Increments;
80+
}
81+
#pragma comment( \
82+
linker, \
83+
"/alternatename:__sycl_increment_profile_counters=__sycl_increment_profile_counters_default")
84+
#else
6985
extern "C" void __attribute__((weak))
7086
__sycl_increment_profile_counters(std::uint64_t FnHash, std::size_t NumCounters,
7187
const std::uint64_t *Increments);
88+
#endif
7289

7390
void DeviceGlobalMapEntry::cleanupProfileCounter(context_impl *CtxImpl) {
7491
std::lock_guard<std::mutex> Lock{MDeviceToUSMPtrMapMutex};
@@ -139,30 +156,30 @@ DeviceGlobalMapEntry::getOrAllocateDeviceGlobalUSM(queue_impl &QueueImpl) {
139156
std::lock_guard<std::mutex> Lock(NewAlloc.MInitEventMutex);
140157
ur_event_handle_t InitEvent;
141158
if (MDeviceGlobalPtr) {
142-
// C++ guarantees members appear in memory in the order they are declared,
143-
// so since the member variable that contains the initial contents of the
144-
// device_global is right after the usm_ptr member variable we can do
145-
// some pointer arithmetic to memcopy over this value to the usm_ptr. This
146-
// value inside of the device_global will be zero-initialized if it was
147-
// not given a value on construction.
159+
// C++ guarantees members appear in memory in the order they are
160+
// declared, so since the member variable that contains the initial
161+
// contents of the device_global is right after the usm_ptr member
162+
// variable we can do some pointer arithmetic to memcopy over this
163+
// value to the usm_ptr. This value inside of the device_global will
164+
// be zero-initialized if it was not given a value on construction.
148165
MemoryManager::copy_usm(
149166
reinterpret_cast<const void *>(
150167
reinterpret_cast<uintptr_t>(MDeviceGlobalPtr) +
151168
sizeof(MDeviceGlobalPtr)),
152169
QueueImpl, MDeviceGlobalTSize, NewAlloc.MPtr,
153170
std::vector<ur_event_handle_t>{}, &InitEvent);
154171
} else {
155-
// For SYCLBIN device globals we do not have a host pointer to copy from,
156-
// so instead we fill the USM memory with 0's.
172+
// For SYCLBIN device globals we do not have a host pointer to copy
173+
// from, so instead we fill the USM memory with 0's.
157174
MemoryManager::fill_usm(NewAlloc.MPtr, QueueImpl, MDeviceGlobalTSize,
158175
{static_cast<unsigned char>(0)}, {}, &InitEvent);
159176
}
160177
NewAlloc.MInitEvent = InitEvent;
161178
}
162179

163180
// Only device globals with host variables need to be registered with the
164-
// context. The rest will be managed by their kernel bundles and cleaned up
165-
// accordingly.
181+
// context. The rest will be managed by their kernel bundles and cleaned
182+
// up accordingly.
166183
if (MDeviceGlobalPtr)
167184
CtxImpl.addAssociatedDeviceGlobal(MDeviceGlobalPtr);
168185
return NewAlloc;
@@ -194,29 +211,29 @@ DeviceGlobalMapEntry::getOrAllocateDeviceGlobalUSM(const context &Context) {
194211
NewAlloc.MAllocatingContext = CtxImpl.shared_from_this();
195212

196213
if (MDeviceGlobalPtr) {
197-
// C++ guarantees members appear in memory in the order they are declared,
198-
// so since the member variable that contains the initial contents of the
199-
// device_global is right after the usm_ptr member variable we can do
200-
// some pointer arithmetic to memcopy over this value to the usm_ptr. This
201-
// value inside of the device_global will be zero-initialized if it was not
202-
// given a value on construction.
214+
// C++ guarantees members appear in memory in the order they are
215+
// declared, so since the member variable that contains the initial
216+
// contents of the device_global is right after the usm_ptr member
217+
// variable we can do some pointer arithmetic to memcopy over this value
218+
// to the usm_ptr. This value inside of the device_global will be
219+
// zero-initialized if it was not given a value on construction.
203220
MemoryManager::context_copy_usm(
204221
reinterpret_cast<const void *>(
205222
reinterpret_cast<uintptr_t>(MDeviceGlobalPtr) +
206223
sizeof(MDeviceGlobalPtr)),
207224
&CtxImpl, MDeviceGlobalTSize, NewAlloc.MPtr);
208225
} else {
209-
// For SYCLBIN device globals we do not have a host pointer to copy from,
210-
// so instead we fill the USM memory with 0's.
226+
// For SYCLBIN device globals we do not have a host pointer to copy
227+
// from, so instead we fill the USM memory with 0's.
211228
std::vector<unsigned char> ImmBuff(MDeviceGlobalTSize,
212229
static_cast<unsigned char>(0));
213230
MemoryManager::context_copy_usm(ImmBuff.data(), &CtxImpl,
214231
MDeviceGlobalTSize, NewAlloc.MPtr);
215232
}
216233

217234
// Only device globals with host variables need to be registered with the
218-
// context. The rest will be managed by their kernel bundles and cleaned up
219-
// accordingly.
235+
// context. The rest will be managed by their kernel bundles and cleaned
236+
// up accordingly.
220237
if (MDeviceGlobalPtr)
221238
CtxImpl.addAssociatedDeviceGlobal(MDeviceGlobalPtr);
222239
return NewAlloc;

0 commit comments

Comments
 (0)