Crash using get_devices_for_type() to choose cycles device with python #81877

Open
opened 2020-10-20 03:34:03 +02:00 by Cedar Myers · 5 comments

System Information
Operating system: Ubuntu 20.04.1 LTS
Graphics card: GTX 1070 + GTX 1070 + GTX 1050 Ti, NVIDIA 440.100

Blender Version
Broken: 2.91.0 nightly, Commit date: 2020-10-19 22:48, Hash ea4d28aea0
Worked: 2.83.7

Short description of error
This is a follow-up of #81520. Commit 1001adb500 fixes get_devices() but get_devices_for_type() remains broken. As previously something about the combination of OPTIX and OPENCL messes up the CUDA devices. Also I have since discovered that by changing the order getting OPTIX devices can mess with OPENCL devices.

This may be an issue specific to multi-gpu systems. I am willing to reconfigure hardware to help test if needed.

Exact steps for others to reproduce the error

blender --factory-startup --python-expr "import bpy; \
  cuda_devices = bpy.context.preferences.addons['cycles'].preferences.get_devices_for_type('CUDA'); \
  optix_devices = bpy.context.preferences.addons['cycles'].preferences.get_devices_for_type('OPTIX'); \
  opencl_devices = bpy.context.preferences.addons['cycles'].preferences.get_devices_for_type('OPENCL'); \
  cuda_devices[0].use = True"

or

blender --factory-startup --python-expr "import bpy; \
  cuda_devices = bpy.context.preferences.addons['cycles'].preferences.get_devices_for_type('CUDA'); \
  opencl_devices = bpy.context.preferences.addons['cycles'].preferences.get_devices_for_type('OPENCL'); \
  optix_devices = bpy.context.preferences.addons['cycles'].preferences.get_devices_for_type('OPTIX'); \
  cuda_devices[0].use = True"

More information:
It seems like something is overwriting something else. Are these device locations supposed to be inter-related across types? Perhaps this can help. Consider the different CUDA and OPENCL devices for the CPU at 0x7fa3700c8088 and 0x7fa370412188 respectively in the first example. In the second example below the single device at 0x7f72950c8088 is both the CUDA and OPENCL device. Which behavior is correct? (And does any of this potentially indicate other issues?)

My output (formatted)

blender --factory-startup --python-expr "import bpy; \
  cuda_devices = bpy.context.preferences.addons['cycles'].preferences.get_devices_for_type('CUDA'); \
  print('CUDA devices before getting anything else', cuda_devices); \
  optix_devices = bpy.context.preferences.addons['cycles'].preferences.get_devices_for_type('OPTIX'); \
  print('CUDA devices before getting OPENCL devices', cuda_devices); \
  print('OPTIX devices before getting OPENCL devices', optix_devices); \
  opencl_devices = bpy.context.preferences.addons['cycles'].preferences.get_devices_for_type('OPENCL'); \
  print('CUDA devices after getting OPENCL devices', cuda_devices); \
  print('OPTIX devices after getting OPENCL devices', optix_devices); \
  print('OPENCL devices', opencl_devices); \
  cuda_devices[0].use = True"

CUDA devices before getting anything else [
  <bpy_struct, CyclesDeviceSettings("GeForce GTX 1070") at 0x7fa3700c7f08>,
  <bpy_struct, CyclesDeviceSettings("GeForce GTX 1070") at 0x7fa3700c7f88>,
  <bpy_struct, CyclesDeviceSettings("GeForce GTX 1050 Ti") at 0x7fa3700c8008>,
  <bpy_struct, CyclesDeviceSettings("AMD Ryzen 9 3900X 12-Core Processor") at 0x7fa3700c8088>
]
CUDA devices before getting OPENCL devices [
  <bpy_struct, CyclesDeviceSettings("GeForce GTX 1070") at 0x7fa3700c7f08>,
  <bpy_struct, CyclesDeviceSettings("GeForce GTX 1070") at 0x7fa3700c7f88>,
  <bpy_struct, CyclesDeviceSettings("GeForce GTX 1050 Ti") at 0x7fa3700c8008>,
  <bpy_struct, CyclesDeviceSettings("AMD Ryzen 9 3900X 12-Core Processor") at 0x7fa3700c8088>
]
OPTIX devices before getting OPENCL devices [
  <bpy_struct, CyclesDeviceSettings("GeForce GTX 1070") at 0x7fa370412208>,
  <bpy_struct, CyclesDeviceSettings("GeForce GTX 1070") at 0x7fa370412288>,
  <bpy_struct, CyclesDeviceSettings("GeForce GTX 1050 Ti") at 0x7fa370412308>
]
CUDA devices after getting OPENCL devices [
  <bpy_struct, CyclesDeviceSettings("") at 0x7fa3700c7f08>,
  <bpy_struct, CyclesDeviceSettings("") at 0x7fa3700c7f88>,
  <bpy_struct, CyclesDeviceSettings("") at 0x7fa3700c8008>,
  <bpy_struct, CyclesDeviceSettings("") at 0x7fa3700c8088>
]
OPTIX devices after getting OPENCL devices [
  <bpy_struct, CyclesDeviceSettings("GeForce GTX 1070") at 0x7fa370412208>,
  <bpy_struct, CyclesDeviceSettings("GeForce GTX 1070") at 0x7fa370412288>,
  <bpy_struct, CyclesDeviceSettings("GeForce GTX 1050 Ti") at 0x7fa370412308>
]
OPENCL devices [
  <bpy_struct, CyclesDeviceSettings("AMD Ryzen 9 3900X 12-Core Processor") at 0x7fa370412188>
]
Writing: /tmp/blender.crash.txt
Segmentation fault (core dumped)

