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
1 change: 1 addition & 0 deletions projects/fusilli-plugin/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BasedOnStyle: LLVM
8 changes: 8 additions & 0 deletions projects/fusilli-plugin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# CMake build
build/

# clangd intellisense cache
.cache/

# CMake presets
CMakePresets.json
61 changes: 61 additions & 0 deletions projects/fusilli-plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Copyright 2025 Advanced Micro Devices, Inc.
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

cmake_minimum_required(VERSION 3.28)

project(fusilli-plugin
VERSION 0.1.0
DESCRIPTION "Fusilli-Plugin: A Fusilli/IREE powered hipDNN plugin for graph JIT compilation."
LANGUAGES C CXX)

# Set C++ standard
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_SCAN_FOR_MODULES OFF)

# Local Includes
list(APPEND CMAKE_MODULE_PATH
${CMAKE_CURRENT_LIST_DIR}/build_tools/cmake/
)
include(FusilliPluginDependencyUtils)

# Global constants
set(FUSILLI_PLUGIN_NAME fusilli_plugin)
set(FUSILLI_PLUGIN_ENGINE_ID 1001)

# Options
option(FUSILLI_PLUGIN_USE_LOCAL_FUSILLI "Use local Fusilli build from ../sharkfuser" ON)

# Dependencies
set(HIP_PLATFORM "amd")
find_package(hip REQUIRED)
fusilli_plugin_dependency(GTest GTEST_VERSION 1.16.0)
fusilli_plugin_dependency(IREERuntime)
fusilli_plugin_dependency(hipdnn_frontend HIP_DNN_HASH 4e0a0452cfcb8fdb86e9c40a6e43debab4d4ecbc)
fusilli_plugin_dependency(Fusilli USE_LOCAL ${FUSILLI_PLUGIN_USE_LOCAL_FUSILLI})

# Includes
include_directories(include)

# Plugin definition
add_library(${FUSILLI_PLUGIN_NAME} SHARED
src/fusilli_plugin.cpp
)
target_compile_options(${FUSILLI_PLUGIN_NAME} PRIVATE ${HIPDNN_WARNING_COMPILE_OPTIONS})
target_link_libraries(${FUSILLI_PLUGIN_NAME} PRIVATE hipdnn_sdk hip::host fusilli::fusilli)
target_compile_definitions(${FUSILLI_PLUGIN_NAME} PRIVATE
FUSILLI_PLUGIN_NAME="${FUSILLI_PLUGIN_NAME}"
FUSILLI_PLUGIN_ENGINE_ID=${FUSILLI_PLUGIN_ENGINE_ID}
)
set_target_properties(${FUSILLI_PLUGIN_NAME} PROPERTIES
CXX_VISIBILITY_PRESET hidden
LIBRARY_OUTPUT_DIRECTORY "${HIPDNN_BUILD_PLUGIN_ENGINE_DIR}"
)

# Tests
enable_testing()
add_subdirectory(test)
26 changes: 26 additions & 0 deletions projects/fusilli-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Fusilli Plugin

Fusilli-Plugin: A Fusilli/IREE powered hipDNN plugin for graph JIT compilation.

:construction: **This project is under active development, many things don't work yet** :construction:

