5151// from heavy.cu
5252#ifdef __cplusplus
5353extern "C"
54+ {
5455#endif
5556int cuda_num_devices ();
57+ int cuda_finddevice (char * name );
58+ #ifdef __cplusplus
59+ }
60+ #endif
5661
5762
5863#ifdef __linux /* Linux specific policy and affinity management */
@@ -144,10 +149,11 @@ static int opt_scantime = 5;
144149static json_t * opt_config ;
145150static const bool opt_time = true;
146151static sha256_algos opt_algo = ALGO_HEAVY ;
147- static int opt_n_threads ;
152+ static int opt_n_threads = 0 ;
148153bool opt_trust_pool = false;
149154uint16_t opt_vote = 9999 ;
150155static int num_processors ;
156+ int device_map [8 ] = {0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 }; // CB
151157static char * rpc_url ;
152158static char * rpc_userpass ;
153159static char * rpc_user , * rpc_pass ;
@@ -185,7 +191,11 @@ Options:\n\
185191 - a , -- algo = ALGO specify the algorithm to use \n \
186192 fugue256 Fuguecoin hash \n \
187193 heavy Heavycoin hash \n \
188- - v , -- vote = VOTE block reward vote \n \
194+ - d , -- devices takes a comma separated list of CUDA devices to use .\n \
195+ Device IDs start counting from 0 ! Alternatively takes \n \
196+ string names of your cards like gtx780ti or gt640 #2 \n\
197+ (matching 2nd gt640 in the PC)\n\
198+ -v, --vote=VOTE block reward vote (for HeavyCoin)\n\
189199 -m, --trust-pool trust the max block reward vote (maxvote) sent by the pool\n\
190200 -o, --url=URL URL of mining server\n\
191201 -O, --userpass=U:P username:password pair for mining server\n\
@@ -227,7 +237,7 @@ static char const short_options[] =
227237#ifdef HAVE_SYSLOG_H
228238 "S"
229239#endif
230- "a:c:Dhp:Px:qr:R:s:t:T:o:u:O:Vmv :" ;
240+ "a:c:Dhp:Px:qr:R:s:t:T:o:u:O:Vd:mv :" ;
231241
232242static struct option const options [] = {
233243 { "algo" , 1 , NULL , 'a' },
@@ -259,6 +269,7 @@ static struct option const options[] = {
259269 { "user" , 1 , NULL , 'u' },
260270 { "userpass" , 1 , NULL , 'O' },
261271 { "version" , 0 , NULL , 'V' },
272+ { "devices" , 1 , NULL , 'd' },
262273 { 0 , 0 , 0 , 0 }
263274};
264275
@@ -1251,6 +1262,32 @@ static void parse_arg (int key, char *arg)
12511262 case 'S ':
12521263 use_syslog = true;
12531264 break ;
1265+ case 'd ': // CB
1266+ {
1267+ char * pch = strtok (arg ,",");
1268+ opt_n_threads = 0 ;
1269+ while (pch != NULL ) {
1270+ if (pch [0 ] >= '0' && pch [0 ] <= '9' && pch [1 ] == '\0' )
1271+ {
1272+ if (atoi (pch ) < num_processors )
1273+ device_map [opt_n_threads ++ ] = atoi (pch );
1274+ else {
1275+ applog (LOG_ERR , "Non-existant CUDA device #%d specified in -d option" , atoi (pch ));
1276+ exit (1 );
1277+ }
1278+ } else {
1279+ int device = cuda_finddevice (pch );
1280+ if (device >= 0 && device < num_processors )
1281+ device_map [opt_n_threads ++ ] = device ;
1282+ else {
1283+ applog (LOG_ERR , "Non-existant CUDA device '%s' specified in -d option" , pch );
1284+ exit (1 );
1285+ }
1286+ }
1287+ pch = strtok (NULL , "," );
1288+ }
1289+ }
1290+ break ;
12541291 case 'V' :
12551292 show_version_and_exit ();
12561293 case 'h' :
@@ -1346,7 +1383,7 @@ static void signal_handler(int sig)
13461383}
13471384#endif
13481385
1349- #define PROGRAM_VERSION "0.4 "
1386+ #define PROGRAM_VERSION "0.5 "
13501387int main (int argc , char * argv [])
13511388{
13521389 struct thr_info * thr ;
@@ -1370,6 +1407,9 @@ int main(int argc, char *argv[])
13701407 rpc_user = strdup ("" );
13711408 rpc_pass = strdup ("" );
13721409
1410+ pthread_mutex_init (& applog_lock , NULL );
1411+ num_processors = cuda_num_devices ();
1412+
13731413 /* parse command line */
13741414 parse_cmdline (argc , argv );
13751415
@@ -1385,7 +1425,6 @@ int main(int argc, char *argv[])
13851425 sprintf (rpc_userpass , "%s:%s" , rpc_user , rpc_pass );
13861426 }
13871427
1388- pthread_mutex_init (& applog_lock , NULL );
13891428 pthread_mutex_init (& stats_lock , NULL );
13901429 pthread_mutex_init (& g_work_lock , NULL );
13911430 pthread_mutex_init (& stratum .sock_lock , NULL );
@@ -1416,7 +1455,6 @@ int main(int argc, char *argv[])
14161455 }
14171456#endif
14181457
1419- num_processors = cuda_num_devices ();
14201458 if (num_processors == 0 )
14211459 {
14221460 applog (LOG_ERR , "No CUDA devices found! terminating." );
0 commit comments