and

blender --factory-startup --python-expr "import bpy; \
  cuda_devices = bpy.context.preferences.addons['cycles'].preferences.get_devices_for_type('CUDA'); \
  print('CUDA devices before getting anything else', cuda_devices); \
  opencl_devices = bpy.context.preferences.addons['cycles'].preferences.get_devices_for_type('OPENCL'); \
  print('CUDA devices before getting OPTIX devices', cuda_devices); \
  print('OPENCL devices before getting OPTIX devices', opencl_devices); \
  optix_devices = bpy.context.preferences.addons['cycles'].preferences.get_devices_for_type('OPTIX'); \
  print('CUDA devices after getting OPTIX devices', cuda_devices); \
  print('OPENCL devices after getting OPTIX devices', opencl_devices); \
  print('OPTIX devices', optix_devices); \
  cuda_devices[0].use = True"

CUDA devices before getting anything else [
  <bpy_struct, CyclesDeviceSettings("GeForce GTX 1070") at 0x7f72950c7f08>,
  <bpy_struct, CyclesDeviceSettings("GeForce GTX 1070") at 0x7f72950c7f88>,
  <bpy_struct, CyclesDeviceSettings("GeForce GTX 1050 Ti") at 0x7f72950c8008>,
  <bpy_struct, CyclesDeviceSettings("AMD Ryzen 9 3900X 12-Core Processor") at 0x7f72950c8088>
]
CUDA devices before getting OPTIX devices [
  <bpy_struct, CyclesDeviceSettings("GeForce GTX 1070") at 0x7f72950c7f08>,
  <bpy_struct, CyclesDeviceSettings("GeForce GTX 1070") at 0x7f72950c7f88>,
  <bpy_struct, CyclesDeviceSettings("GeForce GTX 1050 Ti") at 0x7f72950c8008>,
  <bpy_struct, CyclesDeviceSettings("AMD Ryzen 9 3900X 12-Core Processor") at 0x7f72950c8088>
]
OPENCL devices before getting OPTIX devices [
  <bpy_struct, CyclesDeviceSettings("AMD Ryzen 9 3900X 12-Core Processor") at 0x7f72950c8088>
]
CUDA devices after getting OPTIX devices [
  <bpy_struct, CyclesDeviceSettings("") at 0x7f72950c7f08>,
  <bpy_struct, CyclesDeviceSettings("") at 0x7f72950c7f88>,
  <bpy_struct, CyclesDeviceSettings("") at 0x7f72950c8008>,
  <bpy_struct, CyclesDeviceSettings("") at 0x7f72950c8088>
]
OPENCL devices after getting OPTIX devices [
  <bpy_struct, CyclesDeviceSettings("") at 0x7f72950c8088>
]
OPTIX devices [
  <bpy_struct, CyclesDeviceSettings("GeForce GTX 1070") at 0x7f7295420108>,
  <bpy_struct, CyclesDeviceSettings("GeForce GTX 1070") at 0x7f7295420188>,
  <bpy_struct, CyclesDeviceSettings("GeForce GTX 1050 Ti") at 0x7f7295420208>
]
Writing: /tmp/blender.crash.txt
Segmentation fault (core dumped)
**System Information** Operating system: Ubuntu 20.04.1 LTS Graphics card: GTX 1070 + GTX 1070 + GTX 1050 Ti, NVIDIA 440.100 **Blender Version** Broken: 2.91.0 nightly, Commit date: 2020-10-19 22:48, Hash ea4d28aea034 Worked: 2.83.7 **Short description of error** This is a follow-up of #81520. Commit 1001adb500 fixes get_devices() but get_devices_for_type() remains broken. As previously something about the combination of OPTIX and OPENCL messes up the CUDA devices. Also I have since discovered that by changing the order getting OPTIX devices can mess with OPENCL devices. This may be an issue specific to multi-gpu systems. I am willing to reconfigure hardware to help test if needed. **Exact steps for others to reproduce the error** ``` blender --factory-startup --python-expr "import bpy; \ cuda_devices = bpy.context.preferences.addons['cycles'].preferences.get_devices_for_type('CUDA'); \ optix_devices = bpy.context.preferences.addons['cycles'].preferences.get_devices_for_type('OPTIX'); \ opencl_devices = bpy.context.preferences.addons['cycles'].preferences.get_devices_for_type('OPENCL'); \ cuda_devices[0].use = True" ``` or ``` blender --factory-startup --python-expr "import bpy; \ cuda_devices = bpy.context.preferences.addons['cycles'].preferences.get_devices_for_type('CUDA'); \ opencl_devices = bpy.context.preferences.addons['cycles'].preferences.get_devices_for_type('OPENCL'); \ optix_devices = bpy.context.preferences.addons['cycles'].preferences.get_devices_for_type('OPTIX'); \ cuda_devices[0].use = True" ``` **More information:** It seems like something is overwriting something else. Are these device locations supposed to be inter-related across types? Perhaps this can help. Consider the _different_ CUDA and OPENCL devices for the CPU at 0x7fa3700c8088 and 0x7fa370412188 respectively in the first example. In the second example below the single device at 0x7f72950c8088 is both the **CUDA and OPENCL** device. Which behavior is correct? (And does any of this potentially indicate other issues?) My output (formatted) ``` blender --factory-startup --python-expr "import bpy; \ cuda_devices = bpy.context.preferences.addons['cycles'].preferences.get_devices_for_type('CUDA'); \ print('CUDA devices before getting anything else', cuda_devices); \ optix_devices = bpy.context.preferences.addons['cycles'].preferences.get_devices_for_type('OPTIX'); \ print('CUDA devices before getting OPENCL devices', cuda_devices); \ print('OPTIX devices before getting OPENCL devices', optix_devices); \ opencl_devices = bpy.context.preferences.addons['cycles'].preferences.get_devices_for_type('OPENCL'); \ print('CUDA devices after getting OPENCL devices', cuda_devices); \ print('OPTIX devices after getting OPENCL devices', optix_devices); \ print('OPENCL devices', opencl_devices); \ cuda_devices[0].use = True" CUDA devices before getting anything else [ <bpy_struct, CyclesDeviceSettings("GeForce GTX 1070") at 0x7fa3700c7f08>, <bpy_struct, CyclesDeviceSettings("GeForce GTX 1070") at 0x7fa3700c7f88>, <bpy_struct, CyclesDeviceSettings("GeForce GTX 1050 Ti") at 0x7fa3700c8008>, <bpy_struct, CyclesDeviceSettings("AMD Ryzen 9 3900X 12-Core Processor") at 0x7fa3700c8088> ] CUDA devices before getting OPENCL devices [ <bpy_struct, CyclesDeviceSettings("GeForce GTX 1070") at 0x7fa3700c7f08>, <bpy_struct, CyclesDeviceSettings("GeForce GTX 1070") at 0x7fa3700c7f88>, <bpy_struct, CyclesDeviceSettings("GeForce GTX 1050 Ti") at 0x7fa3700c8008>, <bpy_struct, CyclesDeviceSettings("AMD Ryzen 9 3900X 12-Core Processor") at 0x7fa3700c8088> ] OPTIX devices before getting OPENCL devices [ <bpy_struct, CyclesDeviceSettings("GeForce GTX 1070") at 0x7fa370412208>, <bpy_struct, CyclesDeviceSettings("GeForce GTX 1070") at 0x7fa370412288>, <bpy_struct, CyclesDeviceSettings("GeForce GTX 1050 Ti") at 0x7fa370412308> ] CUDA devices after getting OPENCL devices [ <bpy_struct, CyclesDeviceSettings("") at 0x7fa3700c7f08>, <bpy_struct, CyclesDeviceSettings("") at 0x7fa3700c7f88>, <bpy_struct, CyclesDeviceSettings("") at 0x7fa3700c8008>, <bpy_struct, CyclesDeviceSettings("") at 0x7fa3700c8088> ] OPTIX devices after getting OPENCL devices [ <bpy_struct, CyclesDeviceSettings("GeForce GTX 1070") at 0x7fa370412208>, <bpy_struct, CyclesDeviceSettings("GeForce GTX 1070") at 0x7fa370412288>, <bpy_struct, CyclesDeviceSettings("GeForce GTX 1050 Ti") at 0x7fa370412308> ] OPENCL devices [ <bpy_struct, CyclesDeviceSettings("AMD Ryzen 9 3900X 12-Core Processor") at 0x7fa370412188> ] Writing: /tmp/blender.crash.txt Segmentation fault (core dumped) ``` and ``` blender --factory-startup --python-expr "import bpy; \ cuda_devices = bpy.context.preferences.addons['cycles'].preferences.get_devices_for_type('CUDA'); \ print('CUDA devices before getting anything else', cuda_devices); \ opencl_devices = bpy.context.preferences.addons['cycles'].preferences.get_devices_for_type('OPENCL'); \ print('CUDA devices before getting OPTIX devices', cuda_devices); \ print('OPENCL devices before getting OPTIX devices', opencl_devices); \ optix_devices = bpy.context.preferences.addons['cycles'].preferences.get_devices_for_type('OPTIX'); \ print('CUDA devices after getting OPTIX devices', cuda_devices); \ print('OPENCL devices after getting OPTIX devices', opencl_devices); \ print('OPTIX devices', optix_devices); \ cuda_devices[0].use = True" CUDA devices before getting anything else [ <bpy_struct, CyclesDeviceSettings("GeForce GTX 1070") at 0x7f72950c7f08>, <bpy_struct, CyclesDeviceSettings("GeForce GTX 1070") at 0x7f72950c7f88>, <bpy_struct, CyclesDeviceSettings("GeForce GTX 1050 Ti") at 0x7f72950c8008>, <bpy_struct, CyclesDeviceSettings("AMD Ryzen 9 3900X 12-Core Processor") at 0x7f72950c8088> ] CUDA devices before getting OPTIX devices [ <bpy_struct, CyclesDeviceSettings("GeForce GTX 1070") at 0x7f72950c7f08>, <bpy_struct, CyclesDeviceSettings("GeForce GTX 1070") at 0x7f72950c7f88>, <bpy_struct, CyclesDeviceSettings("GeForce GTX 1050 Ti") at 0x7f72950c8008>, <bpy_struct, CyclesDeviceSettings("AMD Ryzen 9 3900X 12-Core Processor") at 0x7f72950c8088> ] OPENCL devices before getting OPTIX devices [ <bpy_struct, CyclesDeviceSettings("AMD Ryzen 9 3900X 12-Core Processor") at 0x7f72950c8088> ] CUDA devices after getting OPTIX devices [ <bpy_struct, CyclesDeviceSettings("") at 0x7f72950c7f08>, <bpy_struct, CyclesDeviceSettings("") at 0x7f72950c7f88>, <bpy_struct, CyclesDeviceSettings("") at 0x7f72950c8008>, <bpy_struct, CyclesDeviceSettings("") at 0x7f72950c8088> ] OPENCL devices after getting OPTIX devices [ <bpy_struct, CyclesDeviceSettings("") at 0x7f72950c8088> ] OPTIX devices [ <bpy_struct, CyclesDeviceSettings("GeForce GTX 1070") at 0x7f7295420108>, <bpy_struct, CyclesDeviceSettings("GeForce GTX 1070") at 0x7f7295420188>, <bpy_struct, CyclesDeviceSettings("GeForce GTX 1050 Ti") at 0x7f7295420208> ] Writing: /tmp/blender.crash.txt Segmentation fault (core dumped) ```
Author

Added subscriber: @Cedar-Myers

Added subscriber: @Cedar-Myers

Added subscriber: @ideasman42

Added subscriber: @ideasman42

This is caused by re-allocation each time get_devices_for_type is called, suggest either...

  • Initialize devices for all types (once) so re-allocation doesn't occur.
Assume this would cause problems if devices are added at run-time (is that even supported?)
  • Return copies from get_devices_for_type (named-tuples for example).
Is it ever necessary to write to the returned values?

We could make the current get_devices_for_type into a private function, which can be used for drawing, then have a public version that copies the values to avoid these allocation issues.

This is caused by re-allocation each time `get_devices_for_type` is called, suggest either... - Initialize devices for all types (once) so re-allocation doesn't occur. ``` Assume this would cause problems if devices are added at run-time (is that even supported?) ``` - Return copies from `get_devices_for_type` (named-tuples for example). ``` Is it ever necessary to write to the returned values? ``` ---- We could make the current `get_devices_for_type` into a private function, which can be used for drawing, then have a public version that copies the values to avoid these allocation issues.
Contributor

Added subscriber: @Raimund58

Added subscriber: @Raimund58
Member

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'
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
4 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#81877
No description provided.