CMakeLists.txt 6.17 KB
Newer Older
1
include_directories(BEFORE
Chao Liu's avatar
Chao Liu committed
2
3
    ${PROJECT_SOURCE_DIR}/include
    ${PROJECT_SOURCE_DIR}/library/include
4
5
)

Chao Liu's avatar
Chao Liu committed
6
add_custom_target(examples)
7

8
9
10
11
12
13
function(add_example_dependencies EXAMPLE_NAME FILE_NAME)
    if(FILE_NAME)
        add_dependencies(EXAMPLE_NAME FILE_NAME)
    endif()
endfunction(add_example_dependencies EXAMPLE_NAME)

Anthony Chang's avatar
Anthony Chang committed
14
function(add_example_executable EXAMPLE_NAME FILE_NAME)
Chao Liu's avatar
Chao Liu committed
15
    message("adding example ${EXAMPLE_NAME}")
16
17
18
19
    set(result 1)
    if(DEFINED DTYPES)
    foreach(source IN LISTS FILE_NAME)
        set(test 0)
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
        if((source MATCHES "_fp16" OR source MATCHES "_f16") AND NOT "fp16" IN_LIST DTYPES)
            set(test 1)
        endif()
        if((source MATCHES "_fp32" OR source MATCHES "_f32") AND NOT "fp32" IN_LIST DTYPES)
            set(test 1)
        endif()
        if((source MATCHES "_fp64" OR source MATCHES "_f64") AND NOT "fp64" IN_LIST DTYPES)
            set(test 1)
        endif()
        if((source MATCHES "_fp8" OR source MATCHES "_f8") AND NOT "fp8" IN_LIST DTYPES)
            set(test 1)
        endif()
        if((source MATCHES "_bf8" OR source MATCHES "_bf8") AND NOT "bf8" IN_LIST DTYPES)
            set(test 1)
        endif()
        if((source MATCHES "_bf16" OR source MATCHES "_b16") AND NOT "bf16" IN_LIST DTYPES)
            set(test 1)
        endif()
        if((source MATCHES "_int8" OR source MATCHES "_i8") AND NOT "int8" IN_LIST DTYPES)
            set(test 1)
        endif()
41
42
43
44
45
46
        if(test EQUAL 1)
            message("removing example source file ${source} ")
            list(REMOVE_ITEM FILE_NAME "${source}")
        endif()
    endforeach()
    endif()
47
    #Do not build any DL examples if DL_KERNELS not set
48
49
50
51
52
53
    foreach(source IN LISTS FILE_NAME)
        if(NOT DEFINED DL_KERNELS AND source MATCHES "_dl")
            message("removing dl example ${source} ")
            list(REMOVE_ITEM FILE_NAME "${source}")
        endif()
    endforeach()
54
55
56
57
58
59
60
61
62
63
64
65
66
67
    #Do not build any XDL examples if gfx9 targets are not on the list
    foreach(source IN LISTS FILE_NAME)
        if(NOT GPU_TARGETS MATCHES "gfx9" AND source MATCHES "_xdl")
            message("removing xdl example ${source} ")
            list(REMOVE_ITEM FILE_NAME "${source}")
        endif()
    endforeach()
    #Do not build any WMMA examples if gfx11 targets are not on the list
    foreach(source IN LISTS FILE_NAME)
        if(NOT GPU_TARGETS MATCHES "gfx11" AND source MATCHES "_wmma")
            message("removing wmma example ${source} ")
            list(REMOVE_ITEM FILE_NAME "${source}")
        endif()
    endforeach()
68
69
70
71
72
73
74
75
76
77
78
    #only continue if there are some source files left on the list
    if(FILE_NAME)
        add_executable(${EXAMPLE_NAME} ${FILE_NAME})
        target_link_libraries(${EXAMPLE_NAME} PRIVATE utility)
        add_test(NAME ${EXAMPLE_NAME} COMMAND $<TARGET_FILE:${EXAMPLE_NAME}> ${ARGN})
        add_dependencies(examples ${EXAMPLE_NAME})
        add_dependencies(check ${EXAMPLE_NAME})
        rocm_install(TARGETS ${EXAMPLE_NAME} COMPONENT examples)
        set(result 0)
    endif()
    #message("add_example returns ${result}")
79
    set(result ${result} PARENT_SCOPE)
