CMakeLists.txt 9.62 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
set(REGRESSION_EXAMPLES
    example_sparse_embedding3_forward_layernorm
)


13
14
15
16
17
18
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
19
function(add_example_executable EXAMPLE_NAME FILE_NAME)
Chao Liu's avatar
Chao Liu committed
20
    message("adding example ${EXAMPLE_NAME}")
21
22
23
24
    set(result 1)
    if(DEFINED DTYPES)
    foreach(source IN LISTS FILE_NAME)
        set(test 0)
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
        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()
46
47
48
49
50
51
        if(test EQUAL 1)
            message("removing example source file ${source} ")
            list(REMOVE_ITEM FILE_NAME "${source}")
        endif()
    endforeach()
    endif()
52

53
    set(EX_TARGETS ${SUPPORTED_GPU_TARGETS})
54

55
    #Do not build any DL examples if DL_KERNELS not set
56
57
58
59
60
61
    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()
62
    #Do not build any DPP examples if DPP_KERNELS not set
63
    foreach(source IN LISTS FILE_NAME)
64
        if(NOT DEFINED DPP_KERNELS AND source MATCHES "_dpp")
65
66
67
68
            message("removing dpp example ${source} ")
            list(REMOVE_ITEM FILE_NAME "${source}")
        endif()
    endforeach()
69
70
    #Do not build any XDL examples if gfx9 targets are not on the list
    foreach(source IN LISTS FILE_NAME)
71
        if(NOT EX_TARGETS MATCHES "gfx9" AND source MATCHES "_xdl")
72
73
74
75
76
77
            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)
78
	if(NOT EX_TARGETS MATCHES "gfx11" AND NOT EX_TARGETS MATCHES "gfx12" AND source MATCHES "_wmma")
79
80
81
82
            message("removing wmma example ${source} ")
            list(REMOVE_ITEM FILE_NAME "${source}")
        endif()
    endforeach()
83
84
85
86
87
88
89
90
91
92
93
94
95
96
    #Do not build any FP8 examples if CK_ENABLE_FP8 not set
    foreach(source IN LISTS FILE_NAME)
        if(NOT DEFINED CK_ENABLE_FP8 AND source MATCHES "_fp8")
            message("removing fp8 example ${source} ")
            list(REMOVE_ITEM FILE_NAME "${source}")
        endif()
    endforeach()
    #Do not build any BF8 examples if CK_ENABLE_BF8 not set
    foreach(source IN LISTS FILE_NAME)
        if(NOT DEFINED CK_ENABLE_BF8 AND source MATCHES "_bf8")
            message("removing bf8 example ${source} ")
            list(REMOVE_ITEM FILE_NAME "${source}")
        endif()
    endforeach()
97
98
    #only continue if there are some source files left on the list
    if(FILE_NAME)
99
        if(FILE_NAME MATCHES "_xdl")
100
            list(REMOVE_ITEM EX_TARGETS gfx900 gfx906 gfx906:xnack- gfx1030 gfx1100 gfx1101 gfx1102 gfx1103 gfx1200 gfx1201 gfx10.3-generic gfx11-generic gfx12-generic)
101
        elseif(FILE_NAME MATCHES "_wmma")
102
            list(REMOVE_ITEM EX_TARGETS gfx900 gfx906 gfx906:xnack- gfx908:xnack+ gfx908:xnack- gfx90a:xnack+ gfx90a:xnack- gfx908 gfx90a gfx940 gfx941 gfx942 gfx1030)
103
104
        endif()
        set_source_files_properties(${FILE_NAME} PROPERTIES LANGUAGE HIP)
105
106
107
        add_executable(${EXAMPLE_NAME} ${FILE_NAME})
        target_link_libraries(${EXAMPLE_NAME} PRIVATE utility)
        add_test(NAME ${EXAMPLE_NAME} COMMAND $<TARGET_FILE:${EXAMPLE_NAME}> ${ARGN})
108
        set_property(TARGET ${EXAMPLE_NAME} PROPERTY HIP_ARCHITECTURES ${EX_TARGETS} )
109
110
111
112
113
114
        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}")
115
116
117
118
119
120
121
122
123
    if(result EQUAL 0 AND NOT "${EXAMPLE_NAME}" IN_LIST REGRESSION_EXAMPLES)
        message("adding to SMOKE EXAMPLE FILTER ${EXAMPLE_NAME}")
        set_tests_properties(${EXAMPLE_NAME} PROPERTIES LABELS "SMOKE_EXAMPLE")
        add_dependencies(smoke ${EXAMPLE_NAME})
    elseif(result EQUAL 0 AND "${EXAMPLE_NAME}" IN_LIST REGRESSION_EXAMPLES)
        message("Adding to REGRESSION EXAMPLE FILTER ${EXAMPLE_NAME}")
        set_tests_properties(${EXAMPLE_NAME} PROPERTIES LABELS "REGRESSION_EXAMPLE")
        add_dependencies(regression ${EXAMPLE_NAME})
    endif()
