Skip to content
Open
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
33 changes: 26 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ set_target_properties(external_error_proto PROPERTIES POSITION_INDEPENDENT_CODE
ON)
set(ILUVATAR_EXTERNAL_DEPS_TARGET iluvatar_external_deps)
if(WITH_FLAGCX)
add_custom_target(${ILUVATAR_EXTERNAL_DEPS_TARGET} DEPENDS eigen3 zlib
protobuf flagcx)
add_custom_target(${ILUVATAR_EXTERNAL_DEPS_TARGET}
DEPENDS eigen3 zlib protobuf flagcx warpctc)
else()
add_custom_target(${ILUVATAR_EXTERNAL_DEPS_TARGET} DEPENDS eigen3 zlib
protobuf)
protobuf warpctc)
endif()

if(WITH_COREX)
Expand All @@ -125,11 +125,18 @@ add_definitions(-std=c++17)
option(WITH_TESTING "compile with unit testing" OFF)
option(ON_INFER "compile with inference c++ lib" OFF)
option(WITH_GPU "Compile PaddlePaddle with ILUVATAR_GPU" ON)
option(WITH_CINN "Compile with CINN support" ON)

set(WITH_GPU ON)

include(cuda)

if(WITH_CINN)
message(STATUS "[Iluvatar] CINN enabled, adding subdirectory: cinn")
add_definitions(-DWITH_CINN)
add_subdirectory(cinn)
endif()

