@@ -487,28 +487,40 @@ static int call_eaccess(const char *pathname, int mode) {
487
487
return result ;
488
488
}
489
489
490
- int eaccess (const char * pathname , int mode ) {
491
- int ret = call_eaccess (pathname , mode );
492
- if (ret == 0 ) {
493
- return 0 ;
494
- }
490
+ int is_nvcc_available (void ) {
491
+ char * compiler = getenv ("INTERCEPT_COMPILE_PATH" );
492
+ char * is_compiler_exported =
493
+ getenv ("IS_INTERCEPT_COMPILE_PATH_FROM_ENV_PATH" );
495
494
496
- int nvcc_available = 0 ;
497
- char * value = getenv ("INTERCEPT_COMPILE_PATH" );
498
- if (value ) {
499
- nvcc_available = 1 ;
495
+ // Consider tool chain is avaialbe only when it is available from env path.
496
+ if (is_compiler_exported && * is_compiler_exported == '1' && compiler ) {
497
+ return 1 ;
500
498
}
499
+ return 0 ;
500
+ }
501
501
502
+ int is_nvcc_cmd (const char * pathname ) {
502
503
int len = strlen (pathname );
503
- if (! nvcc_available && len == 4 && pathname [3 ] == 'c' && pathname [2 ] == 'c' &&
504
+ if (len == 4 && pathname [3 ] == 'c' && pathname [2 ] == 'c' &&
504
505
pathname [1 ] == 'v' && pathname [0 ] == 'n' ) {
505
506
// To handle case like "nvcc foo.cu ..."
506
- return 0 ;
507
+ return 1 ;
507
508
}
508
- if (! nvcc_available && len > 4 && pathname [len - 1 ] == 'c' &&
509
- pathname [len - 2 ] == 'c ' && pathname [len - 3 ] == 'v ' &&
510
- pathname [len - 4 ] == 'n' && pathname [ len - 5 ] == '/' ) {
509
+ if (len > 4 && pathname [ len - 1 ] == 'c' && pathname [len - 2 ] == 'c' &&
510
+ pathname [len - 3 ] == 'v ' && pathname [len - 4 ] == 'n ' &&
511
+ pathname [len - 5 ] == '/' ) {
511
512
// To handle case like "/path/to/nvcc foo.cu ..."
513
+ return 1 ;
514
+ }
515
+ return 0 ;
516
+ }
517
+
518
+ int eaccess (const char * pathname , int mode ) {
519
+ int ret = call_eaccess (pathname , mode );
520
+ if (ret == 0 ) {
521
+ return 0 ;
522
+ }
523
+ if (!is_nvcc_available () && is_nvcc_cmd (pathname )) {
512
524
return 0 ;
513
525
}
514
526
return ret ;
@@ -538,35 +550,8 @@ int stat(const char *pathname, struct stat *statbuf) {
538
550
if (ret == 0 ) {
539
551
return 0 ;
540
552
}
541
- int len = strlen (pathname );
542
- if (len == 4 && pathname [3 ] == 'c' && pathname [2 ] == 'c' &&
543
- pathname [1 ] == 'v' && pathname [0 ] == 'n' ) {
544
- // To handle case like "nvcc foo.cu ..."
545
-
546
- const char * nvcc_path = getenv ("INTERCEPT_COMPILE_PATH" );
547
- if (nvcc_path ) {
548
- call_stat (nvcc_path , statbuf );
549
- return 0 ;
550
- }
551
-
552
- pathname = get_intercept_stub_path ();
553
- call_stat (pathname , statbuf );
554
- return 0 ;
555
- }
556
553
557
- if (len > 4 && pathname [len - 1 ] == 'c' && pathname [len - 2 ] == 'c' &&
558
- pathname [len - 3 ] == 'v' && pathname [len - 4 ] == 'n' &&
559
- pathname [len - 5 ] == '/' ) {
560
- // To handle case like "/path/to/nvcc foo.cu ..."
561
-
562
- const char * nvcc_path = getenv ("INTERCEPT_COMPILE_PATH" );
563
- if (nvcc_path ) {
564
- call_stat (nvcc_path , statbuf );
565
- return 0 ;
566
- }
567
-
568
- pathname = get_intercept_stub_path ();
569
- call_stat (pathname , statbuf );
554
+ if (!is_nvcc_available () && is_nvcc_cmd (pathname )) {
570
555
return 0 ;
571
556
}
572
557
return ret ;
@@ -1724,33 +1709,10 @@ char *replace_binary_name(const char *src, const char *pos, int compiler_idx,
1724
1709
int is_tool_available (char const * argv [], size_t const argc ) {
1725
1710
const char * pathname = argv [0 ];
1726
1711
int len = strlen (pathname );
1727
- int is_nvcc = 0 ;
1728
- int is_nvcc_available = 0 ;
1729
-
1730
- char * value = getenv ("INTERCEPT_COMPILE_PATH" );
1731
- if (value ) {
1732
- is_nvcc_available = 1 ;
1733
- }
1734
1712
1735
- if (len == 4 && pathname [3 ] == 'c' && pathname [2 ] == 'c' &&
1736
- pathname [1 ] == 'v' && pathname [0 ] == 'n' ) {
1737
- // To handle case like "nvcc"
1738
- is_nvcc = 1 ;
1739
- value = getenv ("IS_INTERCEPT_COMPILE_PATH_FROM_ENV_PATH" );
1740
- if (value && * value == '0' ) {
1741
- return 0 ;
1742
- }
1743
- }
1744
- if (len > 4 && pathname [len - 1 ] == 'c' && pathname [len - 2 ] == 'c' &&
1745
- pathname [len - 3 ] == 'v' && pathname [len - 4 ] == 'n' &&
1746
- pathname [len - 5 ] == '/' ) {
1747
- // To handle case like "/path/to/nvcc"
1748
- is_nvcc = 1 ;
1749
- }
1750
- if (is_nvcc ) {
1751
- if (is_nvcc_available ) {
1713
+ if (is_nvcc_cmd (pathname )) {
1714
+ if (is_nvcc_available ())
1752
1715
return 1 ;
1753
- }
1754
1716
return 0 ;
1755
1717
}
1756
1718
@@ -1765,7 +1727,7 @@ int is_tool_available(char const *argv[], size_t const argc) {
1765
1727
is_ld = 1 ;
1766
1728
}
1767
1729
if (is_ld ) {
1768
- if (!is_nvcc_available ) {
1730
+ if (!is_nvcc_available () ) {
1769
1731
for (size_t idx = 0 ; idx < argc ; idx ++ ) {
1770
1732
// if ld linker command uses cuda libarary like libcuda.so or
1771
1733
// libcudart.so, then the ld command should be intercepted.
@@ -1776,12 +1738,12 @@ int is_tool_available(char const *argv[], size_t const argc) {
1776
1738
}
1777
1739
}
1778
1740
1779
- if (!is_nvcc_available && argc == 3 ) {
1741
+ if (!is_nvcc_available () && argc == 3 ) {
1780
1742
// To handle case like "/bin/[sh/bash] -c '[echo or something]
1781
1743
// [/path/to/]nvcc -c foo.cu -o foo.o'" on the environment where tool chain
1782
1744
// is not available.
1783
1745
int is_bash = 0 ;
1784
- is_nvcc = 0 ;
1746
+ int is_nvcc_cmd = 0 ;
1785
1747
const char * pathname = argv [0 ];
1786
1748
len = strlen (pathname );
1787
1749
@@ -1805,7 +1767,7 @@ int is_tool_available(char const *argv[], size_t const argc) {
1805
1767
}
1806
1768
1807
1769
if (pos ) {
1808
- is_nvcc =
1770
+ is_nvcc_cmd =
1809
1771
pos > argv [2 ]
1810
1772
? strlen (pos ) >= 4 && isspace (* (pos + 4 )) &&
1811
1773
(* (pos - 1 ) == '/' || * (pos - 1 ) == ';' ||
@@ -1816,7 +1778,7 @@ int is_tool_available(char const *argv[], size_t const argc) {
1816
1778
// sure it is a compiler command.
1817
1779
}
1818
1780
1819
- if (is_bash && strcmp (argv [1 ], "-c" ) == 0 && is_nvcc ) {
1781
+ if (is_bash && strcmp (argv [1 ], "-c" ) == 0 && is_nvcc_cmd ) {
1820
1782
return 0 ;
1821
1783
}
1822
1784
}
0 commit comments