@@ -92,36 +92,46 @@ pub enum ModuleJitOption {
9292
9393impl ModuleJitOption {
9494 pub fn into_raw ( opts : & [ Self ] ) -> ( Vec < cuda:: CUjit_option > , Vec < * mut c_void > ) {
95+ // And here we stumble across one of the most horrific things i have ever seen in my entire
96+ // journey of working with many parts of CUDA. As a background, CUDA usually wants an array
97+ // of pointers to values when it takes void**, after all, this is what is expected by anyone.
98+ // However, there is a SINGLE exception in the entire driver API, and that is cuModuleLoadDataEx,
99+ // it actually wants you to pass values by value instead of by ref if they fit into pointer length.
100+ // Therefore something like MaxRegisters should be passed as `u32 as usize as *mut c_void`.
101+ // This is completely undocumented. I initially brought this up to an nvidia developer,
102+ // who eventually was able to figure out this issue, currently it appears to be labeled "not a bug",
103+ // however this will likely be changed in the future, or at least get documented better. (hopefully)
95104 let mut raw_opts = Vec :: with_capacity ( opts. len ( ) ) ;
96105 let mut raw_vals = Vec :: with_capacity ( opts. len ( ) ) ;
106+
97107 for opt in opts {
98108 match opt {
99109 Self :: MaxRegisters ( regs) => {
100110 raw_opts. push ( cuda:: CUjit_option :: CU_JIT_MAX_REGISTERS ) ;
101- raw_vals. push ( regs as * const u32 as * mut _ ) ;
111+ raw_vals. push ( * regs as usize as * mut c_void ) ;
102112 }
103113 Self :: OptLevel ( level) => {
104114 raw_opts. push ( cuda:: CUjit_option :: CU_JIT_OPTIMIZATION_LEVEL ) ;
105- raw_vals. push ( level as * const OptLevel as * mut _ ) ;
115+ raw_vals. push ( * level as usize as * mut c_void ) ;
106116 }
107117 Self :: DetermineTargetFromContext => {
108118 raw_opts. push ( cuda:: CUjit_option :: CU_JIT_TARGET_FROM_CUCONTEXT ) ;
109119 }
110120 Self :: Target ( target) => {
111121 raw_opts. push ( cuda:: CUjit_option :: CU_JIT_TARGET ) ;
112- raw_vals. push ( target as * const JitTarget as * mut _ ) ;
122+ raw_vals. push ( * target as usize as * mut c_void ) ;
113123 }
114124 Self :: Fallback ( fallback) => {
115125 raw_opts. push ( cuda:: CUjit_option :: CU_JIT_FALLBACK_STRATEGY ) ;
116- raw_vals. push ( fallback as * const JitFallback as * mut _ ) ;
126+ raw_vals. push ( * fallback as usize as * mut c_void ) ;
117127 }
118128 Self :: GenenerateDebugInfo ( gen) => {
119129 raw_opts. push ( cuda:: CUjit_option :: CU_JIT_GENERATE_DEBUG_INFO ) ;
120- raw_vals. push ( gen as * const bool as * mut _ ) ;
130+ raw_vals. push ( * gen as usize as * mut c_void ) ;
121131 }
122132 Self :: GenerateLineInfo ( gen) => {
123133 raw_opts. push ( cuda:: CUjit_option :: CU_JIT_GENERATE_LINE_INFO ) ;
124- raw_vals. push ( gen as * const bool as * mut _ )
134+ raw_vals. push ( * gen as usize as * mut c_void )
125135 }
126136 }
127137 }
0 commit comments