Class: Ignis::Configuration
- Inherits:
-
Object
- Object
- Ignis::Configuration
- Defined in:
- lib/nvruby/configuration.rb
Overview
Global configuration for Ignis Thread-safe configuration access using Mutex
Constant Summary collapse
- DEFAULT_CUDA_PATHS =
Default CUDA installation paths — Windows and Linux
if RUBY_PLATFORM.match?(/mswin|mingw|cygwin/i) [ 'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1', 'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0', 'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.6', 'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.5', 'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.4', 'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.3', 'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.2', 'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.1', 'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.0', 'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8' ].freeze else [ '/usr/local/cuda-13.1', '/usr/local/cuda-13.0', '/usr/local/cuda-12.6', '/usr/local/cuda-12.5', '/usr/local/cuda', '/opt/cuda' ].freeze end
Instance Attribute Summary collapse
-
#autotuning_enabled ⇒ Boolean
Whether to enable autotuning by default.
-
#autotuning_iterations ⇒ Integer
Default number of autotuning iterations.
-
#cuda_path ⇒ String?
Custom CUDA installation path.
-
#default_device ⇒ Integer
Default device index to use.
-
#default_workspace_size ⇒ Integer
Default workspace size in bytes for cuBLAS operations.
-
#log_level ⇒ Symbol
Log level (:debug, :info, :warn, :error, :fatal).
-
#logger ⇒ Logger
Logger instance for Ignis operations.
-
#max_pool_size ⇒ Integer
Maximum memory pool size in bytes (0 for unlimited).
-
#memory_pooling ⇒ Boolean
(also: #use_memory_pool)
Whether to enable memory pooling.
-
#synchronous ⇒ Boolean
Whether to use synchronous execution by default.
Instance Method Summary collapse
-
#cuda_bin_path ⇒ String?
Get the CUDA bin directory.
-
#cuda_lib_path ⇒ String?
Get the CUDA lib directory.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#reset! ⇒ void
Reset configuration to defaults.
-
#resolved_cuda_path ⇒ String?
Get the resolved CUDA path.
-
#with_lock { ... } ⇒ Object
Thread-safe read of configuration values.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/nvruby/configuration.rb', line 68 def initialize @mutex = Mutex.new @cuda_path = nil @default_device = 0 @autotuning_enabled = true @autotuning_iterations = 10 @logger = create_default_logger @log_level = :info @synchronous = false @default_workspace_size = 32 * 1024 * 1024 # 32 MB @memory_pooling = true @max_pool_size = 0 end |
Instance Attribute Details
#autotuning_enabled ⇒ Boolean
Returns Whether to enable autotuning by default.
41 42 43 |
# File 'lib/nvruby/configuration.rb', line 41 def autotuning_enabled @autotuning_enabled end |
#autotuning_iterations ⇒ Integer
Returns Default number of autotuning iterations.
44 45 46 |
# File 'lib/nvruby/configuration.rb', line 44 def autotuning_iterations @autotuning_iterations end |
#cuda_path ⇒ String?
Returns Custom CUDA installation path.
35 36 37 |
# File 'lib/nvruby/configuration.rb', line 35 def cuda_path @cuda_path end |
#default_device ⇒ Integer
Returns Default device index to use.
38 39 40 |
# File 'lib/nvruby/configuration.rb', line 38 def default_device @default_device end |
#default_workspace_size ⇒ Integer
Returns Default workspace size in bytes for cuBLAS operations.
56 57 58 |
# File 'lib/nvruby/configuration.rb', line 56 def default_workspace_size @default_workspace_size end |
#log_level ⇒ Symbol
Returns Log level (:debug, :info, :warn, :error, :fatal).
50 51 52 |
# File 'lib/nvruby/configuration.rb', line 50 def log_level @log_level end |
#logger ⇒ Logger
Returns Logger instance for Ignis operations.
47 48 49 |
# File 'lib/nvruby/configuration.rb', line 47 def logger @logger end |
#max_pool_size ⇒ Integer
Returns Maximum memory pool size in bytes (0 for unlimited).
62 63 64 |
# File 'lib/nvruby/configuration.rb', line 62 def max_pool_size @max_pool_size end |
#memory_pooling ⇒ Boolean Also known as: use_memory_pool
Returns Whether to enable memory pooling.
59 60 61 |
# File 'lib/nvruby/configuration.rb', line 59 def memory_pooling @memory_pooling end |
#synchronous ⇒ Boolean
Returns Whether to use synchronous execution by default.
53 54 55 |
# File 'lib/nvruby/configuration.rb', line 53 def synchronous @synchronous end |
Instance Method Details
#cuda_bin_path ⇒ String?
Get the CUDA bin directory
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/nvruby/configuration.rb', line 109 def cuda_bin_path base = resolved_cuda_path return nil unless base # Use forward slashes for Ruby compatibility base_normalized = base.tr("\\", "/") if RUBY_PLATFORM.match?(/mswin|mingw|cygwin/i) # Windows: check bin/x64 first, then bin x64_path = File.join(base_normalized, "bin", "x64") if File.directory?(x64_path) dll_check = Dir.glob(File.join(x64_path, "*.dll")) return x64_path if dll_check.any? end File.join(base_normalized, "bin") else # Linux: use lib64 lib64_path = File.join(base_normalized, "lib64") return lib64_path if File.directory?(lib64_path) File.join(base_normalized, "lib") end end |
#cuda_lib_path ⇒ String?
Get the CUDA lib directory
134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/nvruby/configuration.rb', line 134 def cuda_lib_path base = resolved_cuda_path return nil unless base if RUBY_PLATFORM.match?(/mswin|mingw|cygwin/i) lib_path = File.join(base, "lib", "x64") return lib_path if File.directory?(lib_path) File.join(base, "lib") else lib_path = File.join(base, "lib64") return lib_path if File.directory?(lib_path) File.join(base, "lib") end end |
#reset! ⇒ void
This method returns an undefined value.
Reset configuration to defaults
151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/nvruby/configuration.rb', line 151 def reset! @mutex.synchronize do @cuda_path = nil @default_device = 0 @autotuning_enabled = true @autotuning_iterations = 10 @logger = create_default_logger @log_level = :info @synchronous = false @default_workspace_size = 32 * 1024 * 1024 @memory_pooling = true @max_pool_size = 0 end end |
#resolved_cuda_path ⇒ String?
Get the resolved CUDA path
94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/nvruby/configuration.rb', line 94 def resolved_cuda_path @mutex.synchronize do return @cuda_path if @cuda_path && File.directory?(@cuda_path) # Check environment variable env_path = ENV["CUDA_PATH"] return env_path if env_path && File.directory?(env_path) # Search default paths DEFAULT_CUDA_PATHS.find { |path| File.directory?(path) } end end |
#with_lock { ... } ⇒ Object
Thread-safe read of configuration values
169 170 171 |
# File 'lib/nvruby/configuration.rb', line 169 def with_lock(&block) @mutex.synchronize(&block) end |