Skip to content

Commit

Permalink
wwip 3
Browse files Browse the repository at this point in the history
  • Loading branch information
q10 committed Nov 17, 2024
1 parent afe7802 commit 554d6b7
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 106 deletions.
8 changes: 6 additions & 2 deletions cmake/modules/GpuCppLibrary.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ endfunction()
function(prepare_hipified_target_sources)
set(flags)
set(singleValueArgs PREFIX)
set(multiValueArgs SRCS)
set(multiValueArgs SRCS INCLUDE_DIRS)

cmake_parse_arguments(
args
Expand All @@ -105,6 +105,9 @@ function(prepare_hipified_target_sources)
set_source_files_properties(${args_SRCS}
PROPERTIES HIP_SOURCE_PROPERTY_FORMAT 1)

# Add include directories
hip_include_directories("${args_INCLUDE_DIRS}")

set(${args_PREFIX}_sources_hipified ${args_SRCS} PARENT_SCOPE)
endfunction()

Expand Down Expand Up @@ -139,7 +142,8 @@ function(gpu_cpp_library)
# Fetch the HIPified sources
prepare_hipified_target_sources(
PREFIX ${args_PREFIX}
SRCS ${lib_sources})
SRCS ${lib_sources}
INCLUDE_DIRS ${args_INCLUDE_DIRS})
set(lib_sources_hipified ${${args_PREFIX}_sources_hipified})

# Create the HIP library
Expand Down
3 changes: 3 additions & 0 deletions fbgemm_gpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ include(${CMAKEMODULES}/RocmSetup.cmake)
# Load gpu_cpp_library()
include(${CMAKEMODULES}/GpuCppLibrary.cmake)


################################################################################
# Source Includes
################################################################################
Expand All @@ -106,6 +107,7 @@ set(fbgemm_sources_include_directories
${THIRDPARTY}/json/include
${NCCL_INCLUDE_DIRS})


################################################################################
# Build FBGEMM_GPU (Main) Module
################################################################################
Expand All @@ -114,6 +116,7 @@ if(NOT FBGEMM_GENAI_ONLY)
include(FbgemmGpu.cmake)
endif()


################################################################################
# Build Experimental Modules
################################################################################
Expand Down
52 changes: 5 additions & 47 deletions fbgemm_gpu/experimental/example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,20 @@

include(${CMAKEMODULES}/Utilities.cmake)

# Implicit CMake Imports:
# ${fbgemm_sources_include_directories}
# gpu_cpp_library()


################################################################################
# Target Sources
################################################################################

# fbgemm_sources_include_directories
# gpu_cpp_library

# set(fbgemm_sources_include_directories
# # FBGEMM
# ${FBGEMM}/include
# # FBGEMM_GPU
# ${CMAKE_CURRENT_SOURCE_DIR}../..
# ${CMAKE_CURRENT_SOURCE_DIR}../../include
# ${CMAKE_CURRENT_SOURCE_DIR}../../../include
# # PyTorch
# ${TORCH_INCLUDE_DIRS}
# # Third-party
# ${THIRDPARTY}/asmjit/src
# ${THIRDPARTY}/cpuinfo/include
# ${THIRDPARTY}/cutlass/include
# ${THIRDPARTY}/cutlass/tools/util/include
# ${THIRDPARTY}/json/include
# ${NCCL_INCLUDE_DIRS})

set(experimental_example_cpp_source_files
src/cutlass_sgemm_nn.cu
src/example_ops.cpp
src/nccl_example.cpp)

# set_source_files_properties(${experimental_example_cpp_source_files}
# PROPERTIES INCLUDE_DIRECTORIES
# "${fbgemm_sources_include_directories}")

set(experimental_example_python_source_files
example/__init__.py
example/utils.py)
Expand All @@ -57,22 +38,6 @@ gpu_cpp_library(
${experimental_example_cpp_source_files})


# add_library(fbgemm_gpu_experimental_example_py MODULE
# ${experimental_example_cpp_source_files})

# target_include_directories(fbgemm_gpu_experimental_example_py PRIVATE
# ${TORCH_INCLUDE_DIRS}
# ${NCCL_INCLUDE_DIRS})

# target_link_libraries(fbgemm_gpu_experimental_example_py
# ${TORCH_LIBRARIES}
# ${NCCL_LIBRARIES}
# ${CUDA_DRIVER_LIBRARIES})