The plugin builds as a shared library (`fusilli_plugin.so`) providing a `hipDNN` [kernel engine plugin](https://github.com/ROCm/hipDNN/blob/develop/docs/PluginDevelopment.md#creating-a-kernel-engine-plugin) [API](https://github.com/ROCm/hipDNN/blob/839cf6c4bc6fe403d0ef72cb5d7df004e2004743/sdk/include/hipdnn_sdk/plugin/EnginePluginApi.h).

## Developer Guide

### Setup

For the time being, `fusilli-plugin` setup relies on / builds on [Fusilli setup](../sharkfuser/README.md#setup).
Keeping the projects in sync prevents "works on my machine" style bugs.
Requirements that are unique to `fusilli-plugin`, `hipDNN` and `googletest` for
example, are fetched configured and built as part of `fusilli-plugin` build.

After following steps in [Fusilli Setup](../sharkfuser/README.md#setup), build and test
`fusilli-plugin` as follows:
```shell
$ cmake -GNinja -S. -Bbuild \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++
$ cmake --build build --target all
$ ctest --test-dir build
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
# Copyright 2025 Advanced Micro Devices, Inc.
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#===------------------------------------------------------------------------===#
#
# Provides correctly configured dependencies for fusilli-plugin build.
#
# Main entry point:
# fusilli_plugin_dependency(DEP_NAME [args...])
#
# `fusilli_plugin_dependency` routes to lower level `_fetch_X` macros to
# actually fetch dependency `X`. Each `_fetch_X` macro preferentially
# `find_package`s installed/system versions of packages and falls back to
# vendoring dependencies in the build tree with `FetchContent`.
#
# Supported dependencies: GTest, hipdnn_frontend, Fusilli, IREERuntime
#
#===------------------------------------------------------------------------===#

cmake_minimum_required(VERSION 3.25.2)

include(FetchContent)

# Provide a fusilli plugin dependency. `fusilli_plugin_dependency` will
# preferentially use system version (available through `find_package`) of a
# dependency, and fall back to building local copy with `FetchContent` +
# configuration.
#
# fusilli_plugin_dependency(
# DEP_NAME
# [<dependency-specific args>...]
# )
#
# DEP_NAME
# Supported dependencies:
# GTest
# hipdnn_frontend
# Fusilli
# IREERuntime
#
# <dependency-specific args>
# The `_fetch_X` macro for dependency X defines the available options.
# Examples: GTEST_VERSION for GTest, HIP_DNN_HASH for hipdnn_frontend
#
function(fusilli_plugin_dependency DEP_NAME)
# Set indent for logging, any logs from dep "X" will be prefixed with [X].
set(CMAKE_MESSAGE_INDENT "[${DEP_NAME}] ")

# Route to appropriate _fetch_X macro. CMake macros aren't textual
# expansions like C preprocessor macros, so a dynamic call (like below) to a
# macro isn't a problem.
# Macro vs function:
# - macros execute in caller's scope and arguments are textually substituted
# - functions create a new scope and arguments are real variables
# - both functions and macros are executed at runtime
#
# WARNING: Logging below checks variables it expects a _fetch_X macro to set
# in this scope, requiring that _fetch_X is a macro and not a
# function.
if(COMMAND _fetch_${DEP_NAME})
cmake_language(CALL _fetch_${DEP_NAME} ${ARGN})
else()
set(CMAKE_MESSAGE_INDENT "")
message(FATAL_ERROR "Unknown dependency: ${DEP_NAME}")
endif()

# reset indent.
set(CMAKE_MESSAGE_INDENT "")

# FetchContent_MakeAvailable(DEP) creates a <dep>_POPULATED variable
# indicating the dependency was fetched rather than found on system.
#
# WARNING: FetchContent_Declare(<name>)/FetchContent_MakeAvailable(<name>)
# can use anything for the name argument, if the _fetch_X macro
# doesn't use ${DEP_NAME} the <name>_POPULATED we're checking for
# here won't exist and the log may be misleading.
string(TOLOWER ${DEP_NAME} DEP_NAME_LOWER)
if (${DEP_NAME_LOWER}_POPULATED)
message(STATUS "${DEP_NAME} dependency populated via FetchContent")
message(STATUS " Source: ${${DEP_NAME_LOWER}_SOURCE_DIR}")
message(STATUS " Build: ${${DEP_NAME_LOWER}_BINARY_DIR}")
else()
message(STATUS "${DEP_NAME} dependency found on system via find_package")
message(STATUS " Config: ${${DEP_NAME}_DIR}")
endif()
endfunction()

# GTest
#
# GTEST_VERSION
# Version tag of GTest
macro(_fetch_GTest)
cmake_parse_arguments(
ARG # prefix for parsed variables
"" # options (flags)
"GTEST_VERSION" # single-value arguments
"" # multi-value arguments
${ARGN}
)
if(NOT DEFINED ARG_GTEST_VERSION)
message(FATAL_ERROR "GTEST_VERSION is required")
endif()

FetchContent_Declare(
GTest
URL https://github.com/google/googletest/archive/refs/tags/v${ARG_GTEST_VERSION}.zip
)
set(INSTALL_GTEST OFF)
set(BUILD_GMOCK OFF)
FetchContent_MakeAvailable(GTest)
endmacro()

# hipdnn_frontend
#
# NOTE: we currently build hipDNN as a CMake source dependency (via
# FetchContent) rather than using find_package() to locate an installed version.
# The hipDNN build automatically handles transitive dependencies, which is
# quite convenient.
#
# HIP_DNN_HASH
# Git commit hash or tag to fetch
macro(_fetch_hipdnn_frontend)
cmake_parse_arguments(
ARG # prefix for parsed variables
"" # options (flags)
"HIP_DNN_HASH;LOCAL_PATH" # single-value arguments
"" # multi-value arguments
${ARGN}
)
if(NOT DEFINED ARG_LOCAL_PATH AND NOT DEFINED ARG_HIP_DNN_HASH)
message(FATAL_ERROR "Required argument: one of LOCAL_PATH or HIP_DNN_HASH")
endif()

if(DEFINED ARG_LOCAL_PATH AND DEFINED ARG_HIP_DNN_HASH)
message(FATAL_ERROR "Argument error: passing both LOCAL_PATH and HIP_DNN_HASH is ambiguous.")
endif()

if (DEFINED ARG_HIP_DNN_HASH)
FetchContent_Declare(
hipdnn_frontend
# location of hipdnn CMakeLists.txt in rocm-libraries
SOURCE_SUBDIR projects/hipdnn
# rocm-libraries takes 10+ min to fetch without sparse checkout
# (even with a shallow clone). We provide a custom
# DOWNLOAD_COMMAND until such time as CMAKE natively supports
# sparse checkouts.
DOWNLOAD_COMMAND
git clone --no-checkout --filter=blob:none https://github.com/ROCm/rocm-libraries.git <SOURCE_DIR> &&
cd <SOURCE_DIR> &&
git sparse-checkout init --cone &&
git sparse-checkout set projects/hipdnn &&
git checkout ${ARG_HIP_DNN_HASH}
)
else()
FetchContent_Declare(
hipdnn_frontend
SOURCE_DIR ${ARG_LOCAL_PATH}
)
endif()

set(HIP_DNN_BUILD_BACKEND ON)
set(HIP_DNN_BUILD_FRONTEND ON)
set(HIP_DNN_SKIP_TESTS ON)
set(HIP_DNN_BUILD_PLUGINS OFF)
set(ENABLE_CLANG_TIDY OFF)
# PIC required to link static library into shared object.
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
FetchContent_MakeAvailable(hipdnn_frontend)
endmacro()

# IREERuntime
#
# NOTE: For now, we're not providing a FetchContent fallback for IREERuntime.
# Fusilli expects that the system provides this dependency, and we're
# keeping the projects in sync as much as possible for now. If you're
# running in the fusilli docker container (described in sharkfuser README)
# passing -DIREERuntime_DIR=/workspace/.cache/docker/iree/build/lib/cmake/IREE
# should be enough.
macro(_fetch_IREERuntime)
find_package(IREERuntime CONFIG REQUIRED)
endmacro()

# Fusilli
#
# USE_LOCAL
# If set, uses local source from ../sharkfuser directory. Without USE_LOCAL,
# requires system installation via find_package.
macro(_fetch_Fusilli)
cmake_parse_arguments(
ARG # prefix for parsed variables
"" # options (flags)
"USE_LOCAL" # single-value arguments
"" # multi-value arguments
${ARGN}
)

if(NOT DEFINED ARG_USE_LOCAL)
message(FATAL_ERROR "USE_LOCAL argument is required")
endif()

if(NOT ARG_USE_LOCAL)
# For the time being we're keeping fusilli-plugin setup as in sync as
# possible with fusilli.
message(FATAL_ERROR "Only LOCAL builds are supported currently")
endif()

message(STATUS "Using local Fusilli build from ../sharkfuser")
FetchContent_Declare(
Fusilli
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../sharkfuser
)
set(FUSILLI_BUILD_TESTS OFF)
set(FUSILLI_BUILD_BENCHMARKS OFF)
set(FUSILLI_SYSTEMS_AMDGPU ON)
FetchContent_MakeAvailable(Fusilli)
endmacro()
Loading