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
19 changes: 19 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -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 @@ -894,6 +907,12 @@ 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
2 changes: 1 addition & 1 deletion Paddle
Submodule Paddle updated 267 files
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,26 @@ bash build_paddle.sh
# Install
bash install_paddle.sh
```
## For incremental compilation(faster rebuilds after code changes)

To enable CINN, set the CMake option **`WITH_CINN` to `ON`** (it is off by default), for example:

```bash
WITH_CINN=ON bash build_paddle.sh
```

## Incremental compilation (faster rebuilds after code changes)

```bash
# For incremental compilation (faster rebuilds after code changes, also installs whl)
# Incremental compilation (faster rebuilds after code changes, also installs whl)
bash build_inc.sh
```

For incremental builds with CINN enabled, pass the same variable:

```bash
WITH_CINN=ON bash build_inc.sh
```

## Verification

```bash
Expand Down
12 changes: 12 additions & 0 deletions README_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,24 @@ bash build_paddle.sh
bash install_paddle.sh
```

若需开启 CINN,请将 CMake 选项 **`WITH_CINN` 设为 `ON`**(默认为关闭),例如:

```bash
WITH_CINN=ON bash build_paddle.sh
```

## 增量编译(代码修改后更快地重新编译)
```bash
# 增量编译(代码修改后更快地重新编译,也会安装 whl 包)
bash build_inc.sh
```

增量编译若也要启用 CINN,同样传入环境变量:

```bash
WITH_CINN=ON bash build_inc.sh
```

## 验证

```bash
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
3 changes: 2 additions & 1 deletion 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 Down Expand Up @@ -69,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
Loading