File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -158,7 +158,18 @@ @interface MPSGraphExecutionDescriptor ()
158158 endKernelCoalescing ();
159159 id <MTLBlitCommandEncoder > blitEncoder = [commandBuffer () blitCommandEncoder ];
160160
161- [blitEncoder fillBuffer: buffer range: NSMakeRange (offset, length) value: value];
161+ // For some reason fillBufferfor stopped working for lengh > 4Gb on MacOS 26
162+ // See https://github.com/pytorch/pytorch/issues/163962
163+ // Workaround by batching copy commands into 4Gb chunks
164+ constexpr size_t max_copy_size = 0x100000000 ; // 4GB
165+ size_t bytes_filled = 0 ;
166+ size_t bytes_remains = length;
167+ while (bytes_remains > 0 ) {
168+ NSUInteger bytes_to_copy = std::min (max_copy_size, bytes_remains);
169+ [blitEncoder fillBuffer: buffer range: NSMakeRange (offset + bytes_filled, bytes_to_copy) value: value];
170+ bytes_filled += bytes_to_copy;
171+ bytes_remains -= bytes_to_copy;
172+ }
162173 [blitEncoder endEncoding ];
163174 synchronize (syncType);
164175 }
You can’t perform that action at this time.
0 commit comments