Anthony Chang's avatar
Anthony Chang committed
80
81
endfunction(add_example_executable EXAMPLE_NAME)

82
83
84
85
86
87
function(add_example_dependencies EXAMPLE_NAME FILE_NAME)
    if(result EQUAL 0)
        add_dependencies(${EXAMPLE_NAME} ${FILE_NAME})
    endif()
endfunction(add_example_dependencies EXAMPLE_NAME)

Anthony Chang's avatar
Anthony Chang committed
88
89
function(add_example_executable_no_testing EXAMPLE_NAME FILE_NAME)
    message("adding example ${EXAMPLE_NAME}")
90
91
92
93
    set(result 1)
    if(DEFINED DTYPES)
    foreach(source IN LISTS FILE_NAME)
        set(test 0)
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
        if((source MATCHES "_fp16" OR source MATCHES "_f16") AND NOT "fp16" IN_LIST DTYPES)
            set(test 1)
        endif()
        if((source MATCHES "_fp32" OR source MATCHES "_f32") AND NOT "fp32" IN_LIST DTYPES)
            set(test 1)
        endif()
        if((source MATCHES "_fp64" OR source MATCHES "_f64") AND NOT "fp64" IN_LIST DTYPES)
            set(test 1)
        endif()
        if((source MATCHES "_fp8" OR source MATCHES "_f8") AND NOT "fp8" IN_LIST DTYPES)
            set(test 1)
        endif()
        if((source MATCHES "_bf8" OR source MATCHES "_bf8") AND NOT "bf8" IN_LIST DTYPES)
            set(test 1)
        endif()
        if((source MATCHES "_bf16" OR source MATCHES "_b16") AND NOT "bf16" IN_LIST DTYPES)
            set(test 1)
        endif()
        if((source MATCHES "_int8" OR source MATCHES "_i8") AND NOT "int8" IN_LIST DTYPES)
            set(test 1)
        endif()
115
116
117
        if(test EQUAL 1)
            message("removing example ${source} ")
            list(REMOVE_ITEM FILE_NAME "${source}")
118
        endif()
119
120
    endforeach()
    endif()
121
    #Do not build any DL examples if DL_KERNELS not set
122
123
124
125
126
127
    foreach(source IN LISTS FILE_NAME)
        if(NOT DEFINED DL_KERNELS AND source MATCHES "_dl")
            message("removing dl example ${source} ")
            list(REMOVE_ITEM FILE_NAME "${source}")
        endif()
    endforeach()
128
129
130
131
132
133
134
135
136
137
138
139
140
141
    #Do not build any XDL examples if gfx9 targets are not on the list
    foreach(source IN LISTS FILE_NAME)
        if(NOT GPU_TARGETS MATCHES "gfx9" AND source MATCHES "_xdl")
            message("removing xdl example ${source} ")
            list(REMOVE_ITEM FILE_NAME "${source}")
        endif()
    endforeach()
    #Do not build any WMMA examples if gfx11 targets are not on the list
    foreach(source IN LISTS FILE_NAME)
        if(NOT GPU_TARGETS MATCHES "gfx11" AND source MATCHES "_wmma")
            message("removing wmma example ${source} ")
            list(REMOVE_ITEM FILE_NAME "${source}")
        endif()
    endforeach()
142
143
144
145
146
147
148
149
150
    #only continue if there are some source files left on the list
    if(FILE_NAME)
        add_executable(${EXAMPLE_NAME} ${FILE_NAME})
        target_link_libraries(${EXAMPLE_NAME} PRIVATE utility)
        add_dependencies(examples ${EXAMPLE_NAME})
        rocm_install(TARGETS ${EXAMPLE_NAME} COMPONENT examples)
        set(result 0)
    endif()
    #message("add_example returns ${result}")
151
    set(result ${result} PARENT_SCOPE)
rocking5566's avatar
rocking5566 committed
152
endfunction(add_example_executable_no_testing EXAMPLE_NAME)
153

Shaojie WANG's avatar
Shaojie WANG committed
154
155
156
157
158
159
160
# add all example subdir
file(GLOB dir_list LIST_DIRECTORIES true *)
FOREACH(subdir ${dir_list})
    IF(IS_DIRECTORY "${subdir}")
        add_subdirectory(${subdir})
    ENDIF()
ENDFOREACH()