file(
GLOB
CUDA_SRCS
Expand All @@ -143,6 +150,7 @@ file(
${PADDLE_SOURCE_DIR}/paddle/phi/backends/dynload/cusolver.cc
${PADDLE_SOURCE_DIR}/paddle/phi/backends/dynload/cusparse.cc
${PADDLE_SOURCE_DIR}/paddle/phi/backends/dynload/nvjpeg.cc
${PADDLE_SOURCE_DIR}/paddle/phi/backends/dynload/nvtx.cc
# ${PADDLE_SOURCE_DIR}/paddle/phi/backends/gpu/cuda
${PADDLE_SOURCE_DIR}/paddle/phi/backends/gpu/cuda/cuda_graph.cc
${PADDLE_SOURCE_DIR}/paddle/phi/backends/gpu/cuda/cuda_info.cc
Expand Down Expand Up @@ -696,8 +704,8 @@ file(
${PADDLE_SOURCE_DIR}/paddle/phi/kernels/gpu/unstack_grad_kernel.cu
${PADDLE_SOURCE_DIR}/paddle/phi/kernels/gpu/unstack_kernel.cu
${PADDLE_SOURCE_DIR}/paddle/phi/kernels/gpu/viterbi_decode_kernel.cu
# ${PADDLE_SOURCE_DIR}/paddle/phi/kernels/gpu/warpctc_grad_kernel.cu
# ${PADDLE_SOURCE_DIR}/paddle/phi/kernels/gpu/warpctc_kernel.cu
${PADDLE_SOURCE_DIR}/paddle/phi/kernels/gpu/warpctc_grad_kernel.cu
${PADDLE_SOURCE_DIR}/paddle/phi/kernels/gpu/warpctc_kernel.cu
${PADDLE_SOURCE_DIR}/paddle/phi/kernels/gpu/warprnnt_grad_kernel.cu
${PADDLE_SOURCE_DIR}/paddle/phi/kernels/gpu/weighted_sample_neighbors_kernel.cu
${PADDLE_SOURCE_DIR}/paddle/phi/kernels/gpu/where_grad_kernel.cu
Expand Down Expand Up @@ -871,6 +879,11 @@ target_include_directories(
PRIVATE ${PADDLE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/kernels ${CUDA_INCLUDE_DIRS})

if(WITH_CINN)
target_include_directories(${TARGET_NAME}
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/cinn")
endif()

target_link_libraries(
${TARGET_NAME}
PRIVATE glog
Expand All @@ -886,14 +899,20 @@ target_link_libraries(
ixattnbkd
nccl
onednn
# warpctc change nccl to ${FLAGCX_LIB} if compiling with FlagCX
# ${FLAGCX_LIB}
warpctc
# change nccl to ${FLAGCX_LIB} if compiling with FlagCX ${FLAGCX_LIB}
)

if(TARGET phi_core)
target_link_libraries(${TARGET_NAME} PRIVATE phi_core)
endif()

if(WITH_CINN)
message(STATUS "[Iluvatar] Linking CINN object library")
target_link_libraries(${TARGET_NAME}
PRIVATE $<TARGET_OBJECTS:iluvatar_cinn_obj>)
endif()

include_directories(BEFORE ${PADDLE_SOURCE_DIR})
include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/headers)

Expand Down
3 changes: 2 additions & 1 deletion build_inc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ COREX_VERSION=${COREX_VERSION:-latest}
if [[ "${COREX_VERSION}" == "latest" ]]; then
COREX_VERSION=`date --utc +%Y%m%d%H%M%S`
fi
BUILD_TEST=${BUILD_TEST:-1}
COREX_ARCH=${COREX_ARCH:-ivcore11}
WITH_CINN=${WITH_CINN:-OFF}
export CMAKE_CUDA_ARCHITECTURES=${COREX_ARCH}

SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
Expand Down Expand Up @@ -98,6 +98,7 @@ PADDLE_CMAKE_ARGS=(
"-DWITH_DISTRIBUTE=ON"
"-DWITH_CUSTOM_DEVICE_SUB_BUILD=ON"
"-DCUSTOM_DEVICE_SOURCE_DIR=${ILUVATAR_SOURCE_DIR}"
"-DWITH_CINN=${WITH_CINN}"
)
CUSTOM_DEVICE_CMAKE_ARGS=(
"-DWITH_COREX=ON"
Expand Down
7 changes: 2 additions & 5 deletions build_paddle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ COREX_VERSION=${COREX_VERSION:-latest}
if [[ "${COREX_VERSION}" == "latest" ]]; then
COREX_VERSION=`date --utc +%Y%m%d%H%M%S`
fi
BUILD_TEST=${BUILD_TEST:-1}
COREX_ARCH=${COREX_ARCH:-ivcore11}
WITH_CINN=${WITH_CINN:-OFF}
export CMAKE_CUDA_ARCHITECTURES=${COREX_ARCH}

CURRENT_DIR=$(pwd)
Expand All @@ -45,10 +45,6 @@ fi

bash clean_paddle.sh || { echo "Error: Failed to clean paddle!"; exit 1; }

# pushd "${CURRENT_DIR}/../.."
# git submodule update --init --recursive --force
# popd

if ! git -C "$PADDLE_SOURCE_DIR" apply --reverse --check "$PATCH_FILE" > /dev/null 2>&1; then
if ! git -C "$PADDLE_SOURCE_DIR" apply "$PATCH_FILE"; then
echo "Error: Failed to apply patch!"
Expand All @@ -73,6 +69,7 @@ PADDLE_CMAKE_ARGS=(
"-DWITH_DISTRIBUTE=ON"
"-DWITH_CUSTOM_DEVICE_SUB_BUILD=ON"
"-DCUSTOM_DEVICE_SOURCE_DIR=${ILUVATAR_SOURCE_DIR}"
"-DWITH_CINN=${WITH_CINN}"
)

CUSTOM_DEVICE_CMAKE_ARGS=(
Expand Down
26 changes: 26 additions & 0 deletions cinn/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# =============================================================================
# CINN Plugin for Iluvatar (IXUCA) Backend
# =============================================================================

set(IXUCA_PATH $ENV{IXUCA_PATH})
if(NOT IXUCA_PATH)
set(IXUCA_PATH "/usr/local/corex")
message(
STATUS "[Iluvatar CINN] IXUCA_PATH not set, using default: ${IXUCA_PATH}")
else()
message(STATUS "[Iluvatar CINN] Found IXUCA_PATH: ${IXUCA_PATH}")
endif()

set(CINN_SRCS cinn_interface.cc compiler/compiler.cc runtime/cinn_runtime.cc
passes/pass_manager.cc)

add_library(iluvatar_cinn_obj OBJECT ${CINN_SRCS})

target_include_directories(
iluvatar_cinn_obj
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../
${IXUCA_PATH}/include ${PADDLE_SOURCE_DIR})

set_property(TARGET iluvatar_cinn_obj PROPERTY CXX_STANDARD 17)

set_property(TARGET iluvatar_cinn_obj PROPERTY POSITION_INDEPENDENT_CODE ON)
87 changes: 87 additions & 0 deletions cinn/cinn_interface.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@

// Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "cinn_interface.h" // NOLINT

#include <cstring> // For memset
#include <iostream>

namespace paddle {
namespace custom_device {
namespace iluvatar {

extern C_Status IluvatarCompile(void* dev_ptr,
const char* code,
char* out_path,
size_t len);

extern const char* IluvatarGetRuntimeSource(void* dev_ptr);

extern C_Status IluvatarModuleLoad(void* dev_ptr,
const char* path,
void** mod_out);

extern C_Status IluvatarModuleUnload(void* dev_ptr, void* module_handle);

extern C_Status IluvatarGetKernelAddress(void* dev_ptr,
void* module_handle,
const char* func_name,
void** func_out);

extern C_Status IluvatarLaunchKernel(void* dev_ptr,
void* func_ptr,
void** args,
int num_args,
int gx,
int gy,
int gz,
int bx,
int by,
int bz,
int shm,
void* stream);

extern C_Status IluvatarApplyCustomPass(void* dev_ptr, void* ir_module);

static C_CinnInterface iluvatar_cinn_impl;

void InitCinnInterface(C_DeviceInterface* device_interface) {
std::memset(&iluvatar_cinn_impl, 0, sizeof(C_CinnInterface));

iluvatar_cinn_impl.size = sizeof(C_CinnInterface);

iluvatar_cinn_impl.dev_ptr = nullptr;

iluvatar_cinn_impl.compile = IluvatarCompile;
iluvatar_cinn_impl.get_runtime_source = IluvatarGetRuntimeSource;

iluvatar_cinn_impl.module_load = IluvatarModuleLoad;
iluvatar_cinn_impl.module_unload = IluvatarModuleUnload;
iluvatar_cinn_impl.get_kernel_address = IluvatarGetKernelAddress;
iluvatar_cinn_impl.launch_kernel = IluvatarLaunchKernel;

iluvatar_cinn_impl.apply_custom_pass = IluvatarApplyCustomPass;

if (device_interface) {
device_interface->cinn_interface = &iluvatar_cinn_impl;
} else {
std::cerr << "[Iluvatar] Error: device_interface is null during CINN init."
<< std::endl;
}
}

} // namespace iluvatar
} // namespace custom_device
} // namespace paddle
28 changes: 28 additions & 0 deletions cinn/cinn_interface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

// Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include "paddle/phi/backends/device_ext.h"

namespace paddle {
namespace custom_device {
namespace iluvatar {

void InitCinnInterface(C_DeviceInterface* device_interface);

} // namespace iluvatar
} // namespace custom_device
} // namespace paddle
Loading