@@ -984,6 +984,22 @@ static gpukernel *cuda_newkernel(gpucontext *c, unsigned int count,
984984 CUdevice dev ;
985985 unsigned int i ;
986986 int major , minor ;
987+ strb debug_msg = STRB_STATIC_INIT ;
988+
989+ // options for cuModuleLoadDataEx
990+ const size_t cujit_log_size = 4096 ;
991+ char * cujit_info_log = NULL ;
992+ unsigned int num_cujit_opts = 4 ;
993+ CUjit_option cujit_opts [] = {
994+ CU_JIT_INFO_LOG_BUFFER_SIZE_BYTES ,
995+ CU_JIT_INFO_LOG_BUFFER ,
996+ CU_JIT_ERROR_LOG_BUFFER_SIZE_BYTES ,
997+ CU_JIT_ERROR_LOG_BUFFER
998+ };
999+ void * cujit_opt_vals [] = {
1000+ (void * )(size_t )cujit_log_size , NULL ,
1001+ (void * )(size_t )cujit_log_size , NULL ,
1002+ };
9871003
9881004 if (count == 0 ) FAIL (NULL , GA_VALUE_ERROR );
9891005
@@ -1069,10 +1085,9 @@ static gpukernel *cuda_newkernel(gpucontext *c, unsigned int count,
10691085 & log , & log_len , ret );
10701086 if (bin == NULL ) {
10711087 if (err_str != NULL ) {
1072- strb debug_msg = STRB_STATIC_INIT ;
10731088
10741089 // We're substituting debug_msg for a string with this first line:
1075- strb_appends (& debug_msg , "CUDA kernel build failure ::\n" );
1090+ strb_appends (& debug_msg , "CUDA kernel compile failure ::\n" );
10761091
10771092 /* Delete the final NUL */
10781093 sb .l -- ;
@@ -1089,7 +1104,7 @@ static gpukernel *cuda_newkernel(gpucontext *c, unsigned int count,
10891104 }
10901105 strb_clear (& sb );
10911106 cuda_exit (ctx );
1092- return NULL ;
1107+ FAIL ( NULL , GA_IMPL_ERROR ) ;
10931108 }
10941109 }
10951110
@@ -1122,15 +1137,46 @@ static gpukernel *cuda_newkernel(gpucontext *c, unsigned int count,
11221137 FAIL (NULL , GA_MEMORY_ERROR );
11231138 }
11241139
1125- ctx -> err = cuModuleLoadData (& res -> m , bin );
1140+ // for both info/err log
1141+ cujit_info_log = (char * )malloc (2 * cujit_log_size * sizeof (char ));
1142+ if (cujit_info_log == NULL ) {
1143+ _cuda_freekernel (res );
1144+ strb_clear (& sb );
1145+ cuda_exit (ctx );
1146+ FAIL (NULL , GA_MEMORY_ERROR );
1147+ }
1148+ cujit_info_log [0 ] = 0 ;
1149+ cujit_info_log [cujit_log_size ] = 0 ;
1150+ cujit_opt_vals [1 ] = (void * )cujit_info_log ;
1151+ cujit_opt_vals [3 ] = (void * )(cujit_info_log + cujit_log_size );
1152+
1153+ ctx -> err = cuModuleLoadDataEx (
1154+ & res -> m , bin ,
1155+ num_cujit_opts , cujit_opts , (void * * )cujit_opt_vals );
11261156
11271157 if (ctx -> err != CUDA_SUCCESS ) {
1158+ if (err_str != NULL ) {
1159+ strb_appends (& debug_msg , "CUDA kernel link failure::\n" );
1160+ if (cujit_info_log [0 ]) {
1161+ strb_appends (& debug_msg , "\nLinker msg:\n" );
1162+ strb_appends (& debug_msg , cujit_info_log );
1163+ }
1164+ if (cujit_info_log [cujit_log_size ]) {
1165+ strb_appends (& debug_msg , "\nLinker error log:\n" );
1166+ strb_appends (& debug_msg , cujit_info_log + cujit_log_size );
1167+ }
1168+ strb_append0 (& debug_msg );
1169+ * err_str = strb_cstr (& debug_msg );
1170+ }
1171+ free (cujit_info_log );
11281172 _cuda_freekernel (res );
11291173 strb_clear (& sb );
11301174 cuda_exit (ctx );
11311175 FAIL (NULL , GA_IMPL_ERROR );
11321176 }
11331177
1178+ free (cujit_info_log );
1179+
11341180 ctx -> err = cuModuleGetFunction (& res -> k , res -> m , fname );
11351181 if (ctx -> err != CUDA_SUCCESS ) {
11361182 _cuda_freekernel (res );
@@ -1352,7 +1398,7 @@ static int cuda_property(gpucontext *c, gpudata *buf, gpukernel *k, int prop_id,
13521398 * ((char * * )res ) = s ;
13531399 cuda_exit (ctx );
13541400 return GA_NO_ERROR ;
1355-
1401+
13561402 case GA_CTX_PROP_PCIBUSID :
13571403 cuda_enter (ctx );
13581404 ctx -> err = cuCtxGetDevice (& id );
0 commit comments