@@ -92,36 +92,46 @@ pub enum ModuleJitOption {
92
92
93
93
impl ModuleJitOption {
94
94
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)
95
104
let mut raw_opts = Vec :: with_capacity ( opts. len ( ) ) ;
96
105
let mut raw_vals = Vec :: with_capacity ( opts. len ( ) ) ;
106
+
97
107
for opt in opts {
98
108
match opt {
99
109
Self :: MaxRegisters ( regs) => {
100
110
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 ) ;
102
112
}
103
113
Self :: OptLevel ( level) => {
104
114
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 ) ;
106
116
}
107
117
Self :: DetermineTargetFromContext => {
108
118
raw_opts. push ( cuda:: CUjit_option :: CU_JIT_TARGET_FROM_CUCONTEXT ) ;
109
119
}
110
120
Self :: Target ( target) => {
111
121
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 ) ;
113
123
}
114
124
Self :: Fallback ( fallback) => {
115
125
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 ) ;
117
127
}
118
128
Self :: GenenerateDebugInfo ( gen) => {
119
129
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 ) ;
121
131
}
122
132
Self :: GenerateLineInfo ( gen) => {
123
133
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 )
125
135
}
126
136
}
127
137
}
0 commit comments