124
    set(result ${result} PARENT_SCOPE)
Anthony Chang's avatar
Anthony Chang committed
125
126
endfunction(add_example_executable EXAMPLE_NAME)

127
128
129
130
131
132
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
133
134
function(add_example_executable_no_testing EXAMPLE_NAME FILE_NAME)
    message("adding example ${EXAMPLE_NAME}")
135
136
137
138
    set(result 1)
    if(DEFINED DTYPES)
    foreach(source IN LISTS FILE_NAME)
        set(test 0)
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
        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()
160
161
162
        if(test EQUAL 1)
            message("removing example ${source} ")
            list(REMOVE_ITEM FILE_NAME "${source}")
163
        endif()
164
165
    endforeach()
    endif()
166

167
168
    set(EX_TARGETS ${SUPPORTED_GPU_TARGETS})

169
    #Do not build any DL examples if DL_KERNELS not set
170
171
172
173
174
175
    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()
176
177
    #Do not build any XDL examples if gfx9 targets are not on the list
    foreach(source IN LISTS FILE_NAME)
178
        if(NOT EX_TARGETS MATCHES "gfx9" AND source MATCHES "_xdl")
179
180
181
182
183
184
            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)
185
	if(NOT EX_TARGETS MATCHES "gfx11" AND NOT EX_TARGETS MATCHES "gfx12" AND source MATCHES "_wmma")
186
187
188
189
            message("removing wmma example ${source} ")
            list(REMOVE_ITEM FILE_NAME "${source}")
        endif()
    endforeach()
190
191
    #only continue if there are some source files left on the list
    if(FILE_NAME)
192
        if(FILE_NAME MATCHES "_xdl")
193
            list(REMOVE_ITEM EX_TARGETS gfx900 gfx906 gfx906:xnack- gfx1030 gfx1100 gfx1101 gfx1102 gfx1103 gfx1200 gfx1201 gfx10.3-generic gfx11-generic gfx12-generic)
194
        elseif(FILE_NAME MATCHES "_wmma")
195
            list(REMOVE_ITEM EX_TARGETS gfx900 gfx906 gfx906:xnack- gfx908:xnack+ gfx908:xnack- gfx90a:xnack+ gfx90a:xnack- gfx908 gfx90a gfx940 gfx941 gfx942 gfx1030)
196
197
        endif()
        set_source_files_properties(${FILE_NAME} PROPERTIES LANGUAGE HIP)
198
199
200
        add_executable(${EXAMPLE_NAME} ${FILE_NAME})
        target_link_libraries(${EXAMPLE_NAME} PRIVATE utility)
        add_dependencies(examples ${EXAMPLE_NAME})
201
        set_property(TARGET ${EXAMPLE_NAME} PROPERTY HIP_ARCHITECTURES ${EX_TARGETS} )
202
203
204
205
        rocm_install(TARGETS ${EXAMPLE_NAME} COMPONENT examples)
        set(result 0)
    endif()
    #message("add_example returns ${result}")
206
207
208
209
210
211
212
213
214
215
    # if(result EQUAL 0 AND NOT "${EXAMPLE_NAME}" IN_LIST REGRESSION_EXAMPLES)
    #     message("NO TESTING:: adding to SMOKE EXAMPLE FILTER ${EXAMPLE_NAME}")
    #     set_tests_properties(${EXAMPLE_NAME} PROPERTIES LABELS "SMOKE_EXAMPLE")
    #     add_dependencies(smoke ${EXAMPLE_NAME})
    # elseif(result EQUAL 0 AND "${EXAMPLE_NAME}" IN_LIST REGRESSION_EXAMPLES)
    #     message("NO TESTING:: Adding to REGRESSION EXAMPLE FILTER ${EXAMPLE_NAME}")
    #     set_tests_properties(${EXAMPLE_NAME} PROPERTIES LABELS "REGRESSION_EXAMPLE")
    #     add_dependencies(regression ${EXAMPLE_NAME})
    # endif()

216
    set(result ${result} PARENT_SCOPE)
rocking5566's avatar
rocking5566 committed
217
endfunction(add_example_executable_no_testing EXAMPLE_NAME)
218

Shaojie WANG's avatar
Shaojie WANG committed
219
220
221
# add all example subdir
file(GLOB dir_list LIST_DIRECTORIES true *)
FOREACH(subdir ${dir_list})
Ruturaj Vaidya's avatar
Ruturaj Vaidya committed
222
    if(IS_DIRECTORY "${subdir}" AND EXISTS "${subdir}/CMakeLists.txt")
Shaojie WANG's avatar
Shaojie WANG committed
223
224
225
        add_subdirectory(${subdir})
    ENDIF()
ENDFOREACH()