2023-11-01 06:11:15 +08:00
#[=======================================================================[.rst:
F i n d C U D A
- - - - - - - -
. . d e p r e c a t e d : : 3 . 1 0
S u p e r s e d e d b y f i r s t - c l a s s s u p p o r t f o r t h e C U D A l a n g u a g e i n C M a k e .
2023-11-01 06:34:31 +08:00
S u p e r s e d e d b y t h e : m o d u l e : ` F i n d C U D A T o o l k i t ` f o r C U D A t o o l k i t l i b r a r i e s .
2023-11-01 06:11:15 +08:00
R e p l a c e m e n t
^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
2023-11-01 06:34:31 +08:00
I t i s n o l o n g e r n e c e s s a r y t o u s e t h i s m o d u l e o r c a l l ` ` find_package ( CUDA ) ` `
f o r c o m p i l i n g C U D A c o d e . I n s t e a d , l i s t ` ` C U D A ` ` a m o n g t h e l a n g u a g e s n a m e d
i n t h e t o p - l e v e l c a l l t o t h e : c o m m a n d : ` p r o j e c t ` c o m m a n d , o r c a l l t h e
2023-11-01 06:11:15 +08:00
: c o m m a n d : ` e n a b l e _ l a n g u a g e ` c o m m a n d w i t h ` ` C U D A ` ` .
T h e n o n e c a n a d d CUDA ( ``.cu`` ) s o u r c e s t o p r o g r a m s d i r e c t l y
i n c a l l s t o : c o m m a n d : ` a d d _ l i b r a r y ` a n d : c o m m a n d : ` a d d _ e x e c u t a b l e ` .
2023-11-01 06:34:31 +08:00
T o f i n d a n d u s e t h e C U D A t o o l k i t l i b r a r i e s t h e : m o d u l e : ` F i n d C U D A T o o l k i t `
m o d u l e h a s s u p e r s e d e d t h i s m o d u l e . I t w o r k s w h e t h e r o r n o t t h e ` ` C U D A ` `
l a n g u a g e i s e n a b l e d .
2023-11-01 06:11:15 +08:00
D o c u m e n t a t i o n o f D e p r e c a t e d U s a g e
^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
T o o l s f o r b u i l d i n g C U D A C f i l e s : l i b r a r i e s a n d b u i l d d e p e n d e n c i e s .
T h i s s c r i p t l o c a t e s t h e N V I D I A C U D A C t o o l s . I t s h o u l d w o r k o n L i n u x ,
W i n d o w s , a n d m a c O S a n d s h o u l d b e r e a s o n a b l y u p t o d a t e w i t h C U D A C
r e l e a s e s .
T h i s s c r i p t m a k e s u s e o f t h e s t a n d a r d : c o m m a n d : ` f i n d _ p a c k a g e ` a r g u m e n t s o f
` ` < V E R S I O N > ` ` , ` ` R E Q U I R E D ` ` a n d ` ` Q U I E T ` ` . ` ` C U D A _ F O U N D ` ` w i l l r e p o r t i f a n
a c c e p t a b l e v e r s i o n o f C U D A w a s f o u n d .
T h e s c r i p t w i l l p r o m p t t h e u s e r t o s p e c i f y ` ` C U D A _ T O O L K I T _ R O O T _ D I R ` ` i f
t h e p r e f i x c a n n o t b e d e t e r m i n e d b y t h e l o c a t i o n o f n v c c i n t h e s y s t e m
p a t h a n d ` ` R E Q U I R E D ` ` i s s p e c i f i e d t o : c o m m a n d : ` f i n d _ p a c k a g e ` . T o u s e
a d i f f e r e n t i n s t a l l e d v e r s i o n o f t h e t o o l k i t s e t t h e e n v i r o n m e n t v a r i a b l e
` ` C U D A _ B I N _ P A T H ` ` b e f o r e r u n n i n g cmake ( e.g.
` ` C U D A _ B I N _ P A T H = / u s r / l o c a l / c u d a 1 . 0 ` ` i n s t e a d o f t h e d e f a u l t
` ` / u s r / l o c a l / c u d a ` ` ) o r s e t ` ` C U D A _ T O O L K I T _ R O O T _ D I R ` ` a f t e r c o n f i g u r i n g . I f
y o u c h a n g e t h e v a l u e o f ` ` C U D A _ T O O L K I T _ R O O T _ D I R ` ` , v a r i o u s c o m p o n e n t s t h a t
d e p e n d o n t h e p a t h w i l l b e r e l o c a t e d .
I t m i g h t b e n e c e s s a r y t o s e t ` ` C U D A _ T O O L K I T _ R O O T _ D I R ` ` m a n u a l l y o n c e r t a i n
p l a t f o r m s , o r t o u s e a C U D A r u n t i m e n o t i n s t a l l e d i n t h e d e f a u l t
l o c a t i o n . I n n e w e r v e r s i o n s o f t h e t o o l k i t t h e C U D A l i b r a r y i s
i n c l u d e d w i t h t h e g r a p h i c s d r i v e r - - b e s u r e t h a t t h e d r i v e r v e r s i o n
m a t c h e s w h a t i s n e e d e d b y t h e C U D A r u n t i m e v e r s i o n .
T h e f o l l o w i n g v a r i a b l e s a f f e c t t h e b e h a v i o r o f t h e m a c r o s i n t h e
script ( in alphabetical order ) . N o t e t h a t a n y o f t h e s e f l a g s c a n b e
c h a n g e d m u l t i p l e t i m e s i n t h e s a m e d i r e c t o r y b e f o r e c a l l i n g
` ` C U D A _ A D D _ E X E C U T A B L E ` ` , ` ` C U D A _ A D D _ L I B R A R Y ` ` , ` ` C U D A _ C O M P I L E ` ` ,
` ` C U D A _ C O M P I L E _ P T X ` ` , ` ` C U D A _ C O M P I L E _ F A T B I N ` ` , ` ` C U D A _ C O M P I L E _ C U B I N ` `
o r ` ` C U D A _ W R A P _ S R C S ` ` : :
CUDA_64_BIT_DEVICE_CODE ( Default matches host bit size )
- - S e t t o O N t o c o m p i l e f o r 6 4 b i t d e v i c e c o d e , O F F f o r 3 2 b i t d e v i c e c o d e .
N o t e t h a t m a k i n g t h i s d i f f e r e n t f r o m t h e h o s t c o d e w h e n g e n e r a t i n g o b j e c t
o r C f i l e s f r o m C U D A c o d e j u s t w o n ' t w o r k , b e c a u s e s i z e _ t g e t s d e f i n e d b y
n v c c i n t h e g e n e r a t e d s o u r c e . I f y o u c o m p i l e t o P T X a n d t h e n l o a d t h e
f i l e y o u r s e l f , y o u c a n m i x b i t s i z e s b e t w e e n d e v i c e a n d h o s t .
CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE ( Default ON )
- - S e t t o O N i f y o u w a n t t h e c u s t o m b u i l d r u l e t o b e a t t a c h e d t o t h e s o u r c e
f i l e i n V i s u a l S t u d i o . T u r n O F F i f y o u a d d t h e s a m e c u d a f i l e t o m u l t i p l e
t a r g e t s .
T h i s a l l o w s t h e u s e r t o b u i l d t h e t a r g e t f r o m t h e C U D A f i l e ; h o w e v e r , b a d
t h i n g s c a n h a p p e n i f t h e C U D A s o u r c e f i l e i s a d d e d t o m u l t i p l e t a r g e t s .
W h e n p e r f o r m i n g p a r a l l e l b u i l d s i t i s p o s s i b l e f o r t h e c u s t o m b u i l d
c o m m a n d t o b e r u n m o r e t h a n o n c e a n d i n p a r a l l e l c a u s i n g c r y p t i c b u i l d
e r r o r s . V S r u n s t h e r u l e s f o r e v e r y s o u r c e f i l e i n t h e t a r g e t , a n d a
s o u r c e c a n h a v e o n l y o n e r u l e n o m a t t e r h o w m a n y p r o j e c t s i t i s a d d e d t o .
W h e n t h e r u l e i s r u n f r o m m u l t i p l e t a r g e t s r a c e c o n d i t i o n s c a n o c c u r o n
t h e g e n e r a t e d f i l e . E v e n t u a l l y e v e r y t h i n g w i l l g e t b u i l t , b u t i f t h e u s e r
i s u n a w a r e o f t h i s b e h a v i o r , t h e r e m a y b e c o n f u s i o n . I t w o u l d b e n i c e i f
t h i s s c r i p t c o u l d d e t e c t t h e r e u s e o f s o u r c e f i l e s a c r o s s m u l t i p l e t a r g e t s
a n d t u r n t h e o p t i o n o f f f o r t h e u s e r , b u t n o g o o d s o l u t i o n c o u l d b e f o u n d .
CUDA_BUILD_CUBIN ( Default OFF )
- - S e t t o O N t o e n a b l e a n d e x t r a c o m p i l a t i o n p a s s w i t h t h e - c u b i n o p t i o n i n
D e v i c e m o d e . T h e o u t p u t i s p a r s e d a n d r e g i s t e r , s h a r e d m e m o r y u s a g e i s
p r i n t e d d u r i n g b u i l d .
CUDA_BUILD_EMULATION ( Default OFF for device mode )
- - S e t t o O N f o r E m u l a t i o n m o d e . - D _ D E V I C E E M U i s d e f i n e d f o r C U D A C f i l e s
w h e n C U D A _ B U I L D _ E M U L A T I O N i s T R U E .
CUDA_LINK_LIBRARIES_KEYWORD ( Default "" )
- - T h e < P R I V A T E | P U B L I C | I N T E R F A C E > k e y w o r d t o u s e f o r i n t e r n a l
t a r g e t _ l i n k _ l i b r a r i e s c a l l s . T h e d e f a u l t i s t o u s e n o k e y w o r d w h i c h
u s e s t h e o l d " p l a i n " f o r m o f t a r g e t _ l i n k _ l i b r a r i e s . N o t e t h a t i s m a t t e r s
b e c a u s e w h a t e v e r i s u s e d i n s i d e t h e F i n d C U D A m o d u l e m u s t a l s o b e u s e d
o u t s i d e - t h e t w o f o r m s o f t a r g e t _ l i n k _ l i b r a r i e s c a n n o t b e m i x e d .
CUDA_GENERATED_OUTPUT_DIR ( Default CMAKE_CURRENT_BINARY_DIR )
- - S e t t o t h e p a t h y o u w i s h t o h a v e t h e g e n e r a t e d f i l e s p l a c e d . I f i t i s
b l a n k o u t p u t f i l e s w i l l b e p l a c e d i n C M A K E _ C U R R E N T _ B I N A R Y _ D I R .
I n t e r m e d i a t e f i l e s w i l l a l w a y s b e p l a c e d i n
C M A K E _ C U R R E N T _ B I N A R Y _ D I R / C M a k e F i l e s .
CUDA_HOST_COMPILATION_CPP ( Default ON )
- - S e t t o O F F f o r C c o m p i l a t i o n o f h o s t c o d e .
CUDA_HOST_COMPILER ( Default CMAKE_C_COMPILER )
- - S e t t h e h o s t c o m p i l e r t o b e u s e d b y n v c c . I g n o r e d i f - c c b i n o r
- - c o m p i l e r - b i n d i r i s a l r e a d y p r e s e n t i n t h e C U D A _ N V C C _ F L A G S o r
C U D A _ N V C C _ F L A G S _ < C O N F I G > v a r i a b l e s . F o r V i s u a l S t u d i o t a r g e t s ,
t h e h o s t c o m p i l e r i s c o n s t r u c t e d w i t h o n e o r m o r e v i s u a l s t u d i o m a c r o s
s u c h a s $ ( V C I n s t a l l D i r ) , t h a t e x p a n d s o u t t o t h e p a t h w h e n
t h e c o m m a n d i s r u n f r o m w i t h i n V S .
I f t h e C U D A H O S T C X X e n v i r o n m e n t v a r i a b l e i s s e t i t w i l l
b e u s e d a s t h e d e f a u l t .
C U D A _ N V C C _ F L A G S
C U D A _ N V C C _ F L A G S _ < C O N F I G >
- - A d d i t i o n a l N V C C c o m m a n d l i n e a r g u m e n t s . N O T E : m u l t i p l e a r g u m e n t s m u s t b e
s e m i - c o l o n delimited ( e.g. --compiler-options;-Wall )
CUDA_PROPAGATE_HOST_FLAGS ( Default ON )
- - S e t t o O N t o p r o p a g a t e C M A K E _ { C , C X X } _ F L A G S a n d t h e i r c o n f i g u r a t i o n
d e p e n d e n t counterparts ( e.g. CMAKE_C_FLAGS_DEBUG ) a u t o m a t i c a l l y t o t h e
h o s t c o m p i l e r t h r o u g h n v c c ' s - X c o m p i l e r f l a g . T h i s h e l p s m a k e t h e
g e n e r a t e d h o s t c o d e m a t c h t h e r e s t o f t h e s y s t e m b e t t e r . S o m e t i m e s
c e r t a i n f l a g s g i v e n v c c p r o b l e m s , a n d t h i s w i l l h e l p y o u t u r n t h e f l a g
p r o p a g a t i o n o f f . T h i s d o e s n o t a f f e c t t h e f l a g s s u p p l i e d d i r e c t l y t o n v c c
v i a C U D A _ N V C C _ F L A G S o r t h r o u g h t h e O P T I O N f l a g s s p e c i f i e d t h r o u g h
C U D A _ A D D _ L I B R A R Y , C U D A _ A D D _ E X E C U T A B L E , o r C U D A _ W R A P _ S R C S . F l a g s u s e d f o r
s h a r e d l i b r a r y c o m p i l a t i o n a r e n o t a f f e c t e d b y t h i s f l a g .
CUDA_SEPARABLE_COMPILATION ( Default OFF )
- - I f s e t t h i s w i l l e n a b l e s e p a r a b l e c o m p i l a t i o n f o r a l l C U D A r u n t i m e o b j e c t
f i l e s . I f u s e d o u t s i d e o f C U D A _ A D D _ E X E C U T A B L E a n d C U D A _ A D D _ L I B R A R Y
( e . g . c a l l i n g C U D A _ W R A P _ S R C S d i r e c t l y ) ,
C U D A _ C O M P U T E _ S E P A R A B L E _ C O M P I L A T I O N _ O B J E C T _ F I L E _ N A M E a n d
C U D A _ L I N K _ S E P A R A B L E _ C O M P I L A T I O N _ O B J E C T S s h o u l d b e c a l l e d .
C U D A _ S O U R C E _ P R O P E R T Y _ F O R M A T
- - I f t h i s s o u r c e f i l e p r o p e r t y i s s e t , i t c a n o v e r r i d e t h e f o r m a t s p e c i f i e d
t o CUDA_WRAP_SRCS ( OBJ, PTX, CUBIN, or FATBIN ) . I f a n i n p u t s o u r c e f i l e
i s n o t a . c u f i l e , s e t t i n g t h i s f i l e w i l l c a u s e i t t o b e t r e a t e d a s a . c u
f i l e . S e e d o c u m e n t a t i o n f o r s e t _ s o u r c e _ f i l e s _ p r o p e r t i e s o n h o w t o s e t
t h i s p r o p e r t y .
CUDA_USE_STATIC_CUDA_RUNTIME ( Default ON )
- - W h e n e n a b l e d t h e s t a t i c v e r s i o n o f t h e C U D A r u n t i m e l i b r a r y w i l l b e u s e d
i n C U D A _ L I B R A R I E S . I f t h e v e r s i o n o f C U D A c o n f i g u r e d d o e s n ' t s u p p o r t
t h i s o p t i o n , t h e n i t w i l l b e s i l e n t l y d i s a b l e d .
CUDA_VERBOSE_BUILD ( Default OFF )
- - S e t t o O N t o s e e a l l t h e c o m m a n d s u s e d w h e n b u i l d i n g t h e C U D A f i l e . W h e n
u s i n g a M a k e f i l e g e n e r a t o r t h e v a l u e d e f a u l t s t o VERBOSE ( run make
V E R B O S E = 1 t o s e e o u t p u t ) , a l t h o u g h s e t t i n g C U D A _ V E R B O S E _ B U I L D t o O N w i l l
a l w a y s p r i n t t h e o u t p u t .
T h e s c r i p t c r e a t e s t h e f o l l o w i n g macros ( in alphabetical order ) : :
CUDA_ADD_CUFFT_TO_TARGET ( cuda_target )
- - A d d s t h e c u f f t l i b r a r y t o t h e target ( can be any target ) . H a n d l e s w h e t h e r
y o u a r e i n e m u l a t i o n m o d e o r n o t .
CUDA_ADD_CUBLAS_TO_TARGET ( cuda_target )
- - A d d s t h e c u b l a s l i b r a r y t o t h e target ( can be any target ) . H a n d l e s
w h e t h e r y o u a r e i n e m u l a t i o n m o d e o r n o t .
CUDA_ADD_EXECUTABLE ( cuda_target file0 file1 ...
[ WIN32 ] [ M A C O S X _ B U N D L E ] [ E X C L U D E _ F R O M _ A L L ] [ O P T I O N S . . . ] )
- - C r e a t e s a n e x e c u t a b l e " c u d a _ t a r g e t " w h i c h i s m a d e u p o f t h e f i l e s
s p e c i f i e d . A l l o f t h e n o n C U D A C f i l e s a r e c o m p i l e d u s i n g t h e s t a n d a r d
b u i l d r u l e s s p e c i f i e d b y C M A K E a n d t h e c u d a f i l e s a r e c o m p i l e d t o o b j e c t
f i l e s u s i n g n v c c a n d t h e h o s t c o m p i l e r . I n a d d i t i o n C U D A _ I N C L U D E _ D I R S i s
a d d e d a u t o m a t i c a l l y t o include_directories ( ) . S o m e s t a n d a r d C M a k e t a r g e t
c a l l s c a n b e u s e d o n t h e t a r g e t a f t e r c a l l i n g t h i s m a c r o
( e . g . s e t _ t a r g e t _ p r o p e r t i e s a n d t a r g e t _ l i n k _ l i b r a r i e s ) , b u t s e t t i n g
p r o p e r t i e s t h a t a d j u s t c o m p i l a t i o n f l a g s w i l l n o t a f f e c t c o d e c o m p i l e d b y
n v c c . S u c h f l a g s s h o u l d b e m o d i f i e d b e f o r e c a l l i n g C U D A _ A D D _ E X E C U T A B L E ,
C U D A _ A D D _ L I B R A R Y o r C U D A _ W R A P _ S R C S .
CUDA_ADD_LIBRARY ( cuda_target file0 file1 ...
[ S T A T I C | S H A R E D | M O D U L E ] [ E X C L U D E _ F R O M _ A L L ] [ O P T I O N S . . . ] )
- - S a m e a s C U D A _ A D D _ E X E C U T A B L E e x c e p t t h a t a l i b r a r y i s c r e a t e d .
CUDA_BUILD_CLEAN_TARGET ( )
- - C r e a t e s a c o n v e n i e n c e t a r g e t t h a t d e l e t e s a l l t h e d e p e n d e n c y f i l e s
g e n e r a t e d . Y o u s h o u l d m a k e c l e a n a f t e r r u n n i n g t h i s t a r g e t t o e n s u r e t h e
d e p e n d e n c y f i l e s g e t r e g e n e r a t e d .
CUDA_COMPILE ( generated_files file0 file1 ... [STATIC | SHARED | MODULE]
[ O P T I O N S . . . ] )
- - R e t u r n s a l i s t o f g e n e r a t e d f i l e s f r o m t h e i n p u t s o u r c e f i l e s t o b e u s e d
w i t h A D D _ L I B R A R Y o r A D D _ E X E C U T A B L E .
CUDA_COMPILE_PTX ( generated_files file0 file1 ... [OPTIONS ...] )
- - R e t u r n s a l i s t o f P T X f i l e s g e n e r a t e d f r o m t h e i n p u t s o u r c e f i l e s .
CUDA_COMPILE_FATBIN ( generated_files file0 file1 ... [OPTIONS ...] )
- - R e t u r n s a l i s t o f F A T B I N f i l e s g e n e r a t e d f r o m t h e i n p u t s o u r c e f i l e s .
CUDA_COMPILE_CUBIN ( generated_files file0 file1 ... [OPTIONS ...] )
- - R e t u r n s a l i s t o f C U B I N f i l e s g e n e r a t e d f r o m t h e i n p u t s o u r c e f i l e s .
CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME ( output_file_var
c u d a _ t a r g e t
o b j e c t _ f i l e s )
- - C o m p u t e t h e n a m e o f t h e i n t e r m e d i a t e l i n k f i l e u s e d f o r s e p a r a b l e
c o m p i l a t i o n . T h i s f i l e n a m e i s t y p i c a l l y p a s s e d i n t o
C U D A _ L I N K _ S E P A R A B L E _ C O M P I L A T I O N _ O B J E C T S . o u t p u t _ f i l e _ v a r i s p r o d u c e d
b a s e d o n c u d a _ t a r g e t t h e l i s t o f o b j e c t s f i l e s t h a t n e e d s e p a r a b l e
c o m p i l a t i o n a s s p e c i f i e d b y o b j e c t _ f i l e s . I f t h e o b j e c t _ f i l e s l i s t i s
e m p t y , t h e n o u t p u t _ f i l e _ v a r w i l l b e e m p t y . T h i s f u n c t i o n i s c a l l e d
a u t o m a t i c a l l y f o r C U D A _ A D D _ L I B R A R Y a n d C U D A _ A D D _ E X E C U T A B L E . N o t e t h a t
t h i s i s a f u n c t i o n a n d n o t a m a c r o .
CUDA_INCLUDE_DIRECTORIES ( path0 path1 ... )
- - S e t s t h e d i r e c t o r i e s t h a t s h o u l d b e p a s s e d t o n v c c
( e . g . n v c c - I p a t h 0 - I p a t h 1 . . . ) . T h e s e p a t h s u s u a l l y c o n t a i n o t h e r . c u
f i l e s .
CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS ( output_file_var cuda_target
n v c c _ f l a g s o b j e c t _ f i l e s )
- - G e n e r a t e s t h e l i n k o b j e c t r e q u i r e d b y s e p a r a b l e c o m p i l a t i o n f r o m t h e g i v e n
o b j e c t f i l e s . T h i s i s c a l l e d a u t o m a t i c a l l y f o r C U D A _ A D D _ E X E C U T A B L E a n d
C U D A _ A D D _ L I B R A R Y , b u t c a n b e c a l l e d m a n u a l l y w h e n u s i n g C U D A _ W R A P _ S R C S
d i r e c t l y . W h e n c a l l e d f r o m C U D A _ A D D _ L I B R A R Y o r C U D A _ A D D _ E X E C U T A B L E t h e
n v c c _ f l a g s p a s s e d i n a r e t h e s a m e a s t h e f l a g s p a s s e d i n v i a t h e O P T I O N S
a r g u m e n t . T h e o n l y n v c c f l a g a d d e d a u t o m a t i c a l l y i s t h e b i t n e s s f l a g a s
s p e c i f i e d b y C U D A _ 6 4 _ B I T _ D E V I C E _ C O D E . N o t e t h a t t h i s i s a f u n c t i o n
i n s t e a d o f a m a c r o .
CUDA_SELECT_NVCC_ARCH_FLAGS ( out_variable [target_CUDA_architectures] )
- - S e l e c t s G P U a r c h f l a g s f o r n v c c b a s e d o n t a r g e t _ C U D A _ a r c h i t e c t u r e s
t a r g e t _ C U D A _ a r c h i t e c t u r e s : A u t o | C o m m o n | A l l | LIST ( ARCH_AND_PTX ... )
- " A u t o " d e t e c t s l o c a l m a c h i n e G P U c o m p u t e a r c h a t r u n t i m e .
- " C o m m o n " a n d " A l l " c o v e r c o m m o n a n d e n t i r e s u b s e t s o f a r c h i t e c t u r e s
A R C H _ A N D _ P T X : N A M E | N U M . N U M | N U M . NUM ( NUM.NUM ) | N U M . N U M + P T X
N A M E : F e r m i K e p l e r M a x w e l l K e p l e r + T e g r a K e p l e r + T e s l a M a x w e l l + T e g r a P a s c a l
N U M : A n y n u m b e r . O n l y t h o s e p a i r s a r e c u r r e n t l y a c c e p t e d b y N V C C t h o u g h :
2 . 0 2 . 1 3 . 0 3 . 2 3 . 5 3 . 7 5 . 0 5 . 2 5 . 3 6 . 0 6 . 2
R e t u r n s L I S T o f f l a g s t o b e a d d e d t o C U D A _ N V C C _ F L A G S i n $ { o u t _ v a r i a b l e }
A d d i t i o n a l l y , s e t s $ { o u t _ v a r i a b l e } _ r e a d a b l e t o t h e r e s u l t i n g n u m e r i c l i s t
E x a m p l e :
CUDA_SELECT_NVCC_ARCH_FLAGS ( ARCH_FLAGS 3.0 3.5+PTX 5.2(5.0 ) M a x w e l l )
LIST ( APPEND CUDA_NVCC_FLAGS ${ ARCH_FLAGS } )
M o r e i n f o o n C U D A a r c h i t e c t u r e s : h t t p s : / / e n . w i k i p e d i a . o r g / w i k i / C U D A
N o t e t h a t t h i s i s a f u n c t i o n i n s t e a d o f a m a c r o .
CUDA_WRAP_SRCS ( cuda_target format generated_files file0 file1 ...
[ S T A T I C | S H A R E D | M O D U L E ] [ O P T I O N S . . . ] )
- - T h i s i s w h e r e a l l t h e m a g i c h a p p e n s . C U D A _ A D D _ E X E C U T A B L E ,
C U D A _ A D D _ L I B R A R Y , C U D A _ C O M P I L E , a n d C U D A _ C O M P I L E _ P T X a l l c a l l t h i s
f u n c t i o n u n d e r t h e h o o d .
G i v e n t h e l i s t o f files ( file0 file1 ... fileN ) t h i s m a c r o g e n e r a t e s
c u s t o m c o m m a n d s t h a t g e n e r a t e e i t h e r P T X o r l i n k a b l e objects ( use "PTX" or
" O B J " f o r t h e f o r m a t a r g u m e n t t o s w i t c h ) . F i l e s t h a t d o n ' t e n d w i t h . c u
o r h a v e t h e H E A D E R _ F I L E _ O N L Y p r o p e r t y a r e i g n o r e d .
T h e a r g u m e n t s p a s s e d i n a f t e r O P T I O N S a r e e x t r a c o m m a n d l i n e o p t i o n s t o
g i v e t o n v c c . Y o u c a n a l s o s p e c i f y p e r c o n f i g u r a t i o n o p t i o n s b y
s p e c i f y i n g t h e n a m e o f t h e c o n f i g u r a t i o n f o l l o w e d b y t h e o p t i o n s . G e n e r a l
o p t i o n s m u s t p r e c e d e c o n f i g u r a t i o n s p e c i f i c o p t i o n s . N o t a l l
c o n f i g u r a t i o n s n e e d t o b e s p e c i f i e d , o n l y t h e o n e s p r o v i d e d w i l l b e u s e d .
O P T I O N S - D F L A G = 2 " - D F L A G _ O T H E R = s p a c e i n f l a g "
D E B U G - g
R E L E A S E - - u s e _ f a s t _ m a t h
R E L W I T H D E B I N F O - - u s e _ f a s t _ m a t h ; - g
M I N S I Z E R E L - - u s e _ f a s t _ m a t h
F o r c e r t a i n configurations ( namely VS generating object files with
C U D A _ A T T A C H _ V S _ B U I L D _ R U L E _ T O _ C U D A _ F I L E s e t t o O N ) , n o g e n e r a t e d f i l e w i l l
b e p r o d u c e d f o r t h e g i v e n c u d a f i l e . T h i s i s b e c a u s e w h e n y o u a d d t h e
c u d a f i l e t o V i s u a l S t u d i o i t k n o w s t h a t t h i s f i l e p r o d u c e s a n o b j e c t f i l e
a n d w i l l l i n k i n t h e r e s u l t i n g o b j e c t f i l e a u t o m a t i c a l l y .
T h i s s c r i p t w i l l a l s o g e n e r a t e a s e p a r a t e c m a k e s c r i p t t h a t i s u s e d a t
b u i l d t i m e t o i n v o k e n v c c . T h i s i s f o r s e v e r a l r e a s o n s .
1 . n v c c c a n r e t u r n n e g a t i v e n u m b e r s a s r e t u r n v a l u e s w h i c h c o n f u s e s
V i s u a l S t u d i o i n t o t h i n k i n g t h a t t h e c o m m a n d s u c c e e d e d . T h e s c r i p t n o w
c h e c k s t h e e r r o r c o d e s a n d p r o d u c e s e r r o r s w h e n t h e r e w a s a p r o b l e m .
2 . n v c c h a s b e e n k n o w n t o n o t d e l e t e i n c o m p l e t e r e s u l t s w h e n i t
e n c o u n t e r s p r o b l e m s . T h i s c o n f u s e s b u i l d s y s t e m s i n t o t h i n k i n g t h e
t a r g e t w a s g e n e r a t e d w h e n i n f a c t a n u n u s a b l e f i l e e x i s t s . T h e s c r i p t
n o w d e l e t e s t h e o u t p u t f i l e s i f t h e r e w a s a n e r r o r .
3 . B y p u t t i n g a l l t h e o p t i o n s t h a t a f f e c t t h e b u i l d i n t o a f i l e a n d t h e n
m a k e t h e b u i l d r u l e d e p e n d e n t o n t h e f i l e , t h e o u t p u t f i l e s w i l l b e
r e g e n e r a t e d w h e n t h e o p t i o n s c h a n g e .
T h i s s c r i p t a l s o l o o k s a t o p t i o n a l a r g u m e n t s S T A T I C , S H A R E D , o r M O D U L E t o
d e t e r m i n e w h e n t o t a r g e t t h e o b j e c t c o m p i l a t i o n f o r a s h a r e d l i b r a r y .
B U I L D _ S H A R E D _ L I B S i s i g n o r e d i n C U D A _ W R A P _ S R C S , b u t i t i s r e s p e c t e d i n
C U D A _ A D D _ L I B R A R Y . O n s o m e s y s t e m s s p e c i a l f l a g s a r e a d d e d f o r b u i l d i n g
o b j e c t s i n t e n d e d f o r s h a r e d l i b r a r i e s . A p r e p r o c e s s o r m a c r o ,
< t a r g e t _ n a m e > _ E X P O R T S i s d e f i n e d w h e n a s h a r e d l i b r a r y c o m p i l a t i o n i s
d e t e c t e d .
F l a g s p a s s e d i n t o a d d _ d e f i n i t i o n s w i t h - D o r / D a r e p a s s e d a l o n g t o n v c c .
T h e s c r i p t d e f i n e s t h e f o l l o w i n g v a r i a b l e s : :
C U D A _ V E R S I O N _ M A J O R - - T h e m a j o r v e r s i o n o f c u d a a s r e p o r t e d b y n v c c .
C U D A _ V E R S I O N _ M I N O R - - T h e m i n o r v e r s i o n .
C U D A _ V E R S I O N
C U D A _ V E R S I O N _ S T R I N G - - C U D A _ V E R S I O N _ M A J O R . C U D A _ V E R S I O N _ M I N O R
C U D A _ H A S _ F P 1 6 - - W h e t h e r a s h o r t float ( float16,fp16 ) i s s u p p o r t e d .
C U D A _ T O O L K I T _ R O O T _ D I R - - P a t h t o t h e C U D A Toolkit ( defined if not set ) .
C U D A _ S D K _ R O O T _ D I R - - P a t h t o t h e C U D A S D K . U s e t h i s t o f i n d f i l e s i n t h e
S D K . T h i s s c r i p t w i l l n o t d i r e c t l y s u p p o r t f i n d i n g
s p e c i f i c l i b r a r i e s o r h e a d e r s , a s t h a t i s n ' t
s u p p o r t e d b y N V I D I A . I f y o u w a n t t o c h a n g e
l i b r a r i e s w h e n t h e p a t h c h a n g e s s e e t h e
F i n d C U D A . c m a k e s c r i p t f o r a n e x a m p l e o f h o w t o c l e a r
t h e s e v a r i a b l e s . T h e r e a r e a l s o e x a m p l e s o f h o w t o
u s e t h e C U D A _ S D K _ R O O T _ D I R t o l o c a t e h e a d e r s o r
l i b r a r i e s , i f y o u s o choose ( at your own risk ) .
C U D A _ I N C L U D E _ D I R S - - I n c l u d e d i r e c t o r y f o r c u d a h e a d e r s . A d d e d a u t o m a t i c a l l y
f o r C U D A _ A D D _ E X E C U T A B L E a n d C U D A _ A D D _ L I B R A R Y .
C U D A _ L I B R A R I E S - - C u d a R T l i b r a r y .
C U D A _ C U F F T _ L I B R A R I E S - - D e v i c e o r e m u l a t i o n l i b r a r y f o r t h e C u d a F F T
implementation ( alternative to:
C U D A _ A D D _ C U F F T _ T O _ T A R G E T m a c r o )
C U D A _ C U B L A S _ L I B R A R I E S - - D e v i c e o r e m u l a t i o n l i b r a r y f o r t h e C u d a B L A S
implementation ( alternative to:
C U D A _ A D D _ C U B L A S _ T O _ T A R G E T m a c r o ) .
C U D A _ c u d a r t _ s t a t i c _ L I B R A R Y - - S t a t i c a l l y l i n k a b l e c u d a r u n t i m e l i b r a r y .
O n l y a v a i l a b l e f o r C U D A v e r s i o n 5 . 5 +
C U D A _ c u d a d e v r t _ L I B R A R Y - - D e v i c e r u n t i m e l i b r a r y .
R e q u i r e d f o r s e p a r a b l e c o m p i l a t i o n .
C U D A _ c u p t i _ L I B R A R Y - - C U D A P r o f i l i n g T o o l s I n t e r f a c e l i b r a r y .
O n l y a v a i l a b l e f o r C U D A v e r s i o n 4 . 0 + .
C U D A _ c u r a n d _ L I B R A R Y - - C U D A R a n d o m N u m b e r G e n e r a t i o n l i b r a r y .
O n l y a v a i l a b l e f o r C U D A v e r s i o n 3 . 2 + .
C U D A _ c u s o l v e r _ L I B R A R Y - - C U D A D i r e c t S o l v e r l i b r a r y .
O n l y a v a i l a b l e f o r C U D A v e r s i o n 7 . 0 + .
C U D A _ c u s p a r s e _ L I B R A R Y - - C U D A S p a r s e M a t r i x l i b r a r y .
O n l y a v a i l a b l e f o r C U D A v e r s i o n 3 . 2 + .
C U D A _ n p p _ L I B R A R Y - - N V I D I A P e r f o r m a n c e P r i m i t i v e s l i b .
O n l y a v a i l a b l e f o r C U D A v e r s i o n 4 . 0 + .
C U D A _ n p p c _ L I B R A R Y - - N V I D I A P e r f o r m a n c e P r i m i t i v e s lib ( core ) .
O n l y a v a i l a b l e f o r C U D A v e r s i o n 5 . 5 + .
C U D A _ n p p i _ L I B R A R Y - - N V I D I A P e r f o r m a n c e P r i m i t i v e s lib ( image processing ) .
O n l y a v a i l a b l e f o r C U D A v e r s i o n 5 . 5 - 8 . 0 .
C U D A _ n p p i a l _ L I B R A R Y - - N V I D I A P e r f o r m a n c e P r i m i t i v e s lib ( image processing ) .
O n l y a v a i l a b l e f o r C U D A v e r s i o n 9 . 0 .
C U D A _ n p p i c c _ L I B R A R Y - - N V I D I A P e r f o r m a n c e P r i m i t i v e s lib ( image processing ) .
O n l y a v a i l a b l e f o r C U D A v e r s i o n 9 . 0 .
C U D A _ n p p i c o m _ L I B R A R Y - - N V I D I A P e r f o r m a n c e P r i m i t i v e s lib ( image processing ) .
2023-11-01 06:36:59 +08:00
O n l y a v a i l a b l e f o r C U D A v e r s i o n 9 . 0 - 1 0 . 2 .
R e p l a c e d b y n v j p e g .
2023-11-01 06:11:15 +08:00
C U D A _ n p p i d e i _ L I B R A R Y - - N V I D I A P e r f o r m a n c e P r i m i t i v e s lib ( image processing ) .
O n l y a v a i l a b l e f o r C U D A v e r s i o n 9 . 0 .
C U D A _ n p p i f _ L I B R A R Y - - N V I D I A P e r f o r m a n c e P r i m i t i v e s lib ( image processing ) .
O n l y a v a i l a b l e f o r C U D A v e r s i o n 9 . 0 .
C U D A _ n p p i g _ L I B R A R Y - - N V I D I A P e r f o r m a n c e P r i m i t i v e s lib ( image processing ) .
O n l y a v a i l a b l e f o r C U D A v e r s i o n 9 . 0 .
C U D A _ n p p i m _ L I B R A R Y - - N V I D I A P e r f o r m a n c e P r i m i t i v e s lib ( image processing ) .
O n l y a v a i l a b l e f o r C U D A v e r s i o n 9 . 0 .
C U D A _ n p p i s t _ L I B R A R Y - - N V I D I A P e r f o r m a n c e P r i m i t i v e s lib ( image processing ) .
O n l y a v a i l a b l e f o r C U D A v e r s i o n 9 . 0 .
C U D A _ n p p i s u _ L I B R A R Y - - N V I D I A P e r f o r m a n c e P r i m i t i v e s lib ( image processing ) .
O n l y a v a i l a b l e f o r C U D A v e r s i o n 9 . 0 .
C U D A _ n p p i t c _ L I B R A R Y - - N V I D I A P e r f o r m a n c e P r i m i t i v e s lib ( image processing ) .
O n l y a v a i l a b l e f o r C U D A v e r s i o n 9 . 0 .
C U D A _ n p p s _ L I B R A R Y - - N V I D I A P e r f o r m a n c e P r i m i t i v e s lib ( signal processing ) .
O n l y a v a i l a b l e f o r C U D A v e r s i o n 5 . 5 + .
C U D A _ n v c u v e n c _ L I B R A R Y - - C U D A V i d e o E n c o d e r l i b r a r y .
O n l y a v a i l a b l e f o r C U D A v e r s i o n 3 . 2 + .
W i n d o w s o n l y .
C U D A _ n v c u v i d _ L I B R A R Y - - C U D A V i d e o D e c o d e r l i b r a r y .
O n l y a v a i l a b l e f o r C U D A v e r s i o n 3 . 2 + .
W i n d o w s o n l y .
2023-11-01 06:20:22 +08:00
C U D A _ n v T o o l s E x t _ L I B R A R Y
- - N V I D A C U D A T o o l s E x t e n s i o n l i b r a r y .
A v a i l a b l e f o r C U D A v e r s i o n 5 + .
C U D A _ O p e n C L _ L I B R A R Y - - N V I D A C U D A O p e n C L l i b r a r y .
A v a i l a b l e f o r C U D A v e r s i o n 5 + .
2023-11-01 06:11:15 +08:00
#]=======================================================================]
# James Bigler, NVIDIA Corp (nvidia.com - jbigler)
# Abe Stephens, SCI Institute -- http://www.sci.utah.edu/~abe/FindCuda.html
#
# Copyright (c) 2008 - 2009 NVIDIA Corporation. All rights reserved.
#
# Copyright (c) 2007-2009
# Scientific Computing and Imaging Institute, University of Utah
#
# This code is licensed under the MIT License. See the FindCUDA.cmake script
# for the text of the license.
# The MIT License
#
# License for the specific language governing rights and limitations under
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
###############################################################################
# FindCUDA.cmake
# This macro helps us find the location of helper files we will need the full path to
macro ( CUDA_FIND_HELPER_FILE _name _extension )
set ( _full_name "${_name}.${_extension}" )
# CMAKE_CURRENT_LIST_FILE contains the full path to the file currently being
# processed. Using this variable, we can pull out the current path, and
# provide a way to get access to the other files we need local to here.
get_filename_component ( CMAKE_CURRENT_LIST_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH )
set ( CUDA_ ${ _name } "${CMAKE_CURRENT_LIST_DIR}/FindCUDA/${_full_name}" )
if ( NOT EXISTS "${CUDA_${_name}}" )
set ( error_message "${_full_name} not found in ${CMAKE_CURRENT_LIST_DIR}/FindCUDA" )
if ( CUDA_FIND_REQUIRED )
message ( FATAL_ERROR "${error_message}" )
else ( )
if ( NOT CUDA_FIND_QUIETLY )
message ( STATUS "${error_message}" )
endif ( )
endif ( )
endif ( )
# Set this variable as internal, so the user isn't bugged with it.
set ( CUDA_ ${ _name } ${ CUDA_${_name } } CACHE INTERNAL "Location of ${_full_name}" FORCE )
endmacro ( )
#####################################################################
## CUDA_INCLUDE_NVCC_DEPENDENCIES
##
# So we want to try and include the dependency file if it exists. If
# it doesn't exist then we need to create an empty one, so we can
# include it.
# If it does exist, then we need to check to see if all the files it
# depends on exist. If they don't then we should clear the dependency
# file and regenerate it later. This covers the case where a header
# file has disappeared or moved.
macro ( CUDA_INCLUDE_NVCC_DEPENDENCIES dependency_file )
set ( CUDA_NVCC_DEPEND )
set ( CUDA_NVCC_DEPEND_REGENERATE FALSE )
# Include the dependency file. Create it first if it doesn't exist . The
# INCLUDE puts a dependency that will force CMake to rerun and bring in the
# new info when it changes. DO NOT REMOVE THIS (as I did and spent a few
# hours figuring out why it didn't work.
if ( NOT EXISTS ${ dependency_file } )
file ( WRITE ${ dependency_file } "#FindCUDA.cmake generated file. Do not edit.\n" )
endif ( )
# Always include this file to force CMake to run again next
# invocation and rebuild the dependencies.
#message("including dependency_file = ${dependency_file}")
include ( ${ dependency_file } )
# Now we need to verify the existence of all the included files
# here. If they aren't there we need to just blank this variable and
# make the file regenerate again.
# if(DEFINED CUDA_NVCC_DEPEND)
# message("CUDA_NVCC_DEPEND set")
# else()
# message("CUDA_NVCC_DEPEND NOT set")
# endif()
if ( CUDA_NVCC_DEPEND )
#message("CUDA_NVCC_DEPEND found")
foreach ( f ${ CUDA_NVCC_DEPEND } )
# message("searching for ${f}")
if ( NOT EXISTS ${ f } )
#message("file ${f} not found")
set ( CUDA_NVCC_DEPEND_REGENERATE TRUE )
endif ( )
endforeach ( )
else ( )
#message("CUDA_NVCC_DEPEND false")
# No dependencies, so regenerate the file.
set ( CUDA_NVCC_DEPEND_REGENERATE TRUE )
endif ( )
#message("CUDA_NVCC_DEPEND_REGENERATE = ${CUDA_NVCC_DEPEND_REGENERATE}")
# No incoming dependencies, so we need to generate them. Make the
# output depend on the dependency file itself, which should cause the
# rule to re-run.
if ( CUDA_NVCC_DEPEND_REGENERATE )
set ( CUDA_NVCC_DEPEND ${ dependency_file } )
#message("Generating an empty dependency_file: ${dependency_file}")
file ( WRITE ${ dependency_file } "#FindCUDA.cmake generated file. Do not edit.\n" )
endif ( )
endmacro ( )
###############################################################################
###############################################################################
# Setup variables' defaults
###############################################################################
###############################################################################
# Allow the user to specify if the device code is supposed to be 32 or 64 bit.
if ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
set ( CUDA_64_BIT_DEVICE_CODE_DEFAULT ON )
else ( )
set ( CUDA_64_BIT_DEVICE_CODE_DEFAULT OFF )
endif ( )
option ( CUDA_64_BIT_DEVICE_CODE "Compile device code in 64 bit mode" ${ CUDA_64_BIT_DEVICE_CODE_DEFAULT } )
# Attach the build rule to the source file in VS. This option
option ( CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE "Attach the build rule to the CUDA source file. Enable only when the CUDA source file is added to at most one target." ON )
# Prints out extra information about the cuda file during compilation
option ( CUDA_BUILD_CUBIN "Generate and parse .cubin files in Device mode." OFF )
# Set whether we are using emulation or device mode.
option ( CUDA_BUILD_EMULATION "Build in Emulation mode" OFF )
# Where to put the generated output.
set ( CUDA_GENERATED_OUTPUT_DIR "" CACHE PATH "Directory to put all the output files. If blank it will default to the CMAKE_CURRENT_BINARY_DIR" )
# Parse HOST_COMPILATION mode.
option ( CUDA_HOST_COMPILATION_CPP "Generated file extension" ON )
# Extra user settable flags
cmake_initialize_per_config_variable ( CUDA_NVCC_FLAGS "Semi-colon delimit multiple arguments." )
if ( DEFINED ENV{CUDAHOSTCXX} )
set ( CUDA_HOST_COMPILER "$ENV{CUDAHOSTCXX}" CACHE FILEPATH "Host side compiler used by NVCC" )
elseif ( CMAKE_GENERATOR MATCHES "Visual Studio" )
set ( _CUDA_MSVC_HOST_COMPILER "$(VCInstallDir)Tools/MSVC/$(VCToolsVersion)/bin/Host$(Platform)/$(PlatformTarget)" )
if ( MSVC_VERSION LESS 1910 )
2023-11-01 06:20:22 +08:00
set ( _CUDA_MSVC_HOST_COMPILER "$(VCInstallDir)bin" )
2023-11-01 06:11:15 +08:00
endif ( )
set ( CUDA_HOST_COMPILER "${_CUDA_MSVC_HOST_COMPILER}" CACHE FILEPATH "Host side compiler used by NVCC" )
else ( )
if ( APPLE
A N D " $ { C M A K E _ C _ C O M P I L E R _ I D } " M A T C H E S " C l a n g "
A N D " $ { C M A K E _ C _ C O M P I L E R } " M A T C H E S " / c c $ " )
# Using cc which is symlink to clang may let NVCC think it is GCC and issue
# unhandled -dumpspecs option to clang. Also in case neither
# CMAKE_C_COMPILER is defined (project does not use C language) nor
# CUDA_HOST_COMPILER is specified manually we should skip -ccbin and let
# nvcc use its own default C compiler.
# Only care about this on APPLE with clang to avoid
# following symlinks to things like ccache
if ( DEFINED CMAKE_C_COMPILER AND NOT DEFINED CUDA_HOST_COMPILER )
get_filename_component ( c_compiler_realpath "${CMAKE_C_COMPILER}" REALPATH )
# if the real path does not end up being clang then
# go back to using CMAKE_C_COMPILER
if ( NOT "${c_compiler_realpath}" MATCHES "/clang$" )
set ( c_compiler_realpath "${CMAKE_C_COMPILER}" )
endif ( )
else ( )
set ( c_compiler_realpath "" )
endif ( )
set ( CUDA_HOST_COMPILER "${c_compiler_realpath}" CACHE FILEPATH "Host side compiler used by NVCC" )
elseif ( MSVC AND "${CMAKE_C_COMPILER}" MATCHES "clcache|sccache" )
# NVCC does not think it will work if it is passed clcache.exe or sccache.exe
# as the host compiler, which means that builds with CC=cl.exe won't work.
# Best to just feed it whatever the actual cl.exe is as the host compiler.
set ( CUDA_HOST_COMPILER "cl.exe" CACHE FILEPATH "Host side compiler used by NVCC" )
else ( )
set ( CUDA_HOST_COMPILER "${CMAKE_C_COMPILER}"
C A C H E F I L E P A T H " H o s t s i d e c o m p i l e r u s e d b y N V C C " )
endif ( )
endif ( )
# Propagate the host flags to the host compiler via -Xcompiler
option ( CUDA_PROPAGATE_HOST_FLAGS "Propagate C/CXX_FLAGS and friends to the host compiler via -Xcompile" ON )
# Enable CUDA_SEPARABLE_COMPILATION
option ( CUDA_SEPARABLE_COMPILATION "Compile CUDA objects with separable compilation enabled. Requires CUDA 5.0+" OFF )
# Specifies whether the commands used when compiling the .cu file will be printed out.
option ( CUDA_VERBOSE_BUILD "Print out the commands run while compiling the CUDA source file. With the Makefile generator this defaults to VERBOSE variable specified on the command line, but can be forced on with this option." OFF )
mark_as_advanced (
C U D A _ 6 4 _ B I T _ D E V I C E _ C O D E
C U D A _ A T T A C H _ V S _ B U I L D _ R U L E _ T O _ C U D A _ F I L E
C U D A _ G E N E R A T E D _ O U T P U T _ D I R
C U D A _ H O S T _ C O M P I L A T I O N _ C P P
C U D A _ N V C C _ F L A G S
C U D A _ P R O P A G A T E _ H O S T _ F L A G S
C U D A _ B U I L D _ C U B I N
C U D A _ B U I L D _ E M U L A T I O N
C U D A _ V E R B O S E _ B U I L D
C U D A _ S E P A R A B L E _ C O M P I L A T I O N
)
# Single config generators like Makefiles or Ninja don't usually have
# CMAKE_CONFIGURATION_TYPES defined (but note that it can be defined if set by
# projects or developers). Even CMAKE_BUILD_TYPE might not be defined for
# single config generators (and should not be defined for multi-config
# generators). To ensure we get a complete superset of all possible
# configurations, we combine CMAKE_CONFIGURATION_TYPES, CMAKE_BUILD_TYPE and
# all of the standard configurations, then weed out duplicates with
# list(REMOVE_DUPLICATES). Looping over the unique set then ensures we have
# each configuration-specific set of nvcc flags defined and marked as advanced.
set ( CUDA_configuration_types ${ CMAKE_CONFIGURATION_TYPES } ${ CMAKE_BUILD_TYPE } Debug MinSizeRel Release RelWithDebInfo )
list ( REMOVE_DUPLICATES CUDA_configuration_types )
###############################################################################
###############################################################################
# Locate CUDA, Set Build Type, etc.
###############################################################################
###############################################################################
macro ( cuda_unset_include_and_libraries )
unset ( CUDA_TOOLKIT_INCLUDE CACHE )
unset ( CUDA_CUDART_LIBRARY CACHE )
unset ( CUDA_CUDA_LIBRARY CACHE )
# Make sure you run this before you unset CUDA_VERSION.
if ( CUDA_VERSION VERSION_EQUAL "3.0" )
# This only existed in the 3.0 version of the CUDA toolkit
unset ( CUDA_CUDARTEMU_LIBRARY CACHE )
endif ( )
unset ( CUDA_cudart_static_LIBRARY CACHE )
unset ( CUDA_cudadevrt_LIBRARY CACHE )
unset ( CUDA_cublas_LIBRARY CACHE )
unset ( CUDA_cublas_device_LIBRARY CACHE )
unset ( CUDA_cublasemu_LIBRARY CACHE )
unset ( CUDA_cufft_LIBRARY CACHE )
unset ( CUDA_cufftemu_LIBRARY CACHE )
unset ( CUDA_cupti_LIBRARY CACHE )
unset ( CUDA_curand_LIBRARY CACHE )
unset ( CUDA_cusolver_LIBRARY CACHE )
unset ( CUDA_cusparse_LIBRARY CACHE )
unset ( CUDA_npp_LIBRARY CACHE )
unset ( CUDA_nppc_LIBRARY CACHE )
unset ( CUDA_nppi_LIBRARY CACHE )
unset ( CUDA_npps_LIBRARY CACHE )
unset ( CUDA_nvcuvenc_LIBRARY CACHE )
unset ( CUDA_nvcuvid_LIBRARY CACHE )
2023-11-01 06:20:22 +08:00
unset ( CUDA_nvToolsExt_LIBRARY CACHE )
unset ( CUDA_OpenCL_LIBRARY CACHE )
2023-11-01 06:11:15 +08:00
unset ( CUDA_GPU_DETECT_OUTPUT CACHE )
endmacro ( )
# Check to see if the CUDA_TOOLKIT_ROOT_DIR and CUDA_SDK_ROOT_DIR have changed,
# if they have then clear the cache variables, so that will be detected again.
if ( NOT "${CUDA_TOOLKIT_ROOT_DIR}" STREQUAL "${CUDA_TOOLKIT_ROOT_DIR_INTERNAL}" )
unset ( CUDA_TOOLKIT_TARGET_DIR CACHE )
unset ( CUDA_NVCC_EXECUTABLE CACHE )
cuda_unset_include_and_libraries ( )
unset ( CUDA_VERSION CACHE )
endif ( )
if ( NOT "${CUDA_TOOLKIT_TARGET_DIR}" STREQUAL "${CUDA_TOOLKIT_TARGET_DIR_INTERNAL}" )
cuda_unset_include_and_libraries ( )
endif ( )
#
# End of unset()
#
#
# Start looking for things
#
# Search for the cuda distribution.
if ( NOT CUDA_TOOLKIT_ROOT_DIR AND NOT CMAKE_CROSSCOMPILING )
# Search in the CUDA_BIN_PATH first.
2023-11-01 06:34:31 +08:00
find_program ( CUDA_TOOLKIT_ROOT_DIR_NVCC
2023-11-01 06:11:15 +08:00
N A M E S n v c c n v c c . e x e
P A T H S
E N V C U D A _ T O O L K I T _ R O O T
E N V C U D A _ P A T H
E N V C U D A _ B I N _ P A T H
P A T H _ S U F F I X E S b i n b i n 6 4
D O C " T o o l k i t l o c a t i o n . "
N O _ D E F A U L T _ P A T H
)
# Now search default paths
2023-11-01 06:34:31 +08:00
find_program ( CUDA_TOOLKIT_ROOT_DIR_NVCC
2023-11-01 06:11:15 +08:00
N A M E S n v c c n v c c . e x e
P A T H S / o p t / c u d a / b i n
P A T H _ S U F F I X E S c u d a / b i n
D O C " T o o l k i t l o c a t i o n . "
)
2023-11-01 06:34:31 +08:00
if ( CUDA_TOOLKIT_ROOT_DIR_NVCC )
get_filename_component ( CUDA_TOOLKIT_ROOT_DIR_NVCC_PAR "${CUDA_TOOLKIT_ROOT_DIR_NVCC}" DIRECTORY )
get_filename_component ( CUDA_TOOLKIT_ROOT_DIR "${CUDA_TOOLKIT_ROOT_DIR_NVCC_PAR}" DIRECTORY CACHE )
2023-11-01 06:11:15 +08:00
string ( REGEX REPLACE "[/\\\\]?bin[64]*[/\\\\]?$" "" CUDA_TOOLKIT_ROOT_DIR ${ CUDA_TOOLKIT_ROOT_DIR } )
# We need to force this back into the cache.
set ( CUDA_TOOLKIT_ROOT_DIR ${ CUDA_TOOLKIT_ROOT_DIR } CACHE PATH "Toolkit location." FORCE )
set ( CUDA_TOOLKIT_TARGET_DIR ${ CUDA_TOOLKIT_ROOT_DIR } )
endif ( )
2023-11-01 06:34:31 +08:00
unset ( CUDA_TOOLKIT_ROOT_DIR_NVCC CACHE )
2023-11-01 06:11:15 +08:00
if ( NOT EXISTS ${ CUDA_TOOLKIT_ROOT_DIR } )
if ( CUDA_FIND_REQUIRED )
message ( FATAL_ERROR "Specify CUDA_TOOLKIT_ROOT_DIR" )
elseif ( NOT CUDA_FIND_QUIETLY )
message ( "CUDA_TOOLKIT_ROOT_DIR not found or specified" )
endif ( )
endif ( )
endif ( )
if ( CMAKE_CROSSCOMPILING )
SET ( CUDA_TOOLKIT_ROOT $ENV{ CUDA_TOOLKIT_ROOT } )
if ( CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7-a" )
# Support for NVPACK
set ( CUDA_TOOLKIT_TARGET_NAME "armv7-linux-androideabi" )
elseif ( CMAKE_SYSTEM_PROCESSOR MATCHES "arm" )
# Support for arm cross compilation
set ( CUDA_TOOLKIT_TARGET_NAME "armv7-linux-gnueabihf" )
elseif ( CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64" )
# Support for aarch64 cross compilation
if ( ANDROID_ARCH_NAME STREQUAL "arm64" )
set ( CUDA_TOOLKIT_TARGET_NAME "aarch64-linux-androideabi" )
else ( )
set ( CUDA_TOOLKIT_TARGET_NAME "aarch64-linux" )
endif ( ANDROID_ARCH_NAME STREQUAL "arm64" )
endif ( )
if ( EXISTS "${CUDA_TOOLKIT_ROOT}/targets/${CUDA_TOOLKIT_TARGET_NAME}" )
set ( CUDA_TOOLKIT_TARGET_DIR "${CUDA_TOOLKIT_ROOT}/targets/${CUDA_TOOLKIT_TARGET_NAME}" CACHE PATH "CUDA Toolkit target location." )
SET ( CUDA_TOOLKIT_ROOT_DIR ${ CUDA_TOOLKIT_ROOT } )
mark_as_advanced ( CUDA_TOOLKIT_TARGET_DIR )
endif ( )
# add known CUDA targetr root path to the set of directories we search for programs, libraries and headers
set ( CMAKE_FIND_ROOT_PATH "${CUDA_TOOLKIT_TARGET_DIR};${CMAKE_FIND_ROOT_PATH}" )
macro ( cuda_find_host_program )
if ( COMMAND find_host_program )
find_host_program ( ${ ARGN } )
else ( )
find_program ( ${ ARGN } )
endif ( )
endmacro ( )
else ( )
# for non-cross-compile, find_host_program == find_program and CUDA_TOOLKIT_TARGET_DIR == CUDA_TOOLKIT_ROOT_DIR
macro ( cuda_find_host_program )
find_program ( ${ ARGN } )
endmacro ( )
SET ( CUDA_TOOLKIT_TARGET_DIR ${ CUDA_TOOLKIT_ROOT_DIR } )
endif ( )
# CUDA_NVCC_EXECUTABLE
if ( DEFINED ENV{CUDA_NVCC_EXECUTABLE} )
set ( CUDA_NVCC_EXECUTABLE "$ENV{CUDA_NVCC_EXECUTABLE}" CACHE FILEPATH "The CUDA compiler" )
else ( )
cuda_find_host_program ( CUDA_NVCC_EXECUTABLE
N A M E S n v c c
P A T H S " $ { C U D A _ T O O L K I T _ R O O T _ D I R } "
E N V C U D A _ P A T H
E N V C U D A _ B I N _ P A T H
P A T H _ S U F F I X E S b i n b i n 6 4
N O _ D E F A U L T _ P A T H
)
# Search default search paths, after we search our own set of paths.
cuda_find_host_program ( CUDA_NVCC_EXECUTABLE nvcc )
endif ( )
mark_as_advanced ( CUDA_NVCC_EXECUTABLE )
if ( CUDA_NVCC_EXECUTABLE AND NOT CUDA_VERSION )
# Compute the version.
execute_process ( COMMAND ${ CUDA_NVCC_EXECUTABLE } "--version" OUTPUT_VARIABLE NVCC_OUT )
string ( REGEX REPLACE ".*release ([0-9]+)\\.([0-9]+).*" "\\1" CUDA_VERSION_MAJOR ${ NVCC_OUT } )
string ( REGEX REPLACE ".*release ([0-9]+)\\.([0-9]+).*" "\\2" CUDA_VERSION_MINOR ${ NVCC_OUT } )
set ( CUDA_VERSION "${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}" CACHE STRING "Version of CUDA as computed from nvcc." )
mark_as_advanced ( CUDA_VERSION )
else ( )
# Need to set these based off of the cached value
string ( REGEX REPLACE "([0-9]+)\\.([0-9]+).*" "\\1" CUDA_VERSION_MAJOR "${CUDA_VERSION}" )
string ( REGEX REPLACE "([0-9]+)\\.([0-9]+).*" "\\2" CUDA_VERSION_MINOR "${CUDA_VERSION}" )
endif ( )
# Always set this convenience variable
set ( CUDA_VERSION_STRING "${CUDA_VERSION}" )
# CUDA_TOOLKIT_INCLUDE
find_path ( CUDA_TOOLKIT_INCLUDE
d e v i c e _ f u n c t i o n s . h # Header included in toolkit
P A T H S $ { C U D A _ T O O L K I T _ T A R G E T _ D I R }
E N V C U D A _ P A T H
E N V C U D A _ I N C _ P A T H
P A T H _ S U F F I X E S i n c l u d e
N O _ D E F A U L T _ P A T H
)
# Search default search paths, after we search our own set of paths.
find_path ( CUDA_TOOLKIT_INCLUDE device_functions.h )
mark_as_advanced ( CUDA_TOOLKIT_INCLUDE )
if ( CUDA_VERSION VERSION_GREATER "7.0" OR EXISTS "${CUDA_TOOLKIT_INCLUDE}/cuda_fp16.h" )
set ( CUDA_HAS_FP16 TRUE )
else ( )
set ( CUDA_HAS_FP16 FALSE )
endif ( )
# Set the user list of include dir to nothing to initialize it.
set ( CUDA_NVCC_INCLUDE_DIRS_USER "" )
set ( CUDA_INCLUDE_DIRS ${ CUDA_TOOLKIT_INCLUDE } )
macro ( cuda_find_library_local_first_with_path_ext _var _names _doc _path_ext )
if ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
# CUDA 3.2+ on Windows moved the library directories, so we need the new
# and old paths.
set ( _cuda_64bit_lib_dir "${_path_ext}lib/x64" "${_path_ext}lib64" "${_path_ext}libx64" )
endif ( )
# CUDA 3.2+ on Windows moved the library directories, so we need to new
# (lib/Win32) and the old path (lib).
find_library ( ${ _var }
N A M E S $ { _ n a m e s }
P A T H S " $ { C U D A _ T O O L K I T _ T A R G E T _ D I R } "
E N V C U D A _ P A T H
E N V C U D A _ L I B _ P A T H
P A T H _ S U F F I X E S $ { _ c u d a _ 6 4 b i t _ l i b _ d i r } " $ { _ p a t h _ e x t } l i b / W i n 3 2 " " $ { _ p a t h _ e x t } l i b " " $ { _ p a t h _ e x t } l i b W i n 3 2 "
D O C $ { _ d o c }
N O _ D E F A U L T _ P A T H
)
if ( NOT CMAKE_CROSSCOMPILING )
# Search default search paths, after we search our own set of paths.
find_library ( ${ _var }
N A M E S $ { _ n a m e s }
P A T H S " / u s r / l i b / n v i d i a - c u r r e n t "
D O C $ { _ d o c }
)
endif ( )
endmacro ( )
macro ( cuda_find_library_local_first _var _names _doc )
cuda_find_library_local_first_with_path_ext ( "${_var}" "${_names}" "${_doc}" "" )
endmacro ( )
macro ( find_library_local_first _var _names _doc )
cuda_find_library_local_first ( "${_var}" "${_names}" "${_doc}" "" )
endmacro ( )
# CUDA_LIBRARIES
cuda_find_library_local_first ( CUDA_CUDART_LIBRARY cudart "\" cudart\ " library" )
if ( CUDA_VERSION VERSION_EQUAL "3.0" )
# The cudartemu library only existed for the 3.0 version of CUDA.
cuda_find_library_local_first ( CUDA_CUDARTEMU_LIBRARY cudartemu "\" cudartemu\ " library" )
mark_as_advanced (
C U D A _ C U D A R T E M U _ L I B R A R Y
)
endif ( )
if ( NOT CUDA_VERSION VERSION_LESS "5.5" )
cuda_find_library_local_first ( CUDA_cudart_static_LIBRARY cudart_static "static CUDA runtime library" )
mark_as_advanced ( CUDA_cudart_static_LIBRARY )
endif ( )
if ( CUDA_cudart_static_LIBRARY )
# If static cudart available, use it by default, but provide a user-visible option to disable it.
option ( CUDA_USE_STATIC_CUDA_RUNTIME "Use the static version of the CUDA runtime library if available" ON )
else ( )
# If not available, silently disable the option.
set ( CUDA_USE_STATIC_CUDA_RUNTIME OFF CACHE INTERNAL "" )
endif ( )
if ( CUDA_USE_STATIC_CUDA_RUNTIME )
set ( CUDA_CUDART_LIBRARY_VAR CUDA_cudart_static_LIBRARY )
else ( )
set ( CUDA_CUDART_LIBRARY_VAR CUDA_CUDART_LIBRARY )
endif ( )
if ( NOT CUDA_VERSION VERSION_LESS "5.0" )
cuda_find_library_local_first ( CUDA_cudadevrt_LIBRARY cudadevrt "\" cudadevrt\ " library" )
mark_as_advanced ( CUDA_cudadevrt_LIBRARY )
endif ( )
if ( CUDA_USE_STATIC_CUDA_RUNTIME )
if ( UNIX )
# Check for the dependent libraries.
# Many of the FindXYZ CMake comes with makes use of try_compile with int main(){return 0;}
# as the source file. Unfortunately this causes a warning with -Wstrict-prototypes and
# -Werror causes the try_compile to fail. We will just temporarily disable other flags
# when doing the find_package command here.
set ( _cuda_cmake_c_flags ${ CMAKE_C_FLAGS } )
set ( CMAKE_C_FLAGS "-fPIC" )
find_package ( Threads REQUIRED )
set ( CMAKE_C_FLAGS ${ _cuda_cmake_c_flags } )
if ( NOT APPLE )
#On Linux, you must link against librt when using the static cuda runtime.
find_library ( CUDA_rt_LIBRARY rt )
if ( NOT CUDA_rt_LIBRARY )
message ( WARNING "Expecting to find librt for libcudart_static, but didn't find it." )
endif ( )
endif ( )
endif ( )
endif ( )
# CUPTI library showed up in cuda toolkit 4.0
if ( NOT CUDA_VERSION VERSION_LESS "4.0" )
cuda_find_library_local_first_with_path_ext ( CUDA_cupti_LIBRARY cupti "\" cupti\ " library" "extras/CUPTI/" )
mark_as_advanced ( CUDA_cupti_LIBRARY )
endif ( )
# Set the CUDA_LIBRARIES variable. This is the set of stuff to link against if you are
# using the CUDA runtime. For the dynamic version of the runtime, most of the
# dependencies are brough in, but for the static version there are additional libraries
# and linker commands needed.
# Initialize to empty
set ( CUDA_LIBRARIES )
# If we are using emulation mode and we found the cudartemu library then use
# that one instead of cudart.
if ( CUDA_BUILD_EMULATION AND CUDA_CUDARTEMU_LIBRARY )
list ( APPEND CUDA_LIBRARIES ${ CUDA_CUDARTEMU_LIBRARY } )
elseif ( CUDA_USE_STATIC_CUDA_RUNTIME AND CUDA_cudart_static_LIBRARY )
2023-11-01 06:34:31 +08:00
list ( APPEND CUDA_LIBRARIES ${ CUDA_cudart_static_LIBRARY } )
if ( TARGET Threads::Threads )
list ( APPEND CUDA_LIBRARIES Threads::Threads )
endif ( )
list ( APPEND CUDA_LIBRARIES ${ CMAKE_DL_LIBS } )
2023-11-01 06:11:15 +08:00
if ( CUDA_rt_LIBRARY )
list ( APPEND CUDA_LIBRARIES ${ CUDA_rt_LIBRARY } )
endif ( )
if ( APPLE )
# We need to add the default path to the driver (libcuda.dylib) as an rpath, so that
# the static cuda runtime can find it at runtime.
list ( APPEND CUDA_LIBRARIES -Wl,-rpath,/usr/local/cuda/lib )
endif ( )
else ( )
list ( APPEND CUDA_LIBRARIES ${ CUDA_CUDART_LIBRARY } )
endif ( )
# 1.1 toolkit on linux doesn't appear to have a separate library on
# some platforms.
cuda_find_library_local_first ( CUDA_CUDA_LIBRARY cuda "\" cuda\ " library (older versions only)." )
mark_as_advanced (
C U D A _ C U D A _ L I B R A R Y
C U D A _ C U D A R T _ L I B R A R Y
)
#######################
# Look for some of the toolkit helper libraries
macro ( FIND_CUDA_HELPER_LIBS _name )
cuda_find_library_local_first ( CUDA_ ${ _name } _LIBRARY ${ _name } "\" ${ _name } \" library " )
mark_as_advanced ( CUDA_ ${ _name } _LIBRARY )
endmacro ( )
#######################
# Disable emulation for v3.1 onward
if ( CUDA_VERSION VERSION_GREATER "3.0" )
if ( CUDA_BUILD_EMULATION )
message ( FATAL_ERROR "CUDA_BUILD_EMULATION is not supported in version 3.1 and onwards. You must disable it to proceed. You have version ${CUDA_VERSION}." )
endif ( )
endif ( )
# Search for additional CUDA toolkit libraries.
if ( CUDA_VERSION VERSION_LESS "3.1" )
# Emulation libraries aren't available in version 3.1 onward.
find_cuda_helper_libs ( cufftemu )
find_cuda_helper_libs ( cublasemu )
endif ( )
find_cuda_helper_libs ( cufft )
find_cuda_helper_libs ( cublas )
if ( NOT CUDA_VERSION VERSION_LESS "3.2" )
# cusparse showed up in version 3.2
find_cuda_helper_libs ( cusparse )
find_cuda_helper_libs ( curand )
if ( WIN32 )
find_cuda_helper_libs ( nvcuvenc )
find_cuda_helper_libs ( nvcuvid )
endif ( )
endif ( )
if ( CUDA_VERSION VERSION_GREATER "5.0" AND CUDA_VERSION VERSION_LESS "9.2" )
# In CUDA 9.2 cublas_device was deprecated
find_cuda_helper_libs ( cublas_device )
endif ( )
2023-11-01 06:20:22 +08:00
if ( NOT CUDA_VERSION VERSION_LESS "5.0" )
find_cuda_helper_libs ( nvToolsExt )
find_cuda_helper_libs ( OpenCL )
endif ( )
2023-11-01 06:11:15 +08:00
if ( NOT CUDA_VERSION VERSION_LESS "9.0" )
# In CUDA 9.0 NPP was nppi was removed
find_cuda_helper_libs ( nppc )
find_cuda_helper_libs ( nppial )
find_cuda_helper_libs ( nppicc )
2023-11-01 06:36:59 +08:00
if ( CUDA_VERSION VERSION_LESS "11.0" )
find_cuda_helper_libs ( nppicom )
endif ( )
2023-11-01 06:11:15 +08:00
find_cuda_helper_libs ( nppidei )
find_cuda_helper_libs ( nppif )
find_cuda_helper_libs ( nppig )
find_cuda_helper_libs ( nppim )
find_cuda_helper_libs ( nppist )
find_cuda_helper_libs ( nppisu )
find_cuda_helper_libs ( nppitc )
find_cuda_helper_libs ( npps )
set ( CUDA_npp_LIBRARY "${CUDA_nppc_LIBRARY};${CUDA_nppial_LIBRARY};${CUDA_nppicc_LIBRARY};${CUDA_nppicom_LIBRARY};${CUDA_nppidei_LIBRARY};${CUDA_nppif_LIBRARY};${CUDA_nppig_LIBRARY};${CUDA_nppim_LIBRARY};${CUDA_nppist_LIBRARY};${CUDA_nppisu_LIBRARY};${CUDA_nppitc_LIBRARY};${CUDA_npps_LIBRARY}" )
elseif ( CUDA_VERSION VERSION_GREATER "5.0" )
# In CUDA 5.5 NPP was split into 3 separate libraries.
find_cuda_helper_libs ( nppc )
find_cuda_helper_libs ( nppi )
find_cuda_helper_libs ( npps )
set ( CUDA_npp_LIBRARY "${CUDA_nppc_LIBRARY};${CUDA_nppi_LIBRARY};${CUDA_npps_LIBRARY}" )
elseif ( NOT CUDA_VERSION VERSION_LESS "4.0" )
find_cuda_helper_libs ( npp )
endif ( )
if ( NOT CUDA_VERSION VERSION_LESS "7.0" )
# cusolver showed up in version 7.0
find_cuda_helper_libs ( cusolver )
endif ( )
if ( CUDA_BUILD_EMULATION )
set ( CUDA_CUFFT_LIBRARIES ${ CUDA_cufftemu_LIBRARY } )
set ( CUDA_CUBLAS_LIBRARIES ${ CUDA_cublasemu_LIBRARY } )
else ( )
set ( CUDA_CUFFT_LIBRARIES ${ CUDA_cufft_LIBRARY } )
set ( CUDA_CUBLAS_LIBRARIES ${ CUDA_cublas_LIBRARY } ${ CUDA_cublas_device_LIBRARY } )
endif ( )
########################
# Look for the SDK stuff. As of CUDA 3.0 NVSDKCUDA_ROOT has been replaced with
# NVSDKCOMPUTE_ROOT with the old CUDA C contents moved into the C subdirectory
find_path ( CUDA_SDK_ROOT_DIR common/inc/cutil.h
H I N T S
" $ E N V { N V S D K C O M P U T E _ R O O T } / C "
E N V N V S D K C U D A _ R O O T
" [ H K E Y _ L O C A L _ M A C H I N E \ \ S O F T W A R E \ \ N V I D I A C o r p o r a t i o n \ \ I n s t a l l e d P r o d u c t s \ \ N V I D I A S D K 1 0 \ \ C o m p u t e ; I n s t a l l D i r ] "
P A T H S
" / D e v e l o p e r / G P U \ C o m p u t i n g / C "
)
# Keep the CUDA_SDK_ROOT_DIR first in order to be able to override the
# environment variables.
set ( CUDA_SDK_SEARCH_PATH
" $ { C U D A _ S D K _ R O O T _ D I R } "
" $ { C U D A _ T O O L K I T _ R O O T _ D I R } / l o c a l / N V S D K 0 . 2 "
" $ { C U D A _ T O O L K I T _ R O O T _ D I R } / N V S D K 0 . 2 "
" $ { C U D A _ T O O L K I T _ R O O T _ D I R } / N V _ C U D A _ S D K "
" $ E N V { H O M E } / N V I D I A _ C U D A _ S D K "
" $ E N V { H O M E } / N V I D I A _ C U D A _ S D K _ M A C O S X "
" / D e v e l o p e r / C U D A "
)
# Example of how to find an include file from the CUDA_SDK_ROOT_DIR
# find_path(CUDA_CUT_INCLUDE_DIR
# cutil.h
# PATHS ${CUDA_SDK_SEARCH_PATH}
# PATH_SUFFIXES "common/inc"
# DOC "Location of cutil.h"
# NO_DEFAULT_PATH
# )
# # Now search system paths
# find_path(CUDA_CUT_INCLUDE_DIR cutil.h DOC "Location of cutil.h")
# mark_as_advanced(CUDA_CUT_INCLUDE_DIR)
# Example of how to find a library in the CUDA_SDK_ROOT_DIR
# # cutil library is called cutil64 for 64 bit builds on windows. We don't want
# # to get these confused, so we are setting the name based on the word size of
# # the build.
# if(CMAKE_SIZEOF_VOID_P EQUAL 8)
# set(cuda_cutil_name cutil64)
# else()
# set(cuda_cutil_name cutil32)
# endif()
# find_library(CUDA_CUT_LIBRARY
# NAMES cutil ${cuda_cutil_name}
# PATHS ${CUDA_SDK_SEARCH_PATH}
# # The new version of the sdk shows up in common/lib, but the old one is in lib
# PATH_SUFFIXES "common/lib" "lib"
# DOC "Location of cutil library"
# NO_DEFAULT_PATH
# )
# # Now search system paths
# find_library(CUDA_CUT_LIBRARY NAMES cutil ${cuda_cutil_name} DOC "Location of cutil library")
# mark_as_advanced(CUDA_CUT_LIBRARY)
# set(CUDA_CUT_LIBRARIES ${CUDA_CUT_LIBRARY})
#############################
# Check for required components
set ( CUDA_FOUND TRUE )
set ( CUDA_TOOLKIT_ROOT_DIR_INTERNAL "${CUDA_TOOLKIT_ROOT_DIR}" CACHE INTERNAL
" T h i s i s t h e v a l u e o f t h e l a s t t i m e C U D A _ T O O L K I T _ R O O T _ D I R w a s s e t s u c c e s s f u l l y . " F O R C E )
set ( CUDA_TOOLKIT_TARGET_DIR_INTERNAL "${CUDA_TOOLKIT_TARGET_DIR}" CACHE INTERNAL
" T h i s i s t h e v a l u e o f t h e l a s t t i m e C U D A _ T O O L K I T _ T A R G E T _ D I R w a s s e t s u c c e s s f u l l y . " F O R C E )
set ( CUDA_SDK_ROOT_DIR_INTERNAL "${CUDA_SDK_ROOT_DIR}" CACHE INTERNAL
" T h i s i s t h e v a l u e o f t h e l a s t t i m e C U D A _ S D K _ R O O T _ D I R w a s s e t s u c c e s s f u l l y . " F O R C E )
include ( ${ CMAKE_CURRENT_LIST_DIR } /FindPackageHandleStandardArgs.cmake )
find_package_handle_standard_args ( CUDA
R E Q U I R E D _ V A R S
C U D A _ T O O L K I T _ R O O T _ D I R
C U D A _ N V C C _ E X E C U T A B L E
C U D A _ I N C L U D E _ D I R S
$ { C U D A _ C U D A R T _ L I B R A R Y _ V A R }
V E R S I O N _ V A R
C U D A _ V E R S I O N
)
###############################################################################
###############################################################################
# Macros
###############################################################################
###############################################################################
###############################################################################
# Add include directories to pass to the nvcc command.
macro ( CUDA_INCLUDE_DIRECTORIES )
foreach ( dir ${ ARGN } )
list ( APPEND CUDA_NVCC_INCLUDE_DIRS_USER ${ dir } )
endforeach ( )
endmacro ( )
##############################################################################
cuda_find_helper_file ( parse_cubin cmake )
cuda_find_helper_file ( make2cmake cmake )
cuda_find_helper_file ( run_nvcc cmake )
include ( "${CMAKE_CURRENT_LIST_DIR}/FindCUDA/select_compute_arch.cmake" )
##############################################################################
# Separate the OPTIONS out from the sources
#
macro ( CUDA_GET_SOURCES_AND_OPTIONS _sources _cmake_options _options )
set ( ${ _sources } )
set ( ${ _cmake_options } )
set ( ${ _options } )
set ( _found_options FALSE )
foreach ( arg ${ ARGN } )
if ( "x${arg}" STREQUAL "xOPTIONS" )
set ( _found_options TRUE )
elseif (
" x $ { a r g } " S T R E Q U A L " x W I N 3 2 " O R
" x $ { a r g } " S T R E Q U A L " x M A C O S X _ B U N D L E " O R
" x $ { a r g } " S T R E Q U A L " x E X C L U D E _ F R O M _ A L L " O R
" x $ { a r g } " S T R E Q U A L " x S T A T I C " O R
" x $ { a r g } " S T R E Q U A L " x S H A R E D " O R
" x $ { a r g } " S T R E Q U A L " x M O D U L E "
)
list ( APPEND ${ _cmake_options } ${ arg } )
else ( )
if ( _found_options )
list ( APPEND ${ _options } ${ arg } )
else ( )
# Assume this is a file
list ( APPEND ${ _sources } ${ arg } )
endif ( )
endif ( )
endforeach ( )
endmacro ( )
##############################################################################
# Parse the OPTIONS from ARGN and set the variables prefixed by _option_prefix
#
macro ( CUDA_PARSE_NVCC_OPTIONS _option_prefix )
set ( _found_config )
foreach ( arg ${ ARGN } )
# Determine if we are dealing with a perconfiguration flag
foreach ( config ${ CUDA_configuration_types } )
string ( TOUPPER ${ config } config_upper )
if ( arg STREQUAL "${config_upper}" )
set ( _found_config _ ${ arg } )
# Set arg to nothing to keep it from being processed further
set ( arg )
endif ( )
endforeach ( )
if ( arg )
list ( APPEND ${ _option_prefix } ${ _found_config } "${arg}" )
endif ( )
endforeach ( )
endmacro ( )
##############################################################################
# Helper to add the include directory for CUDA only once
function ( CUDA_ADD_CUDA_INCLUDE_ONCE )
get_directory_property ( _include_directories INCLUDE_DIRECTORIES )
set ( _add TRUE )
if ( _include_directories )
foreach ( dir ${ _include_directories } )
if ( "${dir}" STREQUAL "${CUDA_INCLUDE_DIRS}" )
set ( _add FALSE )
endif ( )
endforeach ( )
endif ( )
if ( _add )
include_directories ( ${ CUDA_INCLUDE_DIRS } )
endif ( )
endfunction ( )
function ( CUDA_BUILD_SHARED_LIBRARY shared_flag )
set ( cmake_args ${ ARGN } )
# If SHARED, MODULE, or STATIC aren't already in the list of arguments, then
# add SHARED or STATIC based on the value of BUILD_SHARED_LIBS.
list ( FIND cmake_args SHARED _cuda_found_SHARED )
list ( FIND cmake_args MODULE _cuda_found_MODULE )
list ( FIND cmake_args STATIC _cuda_found_STATIC )
if ( _cuda_found_SHARED GREATER -1 OR
_ c u d a _ f o u n d _ M O D U L E G R E A T E R - 1 O R
_ c u d a _ f o u n d _ S T A T I C G R E A T E R - 1 )
set ( _cuda_build_shared_libs )
else ( )
if ( BUILD_SHARED_LIBS )
set ( _cuda_build_shared_libs SHARED )
else ( )
set ( _cuda_build_shared_libs STATIC )
endif ( )
endif ( )
set ( ${ shared_flag } ${ _cuda_build_shared_libs } PARENT_SCOPE )
endfunction ( )
##############################################################################
# Helper to avoid clashes of files with the same basename but different paths.
# This doesn't attempt to do exactly what CMake internals do, which is to only
# add this path when there is a conflict, since by the time a second collision
# in names is detected it's already too late to fix the first one. For
# consistency sake the relative path will be added to all files.
function ( CUDA_COMPUTE_BUILD_PATH path build_path )
#message("CUDA_COMPUTE_BUILD_PATH([${path}] ${build_path})")
# Only deal with CMake style paths from here on out
file ( TO_CMAKE_PATH "${path}" bpath )
if ( IS_ABSOLUTE "${bpath}" )
# Absolute paths are generally unnessary, especially if something like
# file(GLOB_RECURSE) is used to pick up the files.
string ( FIND "${bpath}" "${CMAKE_CURRENT_BINARY_DIR}" _binary_dir_pos )
if ( _binary_dir_pos EQUAL 0 )
file ( RELATIVE_PATH bpath "${CMAKE_CURRENT_BINARY_DIR}" "${bpath}" )
else ( )
file ( RELATIVE_PATH bpath "${CMAKE_CURRENT_SOURCE_DIR}" "${bpath}" )
endif ( )
endif ( )
# This recipe is from cmLocalGenerator::CreateSafeUniqueObjectFileName in the
# CMake source.
# Remove leading /
string ( REGEX REPLACE "^[/]+" "" bpath "${bpath}" )
# Avoid absolute paths by removing ':'
string ( REPLACE ":" "_" bpath "${bpath}" )
# Avoid relative paths that go up the tree
string ( REPLACE "../" "__/" bpath "${bpath}" )
# Avoid spaces
string ( REPLACE " " "_" bpath "${bpath}" )
# Strip off the filename. I wait until here to do it, since removin the
# basename can make a path that looked like path/../basename turn into
# path/.. (notice the trailing slash).
get_filename_component ( bpath "${bpath}" PATH )
set ( ${ build_path } "${bpath}" PARENT_SCOPE )
#message("${build_path} = ${bpath}")
endfunction ( )
##############################################################################
# This helper macro populates the following variables and setups up custom
# commands and targets to invoke the nvcc compiler to generate C or PTX source
# dependent upon the format parameter. The compiler is invoked once with -M
# to generate a dependency file and a second time with -cuda or -ptx to generate
# a .cpp or .ptx file.
# INPUT:
# cuda_target - Target name
# format - PTX, CUBIN, FATBIN or OBJ
# FILE1 .. FILEN - The remaining arguments are the sources to be wrapped.
# OPTIONS - Extra options to NVCC
# OUTPUT:
# generated_files - List of generated files
##############################################################################
##############################################################################
macro ( CUDA_WRAP_SRCS cuda_target format generated_files )
# Put optional arguments in list.
set ( _argn_list "${ARGN}" )
# If one of the given optional arguments is "PHONY", make a note of it, then
# remove it from the list.
list ( FIND _argn_list "PHONY" _phony_idx )
if ( "${_phony_idx}" GREATER "-1" )
set ( _target_is_phony true )
list ( REMOVE_AT _argn_list ${ _phony_idx } )
else ( )
set ( _target_is_phony false )
endif ( )
# If CMake doesn't support separable compilation, complain
if ( CUDA_SEPARABLE_COMPILATION AND CMAKE_VERSION VERSION_LESS "2.8.10.1" )
message ( SEND_ERROR "CUDA_SEPARABLE_COMPILATION isn't supported for CMake versions less than 2.8.10.1" )
endif ( )
# Set up all the command line flags here, so that they can be overridden on a per target basis.
set ( nvcc_flags "" )
# Emulation if the card isn't present.
if ( CUDA_BUILD_EMULATION )
# Emulation.
set ( nvcc_flags ${ nvcc_flags } --device-emulation -D_DEVICEEMU -g )
else ( )
# Device mode. No flags necessary.
endif ( )
if ( CUDA_HOST_COMPILATION_CPP )
set ( CUDA_C_OR_CXX CXX )
else ( )
if ( CUDA_VERSION VERSION_LESS "3.0" )
set ( nvcc_flags ${ nvcc_flags } --host-compilation C )
else ( )
message ( WARNING "--host-compilation flag is deprecated in CUDA version >= 3.0. Removing --host-compilation C flag" )
endif ( )
set ( CUDA_C_OR_CXX C )
endif ( )
set ( generated_extension ${ CMAKE_${CUDA_C_OR_CXX } _OUTPUT_EXTENSION} )
if ( CUDA_64_BIT_DEVICE_CODE )
set ( nvcc_flags ${ nvcc_flags } -m64 )
else ( )
set ( nvcc_flags ${ nvcc_flags } -m32 )
endif ( )
if ( CUDA_TARGET_CPU_ARCH )
set ( nvcc_flags ${ nvcc_flags } "--target-cpu-architecture=${CUDA_TARGET_CPU_ARCH}" )
endif ( )
# This needs to be passed in at this stage, because VS needs to fill out the
# various macros from within VS. Note that CCBIN is only used if
# -ccbin or --compiler-bindir isn't used and CUDA_HOST_COMPILER matches
# _CUDA_MSVC_HOST_COMPILER
if ( CMAKE_GENERATOR MATCHES "Visual Studio" )
set ( ccbin_flags -D "\" CCBIN:PATH= ${ _CUDA_MSVC_HOST_COMPILER } \"" )
else ( )
set ( ccbin_flags )
endif ( )
# Figure out which configure we will use and pass that in as an argument to
# the script. We need to defer the decision until compilation time, because
# for VS projects we won't know if we are making a debug or release build
# until build time.
if ( CMAKE_GENERATOR MATCHES "Visual Studio" )
set ( CUDA_build_configuration "$(ConfigurationName)" )
else ( )
set ( CUDA_build_configuration "${CMAKE_BUILD_TYPE}" )
endif ( )
# Initialize our list of includes with the user ones followed by the CUDA system ones.
set ( CUDA_NVCC_INCLUDE_DIRS ${ CUDA_NVCC_INCLUDE_DIRS_USER } "${CUDA_INCLUDE_DIRS}" )
if ( _target_is_phony )
# If the passed in target name isn't a real target (i.e., this is from a call to one of the
# cuda_compile_* functions), need to query directory properties to get include directories
# and compile definitions.
get_directory_property ( _dir_include_dirs INCLUDE_DIRECTORIES )
get_directory_property ( _dir_compile_defs COMPILE_DEFINITIONS )
list ( APPEND CUDA_NVCC_INCLUDE_DIRS "${_dir_include_dirs}" )
set ( CUDA_NVCC_COMPILE_DEFINITIONS "${_dir_compile_defs}" )
else ( )
# Append the include directories for this target via generator expression, which is
# expanded by the FILE(GENERATE) call below. This generator expression captures all
# include dirs set by the user, whether via directory properties or target properties
list ( APPEND CUDA_NVCC_INCLUDE_DIRS "$<TARGET_PROPERTY:${cuda_target},INCLUDE_DIRECTORIES>" )
# Do the same thing with compile definitions
set ( CUDA_NVCC_COMPILE_DEFINITIONS "$<TARGET_PROPERTY:${cuda_target},COMPILE_DEFINITIONS>" )
endif ( )
# Reset these variables
set ( CUDA_WRAP_OPTION_NVCC_FLAGS )
foreach ( config ${ CUDA_configuration_types } )
string ( TOUPPER ${ config } config_upper )
set ( CUDA_WRAP_OPTION_NVCC_FLAGS_ ${ config_upper } )
endforeach ( )
CUDA_GET_SOURCES_AND_OPTIONS ( _cuda_wrap_sources _cuda_wrap_cmake_options _cuda_wrap_options ${ _argn_list } )
CUDA_PARSE_NVCC_OPTIONS ( CUDA_WRAP_OPTION_NVCC_FLAGS ${ _cuda_wrap_options } )
# Figure out if we are building a shared library. BUILD_SHARED_LIBS is
# respected in CUDA_ADD_LIBRARY.
set ( _cuda_build_shared_libs FALSE )
# SHARED, MODULE
list ( FIND _cuda_wrap_cmake_options SHARED _cuda_found_SHARED )
list ( FIND _cuda_wrap_cmake_options MODULE _cuda_found_MODULE )
if ( _cuda_found_SHARED GREATER -1 OR _cuda_found_MODULE GREATER -1 )
set ( _cuda_build_shared_libs TRUE )
endif ( )
# STATIC
list ( FIND _cuda_wrap_cmake_options STATIC _cuda_found_STATIC )
if ( _cuda_found_STATIC GREATER -1 )
set ( _cuda_build_shared_libs FALSE )
endif ( )
# CUDA_HOST_FLAGS
if ( _cuda_build_shared_libs )
# If we are setting up code for a shared library, then we need to add extra flags for
# compiling objects for shared libraries.
set ( CUDA_HOST_SHARED_FLAGS ${ CMAKE_SHARED_LIBRARY_${CUDA_C_OR_CXX } _FLAGS} )
else ( )
set ( CUDA_HOST_SHARED_FLAGS )
endif ( )
# Only add the CMAKE_{C,CXX}_FLAGS if we are propagating host flags. We
# always need to set the SHARED_FLAGS, though.
if ( CUDA_PROPAGATE_HOST_FLAGS )
set ( _cuda_host_flags "set(CMAKE_HOST_FLAGS ${CMAKE_${CUDA_C_OR_CXX}_FLAGS} ${CUDA_HOST_SHARED_FLAGS})" )
else ( )
set ( _cuda_host_flags "set(CMAKE_HOST_FLAGS ${CUDA_HOST_SHARED_FLAGS})" )
endif ( )
set ( _cuda_nvcc_flags_config "# Build specific configuration flags" )
# Loop over all the configuration types to generate appropriate flags for run_nvcc.cmake
foreach ( config ${ CUDA_configuration_types } )
string ( TOUPPER ${ config } config_upper )
# CMAKE_FLAGS are strings and not lists. By not putting quotes around CMAKE_FLAGS
# we convert the strings to lists (like we want).
if ( CUDA_PROPAGATE_HOST_FLAGS )
# nvcc chokes on -g3 in versions previous to 3.0, so replace it with -g
set ( _cuda_fix_g3 FALSE )
if ( CMAKE_COMPILER_IS_GNUCC )
if ( CUDA_VERSION VERSION_LESS "3.0" OR
C U D A _ V E R S I O N V E R S I O N _ E Q U A L " 4 . 1 " O R
C U D A _ V E R S I O N V E R S I O N _ E Q U A L " 4 . 2 "
)
set ( _cuda_fix_g3 TRUE )
endif ( )
endif ( )
if ( _cuda_fix_g3 )
string ( REPLACE "-g3" "-g" _cuda_C_FLAGS "${CMAKE_${CUDA_C_OR_CXX}_FLAGS_${config_upper}}" )
else ( )
set ( _cuda_C_FLAGS "${CMAKE_${CUDA_C_OR_CXX}_FLAGS_${config_upper}}" )
endif ( )
string ( APPEND _cuda_host_flags "\nset(CMAKE_HOST_FLAGS_${config_upper} ${_cuda_C_FLAGS})" )
endif ( )
# Note that if we ever want CUDA_NVCC_FLAGS_<CONFIG> to be string (instead of a list
# like it is currently), we can remove the quotes around the
# ${CUDA_NVCC_FLAGS_${config_upper}} variable like the CMAKE_HOST_FLAGS_<CONFIG> variable.
string ( APPEND _cuda_nvcc_flags_config "\nset(CUDA_NVCC_FLAGS_${config_upper} ${CUDA_NVCC_FLAGS_${config_upper}} ;; ${CUDA_WRAP_OPTION_NVCC_FLAGS_${config_upper}})" )
endforeach ( )
# Process the C++11 flag. If the host sets the flag, we need to add it to nvcc and
# remove it from the host. This is because -Xcompile -std=c++ will choke nvcc (it uses
# the C preprocessor). In order to get this to work correctly, we need to use nvcc's
# specific c++11 flag.
if ( "${_cuda_host_flags}" MATCHES "-std=c\\+\\+11" )
# Add the c++11 flag to nvcc if it isn't already present. Note that we only look at
# the main flag instead of the configuration specific flags.
if ( NOT "${CUDA_NVCC_FLAGS}" MATCHES "-std=c\\+\\+11" )
list ( APPEND nvcc_flags --std c++11 )
endif ( )
string ( REGEX REPLACE "[-]+std=c\\+\\+11" "" _cuda_host_flags "${_cuda_host_flags}" )
endif ( )
if ( _cuda_build_shared_libs )
list ( APPEND nvcc_flags "-D${cuda_target}_EXPORTS" )
endif ( )
# Reset the output variable
set ( _cuda_wrap_generated_files "" )
# Iterate over the macro arguments and create custom
# commands for all the .cu files.
foreach ( file ${ _argn_list } )
# Ignore any file marked as a HEADER_FILE_ONLY
get_source_file_property ( _is_header ${ file } HEADER_FILE_ONLY )
# Allow per source file overrides of the format. Also allows compiling non-.cu files.
get_source_file_property ( _cuda_source_format ${ file } CUDA_SOURCE_PROPERTY_FORMAT )
if ( ( ${ file } MATCHES "\\.cu$" OR _cuda_source_format ) AND NOT _is_header )
if ( NOT _cuda_source_format )
set ( _cuda_source_format ${ format } )
endif ( )
# If file isn't a .cu file, we need to tell nvcc to treat it as such.
if ( NOT ${ file } MATCHES "\\.cu$" )
set ( cuda_language_flag -x=cu )
else ( )
set ( cuda_language_flag )
endif ( )
if ( ${ _cuda_source_format } MATCHES "OBJ" )
set ( cuda_compile_to_external_module OFF )
else ( )
set ( cuda_compile_to_external_module ON )
if ( ${ _cuda_source_format } MATCHES "PTX" )
set ( cuda_compile_to_external_module_type "ptx" )
elseif ( ${ _cuda_source_format } MATCHES "CUBIN" )
set ( cuda_compile_to_external_module_type "cubin" )
elseif ( ${ _cuda_source_format } MATCHES "FATBIN" )
set ( cuda_compile_to_external_module_type "fatbin" )
else ( )
message ( FATAL_ERROR "Invalid format flag passed to CUDA_WRAP_SRCS or set with CUDA_SOURCE_PROPERTY_FORMAT file property for file '${file}': '${_cuda_source_format}'. Use OBJ, PTX, CUBIN or FATBIN." )
endif ( )
endif ( )
if ( cuda_compile_to_external_module )
# Don't use any of the host compilation flags for PTX targets.
set ( CUDA_HOST_FLAGS )
set ( CUDA_NVCC_FLAGS_CONFIG )
else ( )
set ( CUDA_HOST_FLAGS ${ _cuda_host_flags } )
set ( CUDA_NVCC_FLAGS_CONFIG ${ _cuda_nvcc_flags_config } )
endif ( )
# Determine output directory
cuda_compute_build_path ( "${file}" cuda_build_path )
set ( cuda_compile_intermediate_directory "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${cuda_target}.dir/${cuda_build_path}" )
if ( CUDA_GENERATED_OUTPUT_DIR )
set ( cuda_compile_output_dir "${CUDA_GENERATED_OUTPUT_DIR}" )
else ( )
if ( cuda_compile_to_external_module )
set ( cuda_compile_output_dir "${CMAKE_CURRENT_BINARY_DIR}" )
else ( )
set ( cuda_compile_output_dir "${cuda_compile_intermediate_directory}" )
endif ( )
endif ( )
# Add a custom target to generate a c or ptx file. ######################
get_filename_component ( basename ${ file } NAME )
if ( cuda_compile_to_external_module )
set ( generated_file_path "${cuda_compile_output_dir}" )
set ( generated_file_basename "${cuda_target}_generated_${basename}.${cuda_compile_to_external_module_type}" )
set ( format_flag "-${cuda_compile_to_external_module_type}" )
file ( MAKE_DIRECTORY "${cuda_compile_output_dir}" )
else ( )
set ( generated_file_path "${cuda_compile_output_dir}/${CMAKE_CFG_INTDIR}" )
set ( generated_file_basename "${cuda_target}_generated_${basename}${generated_extension}" )
if ( CUDA_SEPARABLE_COMPILATION )
set ( format_flag "-dc" )
else ( )
set ( format_flag "-c" )
endif ( )
endif ( )
# Set all of our file names. Make sure that whatever filenames that have
# generated_file_path in them get passed in through as a command line
# argument, so that the ${CMAKE_CFG_INTDIR} gets expanded at run time
# instead of configure time.
set ( generated_file "${generated_file_path}/${generated_file_basename}" )
set ( cmake_dependency_file "${cuda_compile_intermediate_directory}/${generated_file_basename}.depend" )
set ( NVCC_generated_dependency_file "${cuda_compile_intermediate_directory}/${generated_file_basename}.NVCC-depend" )
set ( generated_cubin_file "${generated_file_path}/${generated_file_basename}.cubin.txt" )
set ( custom_target_script_pregen "${cuda_compile_intermediate_directory}/${generated_file_basename}.cmake.pre-gen" )
set ( custom_target_script "${cuda_compile_intermediate_directory}/${generated_file_basename}$<$<BOOL:$<CONFIG>>:.$<CONFIG>>.cmake" )
# Setup properties for obj files:
if ( NOT cuda_compile_to_external_module )
set_source_files_properties ( "${generated_file}"
P R O P E R T I E S
E X T E R N A L _ O B J E C T t r u e # This is an object file not to be compiled, but only be linked.
)
endif ( )
# Don't add CMAKE_CURRENT_SOURCE_DIR if the path is already an absolute path.
get_filename_component ( file_path "${file}" PATH )
if ( IS_ABSOLUTE "${file_path}" )
set ( source_file "${file}" )
else ( )
set ( source_file "${CMAKE_CURRENT_SOURCE_DIR}/${file}" )
endif ( )
if ( NOT cuda_compile_to_external_module AND CUDA_SEPARABLE_COMPILATION )
list ( APPEND ${ cuda_target } _SEPARABLE_COMPILATION_OBJECTS "${generated_file}" )
endif ( )
# Bring in the dependencies. Creates a variable CUDA_NVCC_DEPEND #######
cuda_include_nvcc_dependencies ( ${ cmake_dependency_file } )
# Convenience string for output #########################################
if ( CUDA_BUILD_EMULATION )
set ( cuda_build_type "Emulation" )
else ( )
set ( cuda_build_type "Device" )
endif ( )
# Build the NVCC made dependency file ###################################
set ( build_cubin OFF )
if ( NOT CUDA_BUILD_EMULATION AND CUDA_BUILD_CUBIN )
if ( NOT cuda_compile_to_external_module )
set ( build_cubin ON )
endif ( )
endif ( )
# Configure the build script
configure_file ( "${CUDA_run_nvcc}" "${custom_target_script_pregen}" @ONLY )
file ( GENERATE
O U T P U T " $ { c u s t o m _ t a r g e t _ s c r i p t } "
I N P U T " $ { c u s t o m _ t a r g e t _ s c r i p t _ p r e g e n } "
)
# So if a user specifies the same cuda file as input more than once, you
# can have bad things happen with dependencies. Here we check an option
# to see if this is the behavior they want.
if ( CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE )
set ( main_dep MAIN_DEPENDENCY ${ source_file } )
else ( )
set ( main_dep DEPENDS ${ source_file } )
endif ( )
if ( CUDA_VERBOSE_BUILD )
set ( verbose_output ON )
elseif ( CMAKE_GENERATOR MATCHES "Makefiles" )
set ( verbose_output "$(VERBOSE)" )
else ( )
set ( verbose_output OFF )
endif ( )
# Create up the comment string
file ( RELATIVE_PATH generated_file_relative_path "${CMAKE_BINARY_DIR}" "${generated_file}" )
if ( cuda_compile_to_external_module )
set ( cuda_build_comment_string "Building NVCC ${cuda_compile_to_external_module_type} file ${generated_file_relative_path}" )
else ( )
set ( cuda_build_comment_string "Building NVCC (${cuda_build_type}) object ${generated_file_relative_path}" )
endif ( )
set ( _verbatim VERBATIM )
if ( ccbin_flags MATCHES "\\$\\(VCInstallDir\\)" )
set ( _verbatim "" )
endif ( )
# Build the generated file and dependency file ##########################
add_custom_command (
O U T P U T $ { g e n e r a t e d _ f i l e }
# These output files depend on the source_file and the contents of cmake_dependency_file
$ { m a i n _ d e p }
D E P E N D S $ { C U D A _ N V C C _ D E P E N D }
D E P E N D S $ { c u s t o m _ t a r g e t _ s c r i p t }
# Make sure the output directory exists before trying to write to it.
C O M M A N D $ { C M A K E _ C O M M A N D } - E m a k e _ d i r e c t o r y " $ { g e n e r a t e d _ f i l e _ p a t h } "
C O M M A N D $ { C M A K E _ C O M M A N D } A R G S
- D v e r b o s e : B O O L = $ { v e r b o s e _ o u t p u t }
$ { c c b i n _ f l a g s }
- D b u i l d _ c o n f i g u r a t i o n : S T R I N G = $ { C U D A _ b u i l d _ c o n f i g u r a t i o n }
- D " g e n e r a t e d _ f i l e : S T R I N G = $ { g e n e r a t e d _ f i l e } "
- D " g e n e r a t e d _ c u b i n _ f i l e : S T R I N G = $ { g e n e r a t e d _ c u b i n _ f i l e } "
- P " $ { c u s t o m _ t a r g e t _ s c r i p t } "
W O R K I N G _ D I R E C T O R Y " $ { c u d a _ c o m p i l e _ i n t e r m e d i a t e _ d i r e c t o r y } "
C O M M E N T " $ { c u d a _ b u i l d _ c o m m e n t _ s t r i n g } "
$ { _ v e r b a t i m }
)
# Make sure the build system knows the file is generated.
set_source_files_properties ( ${ generated_file } PROPERTIES GENERATED TRUE )
list ( APPEND _cuda_wrap_generated_files ${ generated_file } )
# Add the other files that we want cmake to clean on a cleanup ##########
list ( APPEND CUDA_ADDITIONAL_CLEAN_FILES "${cmake_dependency_file}" )
list ( REMOVE_DUPLICATES CUDA_ADDITIONAL_CLEAN_FILES )
set ( CUDA_ADDITIONAL_CLEAN_FILES ${ CUDA_ADDITIONAL_CLEAN_FILES } CACHE INTERNAL "List of intermediate files that are part of the cuda dependency scanning." )
endif ( )
endforeach ( )
# Set the return parameter
set ( ${ generated_files } ${ _cuda_wrap_generated_files } )
endmacro ( )
function ( _cuda_get_important_host_flags important_flags flag_string )
if ( CMAKE_GENERATOR MATCHES "Visual Studio" )
string ( REGEX MATCHALL "/M[DT][d]?" flags "${flag_string}" )
list ( APPEND ${ important_flags } ${ flags } )
else ( )
string ( REGEX MATCHALL "-fPIC" flags "${flag_string}" )
list ( APPEND ${ important_flags } ${ flags } )
endif ( )
set ( ${ important_flags } ${ ${important_flags } } PARENT_SCOPE )
endfunction ( )
###############################################################################
###############################################################################
# Separable Compilation Link
###############################################################################
###############################################################################
# Compute the filename to be used by CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS
function ( CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME output_file_var cuda_target object_files )
if ( object_files )
set ( generated_extension ${ CMAKE_${CUDA_C_OR_CXX } _OUTPUT_EXTENSION} )
set ( output_file "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${cuda_target}.dir/${CMAKE_CFG_INTDIR}/${cuda_target}_intermediate_link${generated_extension}" )
else ( )
set ( output_file )
endif ( )
set ( ${ output_file_var } "${output_file}" PARENT_SCOPE )
endfunction ( )
# Setup the build rule for the separable compilation intermediate link file.
function ( CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS output_file cuda_target options object_files )
if ( object_files )
set_source_files_properties ( "${output_file}"
P R O P E R T I E S
E X T E R N A L _ O B J E C T T R U E # This is an object file not to be compiled, but only
# be linked.
G E N E R A T E D T R U E # This file is generated during the build
)
# For now we are ignoring all the configuration specific flags.
set ( nvcc_flags )
CUDA_PARSE_NVCC_OPTIONS ( nvcc_flags ${ options } )
if ( CUDA_64_BIT_DEVICE_CODE )
list ( APPEND nvcc_flags -m64 )
else ( )
list ( APPEND nvcc_flags -m32 )
endif ( )
# If -ccbin, --compiler-bindir has been specified, don't do anything. Otherwise add it here.
list ( FIND nvcc_flags "-ccbin" ccbin_found0 )
list ( FIND nvcc_flags "--compiler-bindir" ccbin_found1 )
if ( ccbin_found0 LESS 0 AND ccbin_found1 LESS 0 AND CUDA_HOST_COMPILER )
# Match VERBATIM check below.
if ( CUDA_HOST_COMPILER MATCHES "\\$\\(VCInstallDir\\)" )
list ( APPEND nvcc_flags -ccbin "\" ${ CUDA_HOST_COMPILER } \"")
else ( )
list ( APPEND nvcc_flags -ccbin "${CUDA_HOST_COMPILER}" )
endif ( )
endif ( )
# Create a list of flags specified by CUDA_NVCC_FLAGS_${CONFIG} and CMAKE_${CUDA_C_OR_CXX}_FLAGS*
set ( config_specific_flags )
set ( flags )
foreach ( config ${ CUDA_configuration_types } )
string ( TOUPPER ${ config } config_upper )
# Add config specific flags
foreach ( f ${ CUDA_NVCC_FLAGS_${config_upper } } )
list ( APPEND config_specific_flags $< $<CONFIG:${config} > : ${ f } > )
endforeach ( )
set ( important_host_flags )
_cuda_get_important_host_flags ( important_host_flags "${CMAKE_${CUDA_C_OR_CXX}_FLAGS_${config_upper}}" )
foreach ( f ${ important_host_flags } )
list ( APPEND flags $< $<CONFIG:${config} > :-Xcompiler> $< $<CONFIG:${config} > : ${ f } > )
endforeach ( )
endforeach ( )
# Add CMAKE_${CUDA_C_OR_CXX}_FLAGS
set ( important_host_flags )
_cuda_get_important_host_flags ( important_host_flags "${CMAKE_${CUDA_C_OR_CXX}_FLAGS}" )
foreach ( f ${ important_host_flags } )
list ( APPEND flags -Xcompiler ${ f } )
endforeach ( )
# Add our general CUDA_NVCC_FLAGS with the configuration specifig flags
set ( nvcc_flags ${ CUDA_NVCC_FLAGS } ${ config_specific_flags } ${ nvcc_flags } )
file ( RELATIVE_PATH output_file_relative_path "${CMAKE_BINARY_DIR}" "${output_file}" )
# Some generators don't handle the multiple levels of custom command
# dependencies correctly (obj1 depends on file1, obj2 depends on obj1), so
# we work around that issue by compiling the intermediate link object as a
# pre-link custom command in that situation.
set ( do_obj_build_rule TRUE )
if ( MSVC_VERSION GREATER 1599 AND MSVC_VERSION LESS 1800 )
# VS 2010 and 2012 have this problem.
set ( do_obj_build_rule FALSE )
endif ( )
set ( _verbatim VERBATIM )
if ( nvcc_flags MATCHES "\\$\\(VCInstallDir\\)" )
set ( _verbatim "" )
endif ( )
if ( do_obj_build_rule )
add_custom_command (
O U T P U T $ { o u t p u t _ f i l e }
D E P E N D S $ { o b j e c t _ f i l e s }
C O M M A N D $ { C U D A _ N V C C _ E X E C U T A B L E } $ { n v c c _ f l a g s } - d l i n k $ { o b j e c t _ f i l e s } - o $ { o u t p u t _ f i l e }
$ { f l a g s }
C O M M E N T " B u i l d i n g N V C C i n t e r m e d i a t e l i n k f i l e $ { o u t p u t _ f i l e _ r e l a t i v e _ p a t h } "
C O M M A N D _ E X P A N D _ L I S T S
$ { _ v e r b a t i m }
)
else ( )
get_filename_component ( output_file_dir "${output_file}" DIRECTORY )
add_custom_command (
T A R G E T $ { c u d a _ t a r g e t }
P R E _ L I N K
C O M M A N D $ { C M A K E _ C O M M A N D } - E e c h o " B u i l d i n g N V C C i n t e r m e d i a t e l i n k f i l e $ { o u t p u t _ f i l e _ r e l a t i v e _ p a t h } "
C O M M A N D $ { C M A K E _ C O M M A N D } - E m a k e _ d i r e c t o r y " $ { o u t p u t _ f i l e _ d i r } "
C O M M A N D $ { C U D A _ N V C C _ E X E C U T A B L E } $ { n v c c _ f l a g s } $ { f l a g s } - d l i n k $ { o b j e c t _ f i l e s } - o " $ { o u t p u t _ f i l e } "
C O M M A N D _ E X P A N D _ L I S T S
$ { _ v e r b a t i m }
)
endif ( )
endif ( )
endfunction ( )
###############################################################################
###############################################################################
# ADD LIBRARY
###############################################################################
###############################################################################
macro ( CUDA_ADD_LIBRARY cuda_target )
CUDA_ADD_CUDA_INCLUDE_ONCE ( )
# Separate the sources from the options
CUDA_GET_SOURCES_AND_OPTIONS ( _sources _cmake_options _options ${ ARGN } )
CUDA_BUILD_SHARED_LIBRARY ( _cuda_shared_flag ${ ARGN } )
# Create custom commands and targets for each file.
CUDA_WRAP_SRCS ( ${ cuda_target } OBJ _generated_files ${ _sources }
$ { _ c m a k e _ o p t i o n s } $ { _ c u d a _ s h a r e d _ f l a g }
O P T I O N S $ { _ o p t i o n s } )
# Compute the file name of the intermedate link file used for separable
# compilation.
CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME ( link_file ${ cuda_target } "${${cuda_target}_SEPARABLE_COMPILATION_OBJECTS}" )
# Add the library.
add_library ( ${ cuda_target } ${ _cmake_options }
$ { _ g e n e r a t e d _ f i l e s }
$ { _ s o u r c e s }
$ { l i n k _ f i l e }
)
# Add a link phase for the separable compilation if it has been enabled. If
# it has been enabled then the ${cuda_target}_SEPARABLE_COMPILATION_OBJECTS
# variable will have been defined.
CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS ( "${link_file}" ${ cuda_target } "${_options}" "${${cuda_target}_SEPARABLE_COMPILATION_OBJECTS}" )
target_link_libraries ( ${ cuda_target } ${ CUDA_LINK_LIBRARIES_KEYWORD }
$ { C U D A _ L I B R A R I E S }
)
if ( CUDA_SEPARABLE_COMPILATION )
target_link_libraries ( ${ cuda_target } ${ CUDA_LINK_LIBRARIES_KEYWORD }
$ { C U D A _ c u d a d e v r t _ L I B R A R Y }
)
endif ( )
# We need to set the linker language based on what the expected generated file
# would be. CUDA_C_OR_CXX is computed based on CUDA_HOST_COMPILATION_CPP.
set_target_properties ( ${ cuda_target }
P R O P E R T I E S
L I N K E R _ L A N G U A G E $ { C U D A _ C _ O R _ C X X }
)
endmacro ( )
###############################################################################
###############################################################################
# ADD EXECUTABLE
###############################################################################
###############################################################################
macro ( CUDA_ADD_EXECUTABLE cuda_target )
CUDA_ADD_CUDA_INCLUDE_ONCE ( )
# Separate the sources from the options
CUDA_GET_SOURCES_AND_OPTIONS ( _sources _cmake_options _options ${ ARGN } )
# Create custom commands and targets for each file.
CUDA_WRAP_SRCS ( ${ cuda_target } OBJ _generated_files ${ _sources } OPTIONS ${ _options } )
# Compute the file name of the intermedate link file used for separable
# compilation.
CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME ( link_file ${ cuda_target } "${${cuda_target}_SEPARABLE_COMPILATION_OBJECTS}" )
# Add the library.
add_executable ( ${ cuda_target } ${ _cmake_options }
$ { _ g e n e r a t e d _ f i l e s }
$ { _ s o u r c e s }
$ { l i n k _ f i l e }
)
# Add a link phase for the separable compilation if it has been enabled. If
# it has been enabled then the ${cuda_target}_SEPARABLE_COMPILATION_OBJECTS
# variable will have been defined.
CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS ( "${link_file}" ${ cuda_target } "${_options}" "${${cuda_target}_SEPARABLE_COMPILATION_OBJECTS}" )
target_link_libraries ( ${ cuda_target } ${ CUDA_LINK_LIBRARIES_KEYWORD }
$ { C U D A _ L I B R A R I E S }
)
# We need to set the linker language based on what the expected generated file
# would be. CUDA_C_OR_CXX is computed based on CUDA_HOST_COMPILATION_CPP.
set_target_properties ( ${ cuda_target }
P R O P E R T I E S
L I N K E R _ L A N G U A G E $ { C U D A _ C _ O R _ C X X }
)
endmacro ( )
###############################################################################
###############################################################################
# (Internal) helper for manually added cuda source files with specific targets
###############################################################################
###############################################################################
macro ( cuda_compile_base cuda_target format generated_files )
# Update a counter in this directory, to keep phony target names unique.
set ( _cuda_target "${cuda_target}" )
get_property ( _counter DIRECTORY PROPERTY _cuda_internal_phony_counter )
if ( _counter )
math ( EXPR _counter "${_counter} + 1" )
else ( )
set ( _counter 1 )
endif ( )
string ( APPEND _cuda_target "_${_counter}" )
set_property ( DIRECTORY PROPERTY _cuda_internal_phony_counter ${ _counter } )
# Separate the sources from the options
CUDA_GET_SOURCES_AND_OPTIONS ( _sources _cmake_options _options ${ ARGN } )
# Create custom commands and targets for each file.
CUDA_WRAP_SRCS ( ${ _cuda_target } ${ format } _generated_files ${ _sources }
$ { _ c m a k e _ o p t i o n s } O P T I O N S $ { _ o p t i o n s } P H O N Y )
set ( ${ generated_files } ${ _generated_files } )
endmacro ( )
###############################################################################
###############################################################################
# CUDA COMPILE
###############################################################################
###############################################################################
macro ( CUDA_COMPILE generated_files )
cuda_compile_base ( cuda_compile OBJ ${ generated_files } ${ ARGN } )
endmacro ( )
###############################################################################
###############################################################################
# CUDA COMPILE PTX
###############################################################################
###############################################################################
macro ( CUDA_COMPILE_PTX generated_files )
cuda_compile_base ( cuda_compile_ptx PTX ${ generated_files } ${ ARGN } )
endmacro ( )
###############################################################################
###############################################################################
# CUDA COMPILE FATBIN
###############################################################################
###############################################################################
macro ( CUDA_COMPILE_FATBIN generated_files )
cuda_compile_base ( cuda_compile_fatbin FATBIN ${ generated_files } ${ ARGN } )
endmacro ( )
###############################################################################
###############################################################################
# CUDA COMPILE CUBIN
###############################################################################
###############################################################################
macro ( CUDA_COMPILE_CUBIN generated_files )
cuda_compile_base ( cuda_compile_cubin CUBIN ${ generated_files } ${ ARGN } )
endmacro ( )
###############################################################################
###############################################################################
# CUDA ADD CUFFT TO TARGET
###############################################################################
###############################################################################
macro ( CUDA_ADD_CUFFT_TO_TARGET target )
if ( CUDA_BUILD_EMULATION )
target_link_libraries ( ${ target } ${ CUDA_LINK_LIBRARIES_KEYWORD } ${ CUDA_cufftemu_LIBRARY } )
else ( )
target_link_libraries ( ${ target } ${ CUDA_LINK_LIBRARIES_KEYWORD } ${ CUDA_cufft_LIBRARY } )
endif ( )
endmacro ( )
###############################################################################
###############################################################################
# CUDA ADD CUBLAS TO TARGET
###############################################################################
###############################################################################
macro ( CUDA_ADD_CUBLAS_TO_TARGET target )
if ( CUDA_BUILD_EMULATION )
target_link_libraries ( ${ target } ${ CUDA_LINK_LIBRARIES_KEYWORD } ${ CUDA_cublasemu_LIBRARY } )
else ( )
target_link_libraries ( ${ target } ${ CUDA_LINK_LIBRARIES_KEYWORD } ${ CUDA_cublas_LIBRARY } ${ CUDA_cublas_device_LIBRARY } )
endif ( )
endmacro ( )
###############################################################################
###############################################################################
# CUDA BUILD CLEAN TARGET
###############################################################################
###############################################################################
macro ( CUDA_BUILD_CLEAN_TARGET )
# Call this after you add all your CUDA targets, and you will get a
# convenience target. You should also make clean after running this target
# to get the build system to generate all the code again.
set ( cuda_clean_target_name clean_cuda_depends )
if ( CMAKE_GENERATOR MATCHES "Visual Studio" )
string ( TOUPPER ${ cuda_clean_target_name } cuda_clean_target_name )
endif ( )
add_custom_target ( ${ cuda_clean_target_name }
2023-11-01 06:34:31 +08:00
C O M M A N D $ { C M A K E _ C O M M A N D } - E r m - f $ { C U D A _ A D D I T I O N A L _ C L E A N _ F I L E S } )
2023-11-01 06:11:15 +08:00
# Clear out the variable, so the next time we configure it will be empty.
# This is useful so that the files won't persist in the list after targets
# have been removed.
set ( CUDA_ADDITIONAL_CLEAN_FILES "" CACHE INTERNAL "List of intermediate files that are part of the cuda dependency scanning." )
endmacro ( )