Zero-initialize id<MTLDevice> etc. members in Tensor

PiperOrigin-RevId: 488308585
This commit is contained in:
Nikolay Chirkov 2022-11-14 02:29:30 -08:00 committed by Copybara-Service
parent 6610ca72ba
commit bc6240e989
2 changed files with 7 additions and 3 deletions

View File

@ -387,7 +387,9 @@ void Tensor::Move(Tensor* src) {
src->cpu_buffer_ = nullptr; src->cpu_buffer_ = nullptr;
#if MEDIAPIPE_METAL_ENABLED #if MEDIAPIPE_METAL_ENABLED
device_ = src->device_; device_ = src->device_;
src->device_ = nil;
command_buffer_ = src->command_buffer_; command_buffer_ = src->command_buffer_;
src->command_buffer_ = nil;
metal_buffer_ = src->metal_buffer_; metal_buffer_ = src->metal_buffer_;
src->metal_buffer_ = nil; src->metal_buffer_ = nil;
#endif // MEDIAPIPE_METAL_ENABLED #endif // MEDIAPIPE_METAL_ENABLED
@ -431,6 +433,8 @@ void Tensor::Invalidate() {
DeallocateVirtualMemory(cpu_buffer_, AlignToPageSize(bytes())); DeallocateVirtualMemory(cpu_buffer_, AlignToPageSize(bytes()));
} }
metal_buffer_ = nil; metal_buffer_ = nil;
command_buffer_ = nil;
device_ = nil;
cpu_buffer_ = nullptr; cpu_buffer_ = nullptr;
#if MEDIAPIPE_OPENGL_ES_VERSION >= MEDIAPIPE_OPENGL_ES_30 #if MEDIAPIPE_OPENGL_ES_VERSION >= MEDIAPIPE_OPENGL_ES_30
// Don't need to wait for the resource to be deleted bacause if will be // Don't need to wait for the resource to be deleted bacause if will be

View File

@ -384,9 +384,9 @@ class Tensor {
mutable void* cpu_buffer_ = nullptr; mutable void* cpu_buffer_ = nullptr;
void AllocateCpuBuffer() const; void AllocateCpuBuffer() const;
#if MEDIAPIPE_METAL_ENABLED #if MEDIAPIPE_METAL_ENABLED
mutable id<MTLCommandBuffer> command_buffer_; mutable id<MTLCommandBuffer> command_buffer_ = nil;
mutable id<MTLDevice> device_; mutable id<MTLDevice> device_ = nil;
mutable id<MTLBuffer> metal_buffer_; mutable id<MTLBuffer> metal_buffer_ = nil;
void AllocateMtlBuffer(id<MTLDevice> device) const; void AllocateMtlBuffer(id<MTLDevice> device) const;
#endif // MEDIAPIPE_METAL_ENABLED #endif // MEDIAPIPE_METAL_ENABLED