Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 4 additions & 23 deletions build2cmake/src/templates/cpu/kernel.cmake
Original file line number Diff line number Diff line change
@@ -1,24 +1,5 @@
set({{kernel_name}}_SRC
{{ sources }}
cpu_kernel_component(SRC
SOURCES {{ sources }}
{% if includes %}INCLUDES "{{ includes }}"{% endif %}
{% if cxx_flags %}CXX_FLAGS "{{ cxx_flags }}"{% endif %}
)

{% if includes %}
# TODO: check if CLion support this:
# https://youtrack.jetbrains.com/issue/CPP-16510/CLion-does-not-handle-per-file-include-directories
set_source_files_properties(
{{'${' + kernel_name + '_SRC}'}}
PROPERTIES INCLUDE_DIRECTORIES "{{ includes }}")
{% endif %}

{% if cxx_flags %}
foreach(_KERNEL_SRC {{'${' + kernel_name + '_SRC}'}})
set_property(
SOURCE ${_KERNEL_SRC}
APPEND PROPERTY
COMPILE_OPTIONS "$<$<COMPILE_LANGUAGE:CXX>:{{ cxx_flags }}>"
)
endforeach()
{% endif %}

# Add C++ sources to main source list
list(APPEND SRC {{'"${' + kernel_name + '_SRC}"'}})
4 changes: 4 additions & 0 deletions build2cmake/src/templates/cpu/preamble.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ file(MAKE_DIRECTORY ${FETCHCONTENT_BASE_DIR}) # Ensure the directory exists
message(STATUS "FetchContent base directory: ${FETCHCONTENT_BASE_DIR}")

include(${CMAKE_CURRENT_LIST_DIR}/cmake/utils.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/cmake/kernel.cmake)

if(DEFINED Python3_EXECUTABLE)
# Allow passing through the interpreter (e.g. from setup.py).
Expand Down Expand Up @@ -42,3 +43,6 @@ endif()
{% endif %}

add_compile_definitions(CPU_KERNEL)

# Initialize SRC list for kernel and binding sources
set(SRC "")
102 changes: 10 additions & 92 deletions build2cmake/src/templates/cuda/kernel.cmake
Original file line number Diff line number Diff line change
@@ -1,93 +1,11 @@
{% if cuda_minver %}
if (CUDA_VERSION VERSION_GREATER_EQUAL {{ cuda_minver }})
{% endif %}

set({{kernel_name}}_SRC
{{ sources }}
cuda_kernel_component(SRC
SOURCES {{ sources }}
{% if cuda_minver %}CUDA_MINVER {{ cuda_minver }}{% endif %}
{% if includes %}INCLUDES "{{ includes }}"{% endif %}
{% if cuda_capabilities %}CUDA_CAPABILITIES {{ cuda_capabilities|join(" ") }}{% endif %}
{% if cuda_flags %}CUDA_FLAGS "{{ cuda_flags }}"{% endif %}
{% if cxx_flags %}CXX_FLAGS "{{ cxx_flags }}"{% endif %}
{% if supports_hipify %}SUPPORTS_HIPIFY{% endif %}
{% if hip_flags %}HIP_FLAGS "{{ hip_flags }}"{% endif %}
{% if rocm_archs %}ROCM_ARCHS {{ rocm_archs|join(" ") }}{% endif %}
)

{% if includes %}
# TODO: check if CLion support this:
# https://youtrack.jetbrains.com/issue/CPP-16510/CLion-does-not-handle-per-file-include-directories
set_source_files_properties(
{{'${' + kernel_name + '_SRC}'}}
PROPERTIES INCLUDE_DIRECTORIES "{{ includes }}")
{% endif %}

if(GPU_LANG STREQUAL "CUDA")
{% if cuda_capabilities %}
cuda_archs_loose_intersection({{kernel_name}}_ARCHS "{{ cuda_capabilities|join(";") }}" "${CUDA_ARCHS}")
{% else %}
set({{kernel_name}}_ARCHS "${CUDA_KERNEL_ARCHS}")
{% endif %}
message(STATUS "Capabilities for kernel {{kernel_name}}: {{ '${' + kernel_name + '_ARCHS}'}}")
set_gencode_flags_for_srcs(SRCS {{'"${' + kernel_name + '_SRC}"'}} CUDA_ARCHS "{{ '${' + kernel_name + '_ARCHS}'}}")

{% if cuda_flags %}

set(_CUDA_FLAGS "{{ cuda_flags }}")
# -static-global-template-stub is not supported on CUDA < 12.8. Remove this
# once we don't support CUDA 12.6 anymore.
if(CUDA_VERSION VERSION_LESS 12.8)
string(REGEX REPLACE "-static-global-template-stub=(true|false)" "" _CUDA_FLAGS "${_CUDA_FLAGS}")
endif()

foreach(_KERNEL_SRC {{'${' + kernel_name + '_SRC}'}})
if(_KERNEL_SRC MATCHES ".*\\.cu$")
set_property(
SOURCE ${_KERNEL_SRC}
APPEND PROPERTY
COMPILE_OPTIONS "$<$<COMPILE_LANGUAGE:CUDA>:${_CUDA_FLAGS}>"
)
endif()
endforeach()
{% endif %}

{% if cxx_flags %}
foreach(_KERNEL_SRC {{'${' + kernel_name + '_SRC}'}})
set_property(
SOURCE ${_KERNEL_SRC}
APPEND PROPERTY
COMPILE_OPTIONS "$<$<COMPILE_LANGUAGE:CXX>:{{ cxx_flags }}>"
)
endforeach()
{% endif %}

list(APPEND SRC {{'"${' + kernel_name + '_SRC}"'}})
{% if supports_hipify %}
elseif(GPU_LANG STREQUAL "HIP")
{% if hip_flags %}

foreach(_KERNEL_SRC {{'${' + kernel_name + '_SRC}'}})
if(_KERNEL_SRC MATCHES ".*\\.(cu|hip)$")
set_property(
SOURCE ${_KERNEL_SRC}
APPEND PROPERTY
COMPILE_OPTIONS "$<$<COMPILE_LANGUAGE:HIP>:{{ hip_flags }}>"
)
endif()
endforeach()
{% endif %}

hip_archs_loose_intersection({{kernel_name}}_ARCHS "{{ rocm_archs|join(";") }}" "${ROCM_ARCHS}")
message(STATUS "Archs for kernel {{kernel_name}}: {{ '${' + kernel_name + '_ARCHS}'}}")

foreach(_KERNEL_SRC {{'${' + kernel_name + '_SRC}'}})
if(_KERNEL_SRC MATCHES ".*\\.(cu|hip)$")
foreach(_ROCM_ARCH {{ '${' + kernel_name + '_ARCHS}'}})
set_property(
SOURCE ${_KERNEL_SRC}
APPEND PROPERTY
COMPILE_OPTIONS "$<$<COMPILE_LANGUAGE:HIP>:--offload-arch=${_ROCM_ARCH}>"
)
endforeach()
endif()
endforeach()

list(APPEND SRC {{'"${' + kernel_name + '_SRC}"'}})
{% endif %}
endif()

{% if cuda_minver %}
endif()
{% endif %}
3 changes: 3 additions & 0 deletions build2cmake/src/templates/cuda/preamble.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ message(STATUS "FetchContent base directory: ${FETCHCONTENT_BASE_DIR}")
set(HIP_SUPPORTED_ARCHS "gfx906;gfx908;gfx90a;gfx942;gfx950;gfx1030;gfx1100;gfx1101;gfx1200;gfx1201")

include(${CMAKE_CURRENT_LIST_DIR}/cmake/utils.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/cmake/kernel.cmake)

if(DEFINED Python3_EXECUTABLE)
# Allow passing through the interpreter (e.g. from setup.py).
Expand Down Expand Up @@ -128,6 +129,8 @@ else()
"${${GPU_LANG}_SUPPORTED_ARCHS}")
endif()

# Initialize SRC list for kernel and binding sources
set(SRC "")

message(STATUS "Rendered for platform {{ platform }}")
{% if platform == 'windows' %}
Expand Down
1 change: 0 additions & 1 deletion build2cmake/src/templates/cuda/torch-binding.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ set_source_files_properties(
{% endif %}

list(APPEND SRC {{'"${TORCH_' + name + '_SRC}"'}})

Loading
Loading