Class: Ignis::JIT::Compiler
- Inherits:
-
Object
- Object
- Ignis::JIT::Compiler
- Defined in:
- lib/nvruby/jit/compiler.rb
Overview
JIT Compiler with multi-level caching Provides runtime compilation of CUDA C++ source to executable kernels Based on nvmath-python caching strategy:
-
Thread-local cache for fast path (no locking)
-
Shared cache with Mutex for cross-thread reuse
-
Cache key: source code hash + compute capability
Constant Summary collapse
- DEFAULT_OPTIONS =
Default compilation options
[ "--fmad=true", "--std=c++17", "-default-device" ].freeze
- THREAD_LOCAL_CACHE_KEY =
Thread-local storage key for kernel pointer cache
:nvruby_jit_kernel_cache
Class Method Summary collapse
-
.cache_stats ⇒ Hash
Get cache statistics.
-
.clear_cache! ⇒ void
Clear all caches.
-
.clear_thread_local_cache! ⇒ void
Clear thread-local cache only.
-
.compile(source, kernel_name, device_id: 0, options: []) ⇒ Kernel
Compile CUDA source code and return an executable Kernel.
-
.compile_only(source, kernel_name, compute_capability:, options: []) ⇒ CompiledKernel
Compile to CompiledKernel without loading (for caching/serialization).
-
.version_info ⇒ Hash
Get version information.
Class Method Details
.cache_stats ⇒ Hash
Get cache statistics
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/nvruby/jit/compiler.rb', line 81 def cache_stats @cache_mutex.synchronize do compiled_count = @compiled_code_cache.values.sum { |h| h.size } module_count = @kernel_module_cache.values.sum { |h| h.size } { compiled_kernels: compiled_count, loaded_modules: module_count, compute_capabilities: @compiled_code_cache.keys, devices_with_modules: @kernel_module_cache.keys } end end |
.clear_cache! ⇒ void
This method returns an undefined value.
Clear all caches
64 65 66 67 68 69 70 71 |
# File 'lib/nvruby/jit/compiler.rb', line 64 def clear_cache! @cache_mutex.synchronize do @compiled_code_cache.clear @kernel_module_cache.clear end clear_thread_local_cache! Ignis.logger.info("JIT compiler caches cleared") end |
.clear_thread_local_cache! ⇒ void
This method returns an undefined value.
Clear thread-local cache only
75 76 77 |
# File 'lib/nvruby/jit/compiler.rb', line 75 def clear_thread_local_cache! Thread.current[THREAD_LOCAL_CACHE_KEY] = nil end |
.compile(source, kernel_name, device_id: 0, options: []) ⇒ Kernel
Compile CUDA source code and return an executable Kernel
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/nvruby/jit/compiler.rb', line 37 def compile(source, kernel_name, device_id: 0, options: []) source_hash = compute_source_hash(source, kernel_name) cc = get_device_cc(device_id) kernel_ptr = get_cached_kernel(device_id, source_hash) return kernel_ptr if kernel_ptr @cache_mutex.synchronize do kernel_ptr = get_kernel_module_cached(source, source_hash, kernel_name, device_id, cc, ) cache_kernel_pointer(device_id, source_hash, kernel_ptr) kernel_ptr end end |
.compile_only(source, kernel_name, compute_capability:, options: []) ⇒ CompiledKernel
Compile to CompiledKernel without loading (for caching/serialization)
58 59 60 |
# File 'lib/nvruby/jit/compiler.rb', line 58 def compile_only(source, kernel_name, compute_capability:, options: []) compile_to_cubin(source, kernel_name, compute_capability, ) end |
.version_info ⇒ Hash
Get version information
97 98 99 100 101 102 |
# File 'lib/nvruby/jit/compiler.rb', line 97 def version_info { nvrtc: NVRTCBindings.version, cuda_driver: Ignis.cuda_version } end |