Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions GPU/GPUTracking/Base/metal/GPUReconstructionMetal.mm
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ uint32_t metalGPUCoreCount()
} else {
auto* master = dynamic_cast<GPUReconstructionMetal*>(mMaster);
mWarpSize = master->mWarpSize;
mMultiprocessorCount = master->mMultiprocessorCount;
mMaxBackendThreads = master->mMaxBackendThreads;
mDeviceName = master->mDeviceName;
mDeviceConstantMem = master->mDeviceConstantMem;
Expand Down Expand Up @@ -282,21 +283,25 @@ uint32_t metalGPUCoreCount()
{
// Where a pointer lives as far as the backend is concerned. mDeviceMemoryBase is
// a GPU address, so the CPU-visible address of owned memory has to be taken from
// the buffer rather than from the pointer itself.
// the buffer rather than from the pointer itself. The offsets are into the buffers,
// not from the instance's bases: a slave's bases start after the master's
// permanent memory, but it shares the master's buffers.
struct MetalMemRef {
id<MTLBuffer> buffer; // nil for memory the backend does not own
size_t offset;
char* cpu;
};

MetalMemRef metalResolve(const GPUReconstructionMetalInternals* internals, const void* p, const void* hostBase, size_t hostSize, const void* devBase, size_t devSize)
MetalMemRef metalResolve(const GPUReconstructionMetalInternals* internals, const void* p)
{
if (p >= hostBase && p < ((const char*)hostBase + hostSize)) {
const size_t o = (const char*)p - (const char*)hostBase;
const char* hostBase = (const char*)internals->mem_host.contents;
const char* devBase = (const char*)(uintptr_t)internals->mem_gpu.gpuAddress;
if (p >= hostBase && p < hostBase + internals->mem_host.allocatedSize) {
const size_t o = (const char*)p - hostBase;
return {internals->mem_host, o, (char*)internals->mem_host.contents + o};
}
if (p >= devBase && p < ((const char*)devBase + devSize)) {
const size_t o = (const char*)p - (const char*)devBase;
if (p >= devBase && p < devBase + internals->mem_gpu.allocatedSize) {
const size_t o = (const char*)p - devBase;
return {internals->mem_gpu, o, (char*)internals->mem_gpu.contents + o};
}
return {nil, 0, (char*)p};
Expand All @@ -320,8 +325,8 @@ MetalMemRef metalResolve(const GPUReconstructionMetalInternals* internals, const
if (nEvents) {
StreamWaitForEvents(realStream, evList, nEvents);
}
const MetalMemRef s = metalResolve(mInternals, src, mHostMemoryBase, mHostMemorySize, mDeviceMemoryBase, mDeviceMemorySize);
const MetalMemRef d = metalResolve(mInternals, dst, mHostMemoryBase, mHostMemorySize, mDeviceMemoryBase, mDeviceMemorySize);
const MetalMemRef s = metalResolve(mInternals, src);
const MetalMemRef d = metalResolve(mInternals, dst);

if (s.buffer == nil || d.buffer == nil) {
// A blit moves data between MTLBuffers only, and the calibration objects
Expand Down Expand Up @@ -361,7 +366,7 @@ MetalMemRef metalResolve(const GPUReconstructionMetalInternals* internals, const
}

auto realStream = stream == -1 ? 0 : stream;
const MetalMemRef s = metalResolve(mInternals, src, mHostMemoryBase, mHostMemorySize, mDeviceMemoryBase, mDeviceMemorySize);
const MetalMemRef s = metalResolve(mInternals, src);

if (s.buffer == nil) {
DrainStream(realStream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
template <>
inline void GPUReconstructionMetal::runKernelBackend<GPUMemClean16, 0>(const krnlSetupTime& _xyz, void* const& ptr, uint64_t const& size)
{
const uint64_t offset = static_cast<const uint8_t*>(ptr) - static_cast<const uint8_t*>(mDeviceMemoryBase);
// Into mem_gpu, not from mDeviceMemoryBase: a slave shares the buffer, but its base is the end of the master's permanent memory
const uint64_t offset = (uint64_t)(uintptr_t)ptr - mInternals->mem_gpu.gpuAddress;
const uint64_t length = (size + 15ull) & ~15ull;
if (_xyz.z.evList) {
StreamWaitForEvents(_xyz.x.stream, _xyz.z.evList, _xyz.z.nEvents);
Expand Down