@@ -212,17 +212,16 @@ static int compare_path(const void *a, const void *b)
212212}
213213
214214static inline unsigned int _load_icd (int num_icds , const char * lib_path ) {
215- unsigned int ret = 0 ;
216215 debug (D_LOG , "Loading ICD '%s'" , lib_path );
217216
218217 _icds [num_icds ].dl_handle = dlopen (lib_path , RTLD_LAZY |RTLD_LOCAL );//|RTLD_DEEPBIND);
219218 if (_icds [num_icds ].dl_handle != NULL ) {
220219 debug (D_LOG , "ICD[%i] loaded" , num_icds );
221- ret = 1 ;
220+ num_icds += 1 ;
222221 } else {
223222 debug (D_WARN , "error while dlopening the IDL: '%s',\n => skipping ICD" , dlerror ());
224223 }
225- return ret ;
224+ return num_icds ;
226225}
227226
228227static inline unsigned int _open_driver (unsigned int num_icds ,
@@ -268,14 +267,13 @@ static inline unsigned int _open_driver(unsigned int num_icds,
268267 if ( lib_path [lib_path_length - 1 ] == '\n' )
269268 lib_path [lib_path_length - 1 ] = '\0' ;
270269
271- num_icds + = _load_icd (num_icds , lib_path );
270+ num_icds = _load_icd (num_icds , lib_path );
272271
273272 free (lib_path );
274273 RETURN (num_icds );
275274}
276275
277- static inline unsigned int _open_drivers (DIR * dir , const char * dir_path ) {
278- unsigned int num_icds = 0 ;
276+ static inline unsigned int _open_drivers (unsigned int num_icds , DIR * dir , const char * dir_path ) {
279277 struct dirent * ent ;
280278 while ( (ent = readdir (dir )) != NULL ){
281279 if (! _string_end_with_icd (ent -> d_name )) {
@@ -852,6 +850,22 @@ static void __initClIcd( void ) {
852850 DIR * dir = NULL ;
853851 const char * dir_path = getenv ("OCL_ICD_VENDORS" );
854852 const char * vendor_path = getenv ("OPENCL_VENDOR_PATH" );
853+ char * icd_filenames = getenv ("OCL_ICD_FILENAMES" );
854+
855+ if (icd_filenames ) {
856+ debug (D_DUMP , "OCL_ICD_FILENAMES set to '%s', using it" , icd_filenames );
857+ if (* icd_filenames ) {
858+ num_icds ++ ;
859+ char * next_icd_filenames = strchr (icd_filenames , ':' );
860+ while (next_icd_filenames ) {
861+ next_icd_filenames ++ ;
862+ num_icds ++ ;
863+ next_icd_filenames = strchr (next_icd_filenames , ':' );
864+ }
865+ }
866+ debug (D_LOG , "found %ld potential ICDs in OCL_ICD_FILENAMES" , (long )num_icds );
867+ }
868+
855869 if (! vendor_path || vendor_path [0 ]== 0 ) {
856870 vendor_path = ETC_OPENCL_VENDORS ;
857871 debug (D_DUMP , "OPENCL_VENDOR_PATH unset or empty. Using hard-coded path '%s'" , vendor_path );
@@ -876,7 +890,7 @@ static void __initClIcd( void ) {
876890
877891 if (!is_dir ) {
878892 debug (D_LOG ,"Only loading '%s' as an ICD" , dir_path );
879- num_icds = 1 ;
893+ num_icds + = 1 ;
880894 dir = NULL ;
881895 } else {
882896 debug (D_LOG ,"Reading icd list from '%s'" , dir_path );
@@ -889,7 +903,7 @@ static void __initClIcd( void ) {
889903 goto abort ;
890904 }
891905
892- num_icds = _find_num_icds (dir );
906+ num_icds + = _find_num_icds (dir );
893907 if (num_icds == 0 ) {
894908 goto abort ;
895909 }
@@ -900,20 +914,36 @@ static void __initClIcd( void ) {
900914 goto abort ;
901915 }
902916
917+ num_icds = 0 ;
918+
919+ if (icd_filenames ) {
920+ char * icd_filename = icd_filenames ;
921+ char * next_icd_filename = strchr (icd_filenames , ':' );
922+ while (icd_filename ) {
923+ if (next_icd_filename )
924+ * next_icd_filename ++ = '\0' ;
925+ num_icds = _load_icd (num_icds , icd_filename );
926+ icd_filename = next_icd_filename ;
927+ if (next_icd_filename )
928+ next_icd_filename = strchr (next_icd_filename , ':' );
929+ }
930+ }
931+
903932 if (!is_dir ) {
904933 if (_string_end_with_icd (dir_path )) {
905- num_icds = 0 ;
934+ cl_uint n_icds = 0 ;
906935 if (! _string_with_slash (dir_path )) {
907- num_icds = _open_driver (0 , vendor_path , dir_path );
936+ n_icds = _open_driver (num_icds , vendor_path , dir_path );
908937 }
909- if (num_icds == 0 ) {
910- num_icds = _open_driver (0 , NULL , dir_path );
938+ if (n_icds == num_icds ) {
939+ n_icds = _open_driver (num_icds , NULL , dir_path );
911940 }
941+ num_icds = n_icds ;
912942 } else {
913- num_icds = _load_icd (0 , dir_path );
943+ num_icds = _load_icd (num_icds , dir_path );
914944 }
915945 } else {
916- num_icds = _open_drivers (dir , dir_path );
946+ num_icds = _open_drivers (num_icds , dir , dir_path );
917947 }
918948 if (num_icds == 0 ) {
919949 goto abort ;
0 commit comments