-
Notifications
You must be signed in to change notification settings - Fork 15
/
CMakeLists.txt
141 lines (115 loc) · 5.08 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# ########################################################################
# Copyright (C) 2019-2022 Advanced Micro Devices, Inc. All rights reserved.
#
# 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 cop-
# ies 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 IM-
# PLIED, 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 CONNE-
# CTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
# ########################################################################
cmake_minimum_required( VERSION 3.5 )
set( CMAKE_CXX_STANDARD 17 )
project( rocblas-examples LANGUAGES CXX )
if (WIN32)
if (NOT CMAKE_PREFIX_PATH)
set(CMAKE_PREFIX_PATH C:/hipSDK)
endif()
endif()
find_package(rocblas REQUIRED)
file( GLOB msvc_examples
LIST_DIRECTORIES OFF
CONFIGURE_DEPENDS
# building with msvc
${CMAKE_SOURCE_DIR}/Level-1/*/*.cpp
${CMAKE_SOURCE_DIR}/Level-2/*gemv*/*.cpp
# level 2 her using hip type
${CMAKE_SOURCE_DIR}/Level-3/*/*.cpp
${CMAKE_SOURCE_DIR}/Extensions/*gemm_ex_i*/*.cpp
${CMAKE_SOURCE_DIR}/Extensions/*gemm_ex_f32*/*.cpp
# bf16 helpers require amd clang or user defined operators so skipped
${CMAKE_SOURCE_DIR}/Patterns/*/*.cpp
)
file( GLOB hipcc_examples
LIST_DIRECTORIES OFF
CONFIGURE_DEPENDS
# either clang or hip types so using amd clang compiler
${CMAKE_SOURCE_DIR}/Level-2/*her*/*.cpp
${CMAKE_SOURCE_DIR}/Extensions/*gemm_ex_bf*/*.cpp
${CMAKE_SOURCE_DIR}/Extensions/*gemm_ex_f16*/*.cpp
)
add_library( examples-common STATIC ${CMAKE_SOURCE_DIR}/common/ArgParser.cpp )
target_include_directories( examples-common PRIVATE ${CMAKE_SOURCE_DIR}/common )
# other targets will inherit the rocblas dependency from this
target_link_libraries( examples-common PUBLIC roc::rocblas )
function( new_target file_name target_name )
string(REGEX MATCH "^(.*)\/(.*)\\.[^.]*$" temp ${file_name})
set( target_name ${CMAKE_MATCH_2})
message(STATUS ${target_name})
add_executable( ${target_name} ${file_name} )
target_include_directories( ${target_name} PRIVATE ${CMAKE_SOURCE_DIR}/common )
set_target_properties( ${target_name} PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF
)
target_link_libraries( ${target_name} PRIVATE examples-common )
set( target_name ${target_name} PARENT_SCOPE )
endfunction()
if (NOT CMAKE_CXX_COMPILER MATCHES ".*hipcc.*")
list( APPEND msvc_targets examples-common )
foreach( file_i ${msvc_examples})
new_target( ${file_i} target_name )
list( APPEND msvc_targets ${target_name} )
endforeach( file_i )
message( STATUS "targets: ${msvc_targets}" )
# msvc modifications
foreach( target_i ${msvc_targets})
if (WIN32)
# required for Visual Studio or it defines it as 199711L regardless of C++ standard
target_compile_options( ${target_i} PRIVATE /Zc:__cplusplus )
# we use hip types so setting these
#target_compile_definitions( ${target_i} PRIVATE __HIP_PLATFORM_AMD__ __HIP_PLATFORM_HCC__ )
endif()
endforeach( target_i )
else()
list( APPEND hipcc_targets examples-common )
foreach( file_i ${hipcc_examples})
new_target( ${file_i} target_name )
list( APPEND hipcc_targets ${target_name} )
endforeach( file_i )
message( STATUS "targets: ${hipcc_tagets}" )
# hipcc modifications
foreach( target_i ${hipcc_targets})
endforeach( target_i )
if (WIN32)
# for now put test harness in build binary directory
file( GLOB test_harness
LIST_DIRECTORIES OFF
CONFIGURE_DEPENDS
${CMAKE_SOURCE_DIR}/rtest.*
)
list(GET hipcc_targets -1 last_target)
foreach( file_i ${test_harness})
add_custom_command( TARGET ${last_target} POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy ${file_i} ${PROJECT_BINARY_DIR} )
endforeach( file_i )
# copy msvc build executables into PROJECT_BINARY_DIR
if (CMAKE_BUILD_TYPE MATCHES "Debug")
set(msvc_subdir "Debug")
else()
set(msvc_subdir "Release")
endif()
add_custom_command( TARGET ${last_target} POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_directory ${PROJECT_BINARY_DIR}/../msvc/${msvc_subdir} ${PROJECT_BINARY_DIR} )
endif()
endif()