# # Remove `lib` from the output artifact name
# set_target_properties(fbgemm_gpu_experimental_example_py PROPERTIES PREFIX "")


################################################################################
# Install Shared Library and Python Files
################################################################################
Expand All @@ -82,10 +47,3 @@ install(TARGETS fbgemm_gpu_experimental_example_py

install(FILES ${experimental_example_python_source_files}
DESTINATION fbgemm_gpu/experimental/example)

# add_custom_target(fbgemm_gpu_experimental_example_py_clean_rpath ALL
# WORKING_DIRECTORY ${OUTPUT_DIR}
# COMMAND bash ${FBGEMM}/.github/scripts/fbgemm_gpu_postbuild.bash)

# add_dependencies(fbgemm_gpu_experimental_example_py_clean_rpath
# fbgemm_gpu_experimental_example_py)
123 changes: 66 additions & 57 deletions fbgemm_gpu/experimental/gen_ai/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@
# Target Sources
################################################################################

set(fbgemm_sources_include_directories
# FBGEMM
${FBGEMM}/include
# FBGEMM_GPU
${CMAKE_CURRENT_SOURCE_DIR}/../..
${CMAKE_CURRENT_SOURCE_DIR}/../../include
${CMAKE_CURRENT_SOURCE_DIR}/../../../include
${CMAKE_CURRENT_SOURCE_DIR}/src/quantize
# PyTorch
${TORCH_INCLUDE_DIRS}
# Third-party
${THIRDPARTY}/asmjit/src
${THIRDPARTY}/cpuinfo/include
${THIRDPARTY}/cutlass/include
${THIRDPARTY}/cutlass/tools/util/include
${THIRDPARTY}/json/include
${NCCL_INCLUDE_DIRS})
# set(fbgemm_sources_include_directories
# # FBGEMM
# ${FBGEMM}/include
# # FBGEMM_GPU
# ${CMAKE_CURRENT_SOURCE_DIR}/../..
# ${CMAKE_CURRENT_SOURCE_DIR}/../../include
# ${CMAKE_CURRENT_SOURCE_DIR}/../../../include
# ${CMAKE_CURRENT_SOURCE_DIR}/src/quantize
# # PyTorch
# ${TORCH_INCLUDE_DIRS}
# # Third-party
# ${THIRDPARTY}/asmjit/src
# ${THIRDPARTY}/cpuinfo/include
# ${THIRDPARTY}/cutlass/include
# ${THIRDPARTY}/cutlass/tools/util/include
# ${THIRDPARTY}/json/include
# ${NCCL_INCLUDE_DIRS})

set(attention_ops_sources
src/attention/attention.cpp
Expand Down Expand Up @@ -77,9 +77,9 @@ if(USE_FB_ONLY)
list(APPEND experimental_gen_ai_cpp_source_files ${fb_only_ops_sources})
endif()

set_source_files_properties(${experimental_gen_ai_cpp_source_files}
PROPERTIES INCLUDE_DIRECTORIES
"${fbgemm_sources_include_directories}")
# set_source_files_properties(${experimental_gen_ai_cpp_source_files}
# PROPERTIES INCLUDE_DIRECTORIES
# "${fbgemm_sources_include_directories}")

file(GLOB_RECURSE experimental_gen_ai_python_source_files
RELATIVE gen_ai
Expand All @@ -100,52 +100,61 @@ if(USE_ROCM)
hipify(CUDA_SOURCE_DIR ${PROJECT_SOURCE_DIR}
HEADER_INCLUDE_DIR ${header_include_dir})

# HIPify source files
get_hipified_list("${experimental_gen_ai_cpp_source_files}"
experimental_gen_ai_cpp_source_files_hip)
# # HIPify source files
# get_hipified_list("${experimental_gen_ai_cpp_source_files}"
# experimental_gen_ai_cpp_source_files_hip)

set_source_files_properties(${experimental_gen_ai_cpp_source_files_hip}
PROPERTIES HIP_SOURCE_PROPERTY_FORMAT 1)
# set_source_files_properties(${experimental_gen_ai_cpp_source_files_hip}
# PROPERTIES HIP_SOURCE_PROPERTY_FORMAT 1)

# Add include directories
hip_include_directories("${fbgemm_sources_include_directories}")
# hip_include_directories("${fbgemm_sources_include_directories}")
endif()


################################################################################
# Build Shared Library
################################################################################

if(USE_ROCM)
# Create a HIP library if using ROCm
hip_add_library(fbgemm_gpu_experimental_gen_ai_py SHARED
${experimental_gen_ai_cpp_source_files_hip}
${FBGEMM_HIP_HCC_LIBRARIES}
HIPCC_OPTIONS
${HIP_HCC_FLAGS})

target_include_directories(fbgemm_gpu_experimental_gen_ai_py PUBLIC
${FBGEMM_HIP_INCLUDE}
${ROCRAND_INCLUDE}
${ROCM_SMI_INCLUDE})
gpu_cpp_library(
PREFIX
fbgemm_gpu_experimental_gen_ai
INCLUDE_DIRS
${fbgemm_sources_include_directories}
GPU_SRCS
${experimental_gen_ai_cpp_source_files})

else()
# Else create a CUDA library
add_library(fbgemm_gpu_experimental_gen_ai_py MODULE
${experimental_gen_ai_cpp_source_files})
endif()

target_include_directories(fbgemm_gpu_experimental_gen_ai_py PRIVATE
${TORCH_INCLUDE_DIRS}
${NCCL_INCLUDE_DIRS})
# if(USE_ROCM)
# # Create a HIP library if using ROCm
# hip_add_library(fbgemm_gpu_experimental_gen_ai_py SHARED
# ${experimental_gen_ai_cpp_source_files_hip}
# ${FBGEMM_HIP_HCC_LIBRARIES}
# HIPCC_OPTIONS
# ${HIP_HCC_FLAGS})

# target_include_directories(fbgemm_gpu_experimental_gen_ai_py PUBLIC
# ${FBGEMM_HIP_INCLUDE}
# ${ROCRAND_INCLUDE}
# ${ROCM_SMI_INCLUDE})

# else()
# # Else create a CUDA library
# add_library(fbgemm_gpu_experimental_gen_ai_py MODULE
# ${experimental_gen_ai_cpp_source_files})
# endif()

# target_include_directories(fbgemm_gpu_experimental_gen_ai_py PRIVATE
# ${TORCH_INCLUDE_DIRS}
# ${NCCL_INCLUDE_DIRS})

target_link_libraries(fbgemm_gpu_experimental_gen_ai_py
${TORCH_LIBRARIES}
${NCCL_LIBRARIES}
${CUDA_DRIVER_LIBRARIES})
# target_link_libraries(fbgemm_gpu_experimental_gen_ai_py
# ${TORCH_LIBRARIES}
# ${NCCL_LIBRARIES}
# ${CUDA_DRIVER_LIBRARIES})

# Remove `lib` from the output artifact name
set_target_properties(fbgemm_gpu_experimental_gen_ai_py PROPERTIES PREFIX "")
# # Remove `lib` from the output artifact name
# set_target_properties(fbgemm_gpu_experimental_gen_ai_py PROPERTIES PREFIX "")


################################################################################
Expand All @@ -158,9 +167,9 @@ install(TARGETS fbgemm_gpu_experimental_gen_ai_py
install(FILES ${experimental_gen_ai_python_source_files}
DESTINATION fbgemm_gpu/experimental/gen_ai)

add_custom_target(fbgemm_gpu_experimental_gen_ai_py_clean_rpath ALL
WORKING_DIRECTORY ${OUTPUT_DIR}
COMMAND bash ${FBGEMM}/.github/scripts/fbgemm_gpu_postbuild.bash)
# add_custom_target(fbgemm_gpu_experimental_gen_ai_py_clean_rpath ALL
# WORKING_DIRECTORY ${OUTPUT_DIR}
# COMMAND bash ${FBGEMM}/.github/scripts/fbgemm_gpu_postbuild.bash)

add_dependencies(fbgemm_gpu_experimental_gen_ai_py_clean_rpath
fbgemm_gpu_experimental_gen_ai_py)
# add_dependencies(fbgemm_gpu_experimental_gen_ai_py_clean_rpath
# fbgemm_gpu_experimental_gen_ai_py)

0 comments on commit 554d6b7

Please sign in to comment.