Skip to content

Commit

Permalink
add nvfuser as optional build
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreSlavescu committed Sep 19, 2024
1 parent 16ba8bf commit 291d51f
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 18 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
build/
hub/
traces/
CMakeFiles/
.env
token
token
Makefile
detect_cuda_compute_capabilities.cu
detect_cuda_version.cc
cmake_install.cmake
CMakeCache.txt
35 changes: 28 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,38 @@ foreach(source ${BLAZETORCH_SOURCES})
message(STATUS " ${source}")
endforeach()

add_subdirectory(submodules/nvfuser)
# Define the blazetorch target
add_library(blazetorch SHARED
blazetorch/blazetorch_compiler.cc
blazetorch/compiler.cc
blazetorch/fuse_candidates.cc
blazetorch/fusion_passes/fusion_adddiv.cc
blazetorch/fusion_passes/fusion_addmul.cc
blazetorch/process_graph_ops.cc
blazetorch/register.cc
)

add_library(
blazetorch SHARED
${BLAZETORCH_SOURCES}
# Link libraries to the blazetorch target
target_link_libraries(blazetorch
PRIVATE
${TORCH_LIBRARIES}
${CUDA_LIBRARIES}
pybind11::module
)

target_link_libraries(blazetorch "${TORCH_LIBRARIES}" nvfuser_codegen flatbuffers)
set_property(TARGET blazetorch PROPERTY CXX_STANDARD 17)
# Include directories
include_directories(${TORCH_INCLUDE_DIRS} ${Python3_INCLUDE_DIRS} ${pybind11_INCLUDE_DIRS})

option(BUILD_WITH_NVFUSER "Build with nvfuser" ON)

include_directories(${TORCH_INCLUDE_DIRS} ${Python3_INCLUDE_DIRS} submodules/nvfuser ${pybind11_INCLUDE_DIRS} ${FLATBUFFERS_INCLUDE_DIRS})
if(BUILD_WITH_NVFUSER)
add_subdirectory(submodules/nvfuser)
target_link_libraries(blazetorch PRIVATE nvfuser_codegen flatbuffers)
include_directories(submodules/nvfuser ${FLATBUFFERS_INCLUDE_DIRS})
message(STATUS "Building with nvfuser")
else()
message(STATUS "Building without nvfuser")
endif()

message(STATUS "Torch_DIR: ${Torch_DIR}")
message(STATUS "pybind11_DIR: ${pybind11_DIR}")
Expand Down
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ Before building, make sure you have cmake installed. Tested on cmake version 3.2
```
git clone https://github.com/AndreSlavescu/BlazeTorch
git submodule update --init --recursive
```

# Build NVFuser
```
# build flatbuffers with appropriate version (23 major version and 3 minor version)
cd submodules/nvfuser/third_party/flatbuffers
git fetch --all
Expand All @@ -20,12 +23,17 @@ make install
cd ../../../../..
```

## Build
## Build BlazeTorch

The project gets built with CMake by running:
```
chmod +x build.sh
# build without NVFuser
./build.sh
# build with NVFuser
./build.sh build_with_nvfuser
```

## Running Tests
Expand Down Expand Up @@ -63,4 +71,3 @@ traces will be hosted in a built ```tests/traces/```
adapted and extended from:

https://jott.live/markdown/Writing%20a%20Toy%20Backend%20Compiler%20for%20PyTorch

30 changes: 22 additions & 8 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,32 @@
build_dir="build"
nvfuser_dir="submodules/nvfuser"
nvfuser_build_marker="$nvfuser_dir/bin/CMakeFiles"
build_with_nvfuser=false

if [ ! -d "$nvfuser_build_marker" ]; then
echo "Building nvfuser..."
if [ -d "$build_dir" ]; then
rm -rf "$build_dir"
# Parse arguments
for arg in "$@"
do
if [ "$arg" = "build_with_nvfuser" ]; then
build_with_nvfuser=true
fi
done

if [ "$build_with_nvfuser" = true ]; then
if [ ! -d "$nvfuser_build_marker" ]; then
echo "Building nvfuser..."
if [ -d "$build_dir" ]; then
rm -rf "$build_dir"
fi
mkdir "$build_dir" && cd "$build_dir"
cmake -DBUILD_NVFUSER=ON ..
make -j 16 nvfuser_codegen
else
echo "nvfuser is already built. Skipping nvfuser build."
mkdir -p "$build_dir" && cd "$build_dir"
fi
mkdir "$build_dir" && cd "$build_dir"
cmake ..
make -j 16 nvfuser_codegen
else
echo "nvfuser is already built. Skipping nvfuser build."
mkdir -p "$build_dir" && cd "$build_dir"
cmake -DBUILD_NVFUSER=OFF ..
fi

make -j 16 blazetorch

0 comments on commit 291d51f

Please sign in to comment.