Crash when rendering with CUDA / OptiX #85089

Closed
opened 2021-01-26 22:35:20 +01:00 by James Horsley · 11 comments

System Information
Operating system: Windows-10-10.0.19041-SP0 64 Bits
Graphics card: GeForce RTX 3080/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 460.79

Blender Version
Broken: version: 2.92.0 Beta, branch: master, commit date: 2021-01-25 22:10, hash: 77f73a9284
Worked: 2.91.2

Short description of error
Crashes while loading textures to GPU memory using CUDA.
After some digging in the code it seems to happen when the device memory is low and it decides to 'move_textures_to_host' then it ends up trying to lock 'cuda_mem_map_mutex' twice.
Example stack trace:
image.png

Attached .blend just has 16k and 8k generated black textures and highly subdivided cubes to fill GPU memory. Can't seem to get this to crash in the 2.91.2 release build.

Exact steps for others to reproduce the error
Select CUDA or OptiX as the device
Render a scene with large textures
292Crash.blend

**System Information** Operating system: Windows-10-10.0.19041-SP0 64 Bits Graphics card: GeForce RTX 3080/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 460.79 **Blender Version** Broken: version: 2.92.0 Beta, branch: master, commit date: 2021-01-25 22:10, hash: `77f73a9284` Worked: 2.91.2 **Short description of error** Crashes while loading textures to GPU memory using CUDA. After some digging in the code it seems to happen when the device memory is low and it decides to 'move_textures_to_host' then it ends up trying to lock 'cuda_mem_map_mutex' twice. Example stack trace: ![image.png](https://archive.blender.org/developer/F9599185/image.png) Attached .blend just has 16k and 8k generated black textures and highly subdivided cubes to fill GPU memory. Can't seem to get this to crash in the 2.91.2 release build. **Exact steps for others to reproduce the error** Select CUDA or OptiX as the device Render a scene with large textures [292Crash.blend](https://archive.blender.org/developer/F9599178/292Crash.blend)
Author

Added subscriber: @mmdanggg2

Added subscriber: @mmdanggg2
Author

Seems to have been introduced with bfb6fce659

Seems to have been introduced with bfb6fce659

Added subscriber: @olivier.fx

Added subscriber: @olivier.fx

I've hit this deadlock bug last week as well: I believe you're right, it was introduced when the scoped locks were put in. When the GPU mem is full, the mechanism to free items from the device mem to re-allocate them on the host now suffers from a deadlock, since move_textures_to_host is called from within a mutex locked scope. The method then calls free/alloc which try to acquire the same lock (cuda_mem_map_mutex) and cause a deadlock.

I think the same bug is responsible for #84734.

I fixed the pb guarding the mem calls in CUDADevice::move_textures_to_host(size_t size, bool for_texture):

      /*
       * This method is called from generic_alloc(), which itself is always
       * called in a scope with a thread_scoped_lock lock on cuda_mem_map_mutex.
       * By definition, a call to device_copy_to will free and allocate memory,
       * requiring a lock on cuda_mem_map_mutex, so we need to unlock
       * cuda_mem_map_mutex in order to prevent a systematic deadlock.
       */
      cuda_mem_map_mutex.unlock();
      max_mem->device_copy_to();
      cuda_mem_map_mutex.lock();

And at the end of the method since load_texture_info also tries to acquire the same lock:

  /* Update texture info array with new pointers.
   * See comment above regarding the mutex unlocking */
  cuda_mem_map_mutex.unlock();
  load_texture_info();
  cuda_mem_map_mutex.lock();
I've hit this deadlock bug last week as well: I believe you're right, it was introduced when the scoped locks were put in. When the GPU mem is full, the mechanism to free items from the device mem to re-allocate them on the host now suffers from a deadlock, since `move_textures_to_host` is called from within a mutex locked scope. The method then calls free/alloc which try to acquire the same lock (`cuda_mem_map_mutex`) and cause a deadlock. I think the same bug is responsible for #84734. I fixed the pb guarding the mem calls in `CUDADevice::move_textures_to_host(size_t size, bool for_texture)`: ``` /* * This method is called from generic_alloc(), which itself is always * called in a scope with a thread_scoped_lock lock on cuda_mem_map_mutex. * By definition, a call to device_copy_to will free and allocate memory, * requiring a lock on cuda_mem_map_mutex, so we need to unlock * cuda_mem_map_mutex in order to prevent a systematic deadlock. */ cuda_mem_map_mutex.unlock(); max_mem->device_copy_to(); cuda_mem_map_mutex.lock(); ``` And at the end of the method since `load_texture_info` also tries to acquire the same lock: ``` /* Update texture info array with new pointers. * See comment above regarding the mutex unlocking */ cuda_mem_map_mutex.unlock(); load_texture_info(); cuda_mem_map_mutex.lock(); ```

Just saw your diff, great! (was just about to submit one, will take yours).

Just saw your diff, great! (was just about to submit one, will take yours).

Added subscriber: @rjg

Added subscriber: @rjg

@mmdanggg2 @olivier.fx This is a duplicate of #84734. I will merge this ticket into that one and try to put the information you've gathered in there as well.

Thank you for investigating this. Please continue the discussion in the ticket this one has been merged into.

@mmdanggg2 @olivier.fx This is a duplicate of #84734. I will merge this ticket into that one and try to put the information you've gathered in there as well. Thank you for investigating this. Please continue the discussion in the ticket this one has been merged into.

Closed as duplicate of #84734

Closed as duplicate of #84734

This issue was referenced by blender/cycles@88c43b68e6

This issue was referenced by blender/cycles@88c43b68e6d923c560086d2fe7d6ff5d7562956b

This issue was referenced by 4fbeb3e6be

This issue was referenced by 4fbeb3e6be3ed03e55ebd8a9d41c80c2a4f08815
Member

Changed status from 'Duplicate' to: 'Resolved'

Changed status from 'Duplicate' to: 'Resolved'
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
5 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#85089
No description provided.