Skip to content

Commit 6f7877a

Browse files
committed
GPU Metal: wait for and record the events of kernels and copies
The kernels, the memory clear, GPUMemCpy and WriteToConstantMemory ignored the events they were given, which is how the chain orders the work of its lanes across streams. Wait for the event list before and record the event after, as the CUDA backend does.
1 parent d670d3a commit 6f7877a

3 files changed

Lines changed: 22 additions & 0 deletions

File tree

‎GPU/GPUTracking/Base/metal/GPUReconstructionMetal.mm‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ MetalMemRef metalResolve(const GPUReconstructionMetalInternals* internals, const
232232
}
233233

234234
auto realStream = stream == -1 ? 0 : stream;
235+
if (nEvents) {
236+
StreamWaitForEvents(realStream, evList, nEvents);
237+
}
235238
const MetalMemRef s = metalResolve(mInternals, src, mHostMemoryBase, mHostMemorySize, mDeviceMemoryBase, mDeviceMemorySize);
236239
const MetalMemRef d = metalResolve(mInternals, dst, mHostMemoryBase, mHostMemorySize, mDeviceMemoryBase, mDeviceMemorySize);
237240

@@ -252,6 +255,9 @@ MetalMemRef metalResolve(const GPUReconstructionMetalInternals* internals, const
252255
[blit endEncoding];
253256
CommitStream(realStream);
254257
}
258+
if (ev) {
259+
RecordMarker(ev, realStream);
260+
}
255261

256262
if (GetProcessingSettings().serializeGPU & 2) {
257263
GPUDebug(("GPUMemCpy " + std::to_string(toGPU)).c_str(), stream, true);
@@ -282,6 +288,9 @@ MetalMemRef metalResolve(const GPUReconstructionMetalInternals* internals, const
282288
[blit endEncoding];
283289
CommitStream(realStream);
284290
}
291+
if (ev) {
292+
RecordMarker(ev, realStream);
293+
}
285294

286295
if (GetProcessingSettings().serializeGPU & 2) {
287296
GPUDebug("WriteToConstantMemory", stream, true);

‎GPU/GPUTracking/Base/metal/GPUReconstructionMetalKernels.mm‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
const uint32_t num = GetKernelNum<T, I>();
2626
auto& kExec = _xyz.x;
2727
auto& runRange = _xyz.y;
28+
auto& kEvents = _xyz.z;
29+
if (kEvents.evList) {
30+
StreamWaitForEvents(kExec.stream, kEvents.evList, kEvents.nEvents);
31+
}
2832

2933
id<MTLComputePipelineState> pso = mInternals->pipelines[num];
3034
id<MTLComputeCommandEncoder> computeEncoder = [mInternals->commandBuffers[kExec.stream] computeCommandEncoder];
@@ -51,6 +55,9 @@
5155
// without committing the kernel never reaches the device.
5256
[computeEncoder endEncoding];
5357
CommitStream(kExec.stream);
58+
if (kEvents.ev) {
59+
RecordMarker(kEvents.ev, kExec.stream);
60+
}
5461
}
5562

5663
template <class T, int32_t I>

‎GPU/GPUTracking/Base/metal/GPUReconstructionMetalKernelsSpecialize.inc‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ inline void GPUReconstructionMetal::runKernelBackend<GPUMemClean16, 0>(const krn
1616
{
1717
const uint64_t offset = static_cast<const uint8_t*>(ptr) - static_cast<const uint8_t*>(mDeviceMemoryBase);
1818
const uint64_t length = (size + 15ull) & ~15ull;
19+
if (_xyz.z.evList) {
20+
StreamWaitForEvents(_xyz.x.stream, _xyz.z.evList, _xyz.z.nEvents);
21+
}
1922

2023
id<MTLCommandBuffer> cb = mInternals->commandBuffers[_xyz.x.stream];
2124
id<MTLBlitCommandEncoder> blit = [cb blitCommandEncoder];
@@ -24,4 +27,7 @@ inline void GPUReconstructionMetal::runKernelBackend<GPUMemClean16, 0>(const krn
2427
[blit endEncoding];
2528

2629
CommitStream(_xyz.x.stream);
30+
if (_xyz.z.ev) {
31+
RecordMarker(_xyz.z.ev, _xyz.x.stream);
32+
}
2733
}

0 commit comments

Comments
 (0)