Skip to content

Commit

Permalink
compiles
Browse files Browse the repository at this point in the history
  • Loading branch information
makslevental committed Oct 3, 2024
1 parent 2329da0 commit 9644459
Show file tree
Hide file tree
Showing 21 changed files with 185 additions and 172 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/ci-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ jobs:
git remote add origin $REPO_ADDRESS
git -c protocol.version=2 fetch --depth 1 origin $BRANCH_NAME
git reset --hard FETCH_HEAD
git -c submodule."third_party/torch-mlir".update=none -c submodule."third_party/stablehlo".update=none -c submodule."src/runtime_src/core/common/aiebu".update=none submodule update --init --recursive --depth 1 --single-branch -j 10
git -c submodule."third_party/torch-mlir".update=none \
-c submodule."third_party/stablehlo".update=none \
-c submodule."src/runtime_src/core/common/aiebu".update=none \
submodule update --init --recursive --depth 1 --single-branch -j 10
- name: Install deps
run: |
Expand All @@ -61,6 +64,11 @@ jobs:
run: |
pip install "numpy<2" pyyaml "pybind11[global]==2.10.3" nanobind pytest
- name: Peano dep
run: |
bash build_tools/download_peano.sh
echo "PEANO_INSTALL_DIR=$PWD/llvm-aie" >> $GITHUB_ENV
- name: Run Pytest
run: |
pytest build_tools/ci
Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/ci-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ jobs:
git remote add origin $REPO_ADDRESS
git -c protocol.version=2 fetch --depth 1 origin $BRANCH_NAME
git reset --hard FETCH_HEAD
git -c submodule."third_party/torch-mlir".update=none -c submodule."third_party/stablehlo".update=none -c submodule."src/runtime_src/core/common/aiebu".update=none submodule update --init --recursive --depth 1 --single-branch -j 10
git -c submodule."third_party/torch-mlir".update=none \
-c submodule."third_party/stablehlo".update=none \
-c submodule."src/runtime_src/core/common/aiebu".update=none \
submodule update --init --recursive --depth 1 --single-branch -j 10
- name: Setup Cpp
uses: aminya/setup-cpp@v1
Expand All @@ -86,6 +89,11 @@ jobs:
key: ${{ env.CACHE_KEY }}
restore-keys: windows-build-test-cpp-

- name: Peano dep
run: |
.\build_tools\download_peano.ps1
Add-Content -Path $env:GITHUB_ENV -Value "PEANO_INSTALL_DIR=$PWD\llvm-aie"
- name: Build packages
run: |
$env:cache_dir = "${{ env.CACHE_DIR }}"
Expand Down
12 changes: 10 additions & 2 deletions build_tools/build_test_cpp.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,18 @@ $CMAKE_ARGS = @(
"-DIREE_TARGET_BACKEND_DEFAULTS=OFF"
"-DIREE_TARGET_BACKEND_LLVM_CPU=ON"
"-DIREE_CMAKE_PLUGIN_PATHS=$repo_root"
"-DIREE_EXTERNAL_HAL_DRIVERS=xrt"
"-DIREE_EXTERNAL_HAL_DRIVERS=xrt;xrt-lite"
"-DIREE_BUILD_PYTHON_BINDINGS=ON"
# iree/runtime/src/iree/hal/cts/cts_test_base.h:173:24: error: unused variable 'device_buffer' [-Werror,-Wunused-variable]
"-DIREE_ENABLE_WERROR_FLAG=OFF"
)

$peano_install_dir = "$env:PEANO_INSTALL_DIR"
if ($peano_install_dir -and (Test-Path "$peano_install_dir"))
{
$CMAKE_ARGS += @("-DPEANO_INSTALL_DIR=$peano_install_dir")
}

if ($llvm_install_dir -and (Test-Path "$llvm_install_dir"))
{
echo "using existing llvm install @ $llvm_install_dir"
Expand Down Expand Up @@ -121,7 +129,7 @@ echo "-----"
# better have git-bash installed...
$env:Path = "C:\Program Files\Git\bin;$env:Path"
pushd $build_dir
& bash -l -c "ctest -R amd-aie --output-on-failure -j --repeat until-pass:5"
& bash -l -c "ctest -R amd-aie -E driver/xrt-lite --output-on-failure -j --repeat until-pass:5"
popd

if ($llvm_install_dir -and (Test-Path "$llvm_install_dir"))
Expand Down
111 changes: 65 additions & 46 deletions build_tools/build_test_cpp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ mkdir -p "${cache_dir}/pip"
python="$(which python)"
echo "Using python: $python"

if [[ "$OSTYPE" == "linux-gnu"* ]]; then
if [[ "$OSTYPE" == "linux"* ]]; then
export CMAKE_TOOLCHAIN_FILE="$this_dir/linux_default_toolchain.cmake"
export CC=clang
export CXX=clang++
Expand Down Expand Up @@ -61,54 +61,73 @@ echo '{
}' > $iree_dir/CMakeUserPresets.json

cd $iree_dir
CMAKE_ARGS="\
-GNinja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=$install_dir \
-DCMAKE_INSTALL_LIBDIR=lib \
-DIREE_ERROR_ON_MISSING_SUBMODULES=OFF \
-DIREE_ENABLE_ASSERTIONS=ON \
-DIREE_BUILD_SAMPLES=OFF \
-DIREE_BUILD_PYTHON_BINDINGS=ON \
-DIREE_BUILD_BINDINGS_TFLITE=OFF \
-DIREE_HAL_DRIVER_DEFAULTS=OFF \
-DIREE_HAL_DRIVER_LOCAL_SYNC=ON \
-DIREE_HAL_DRIVER_LOCAL_TASK=ON \
-DIREE_TARGET_BACKEND_DEFAULTS=OFF \
-DIREE_TARGET_BACKEND_LLVM_CPU=ON \
-DIREE_INPUT_TOSA=OFF \
-DIREE_INPUT_STABLEHLO=OFF \
-DIREE_INPUT_TORCH=OFF \
-DCMAKE_OBJECT_PATH_MAX=4096 \
-DIREE_CMAKE_PLUGIN_PATHS=$repo_root"

if [ -d "${llvm_install_dir}" ]; then
CMAKE_ARGS="$CMAKE_ARGS \
-DIREE_BUILD_BUNDLED_LLVM=OFF \
-DClang_DIR=$llvm_install_dir/lib/cmake/clang \
-DLLD_DIR=$llvm_install_dir/lib/cmake/lld \
-DMLIR_DIR=$llvm_install_dir/lib/cmake/mlir \
-DLLVM_DIR=$llvm_install_dir/lib/cmake/llvm"
CMAKE_ARGS=(
-GNinja
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_INSTALL_PREFIX="$install_dir"
-DCMAKE_INSTALL_LIBDIR=lib
-DIREE_ERROR_ON_MISSING_SUBMODULES=OFF
-DIREE_ENABLE_ASSERTIONS=ON
-DIREE_BUILD_SAMPLES=OFF
-DIREE_BUILD_PYTHON_BINDINGS=ON
-DIREE_BUILD_BINDINGS_TFLITE=OFF
-DIREE_HAL_DRIVER_DEFAULTS=OFF
-DIREE_HAL_DRIVER_LOCAL_SYNC=ON
-DIREE_HAL_DRIVER_LOCAL_TASK=ON
-DIREE_TARGET_BACKEND_DEFAULTS=OFF
-DIREE_TARGET_BACKEND_LLVM_CPU=ON
-DIREE_INPUT_TOSA=OFF
-DIREE_INPUT_STABLEHLO=OFF
-DIREE_INPUT_TORCH=OFF
-DCMAKE_OBJECT_PATH_MAX=4096
-DIREE_CMAKE_PLUGIN_PATHS="$repo_root"
# iree/runtime/src/iree/hal/cts/cts_test_base.h:173:24: error: unused variable 'device_buffer' [-Werror,-Wunused-variable]
-DIREE_ENABLE_WERROR_FLAG=OFF
)

PEANO_INSTALL_DIR=${PEANO_INSTALL_DIR:-""}
if [ "$PEANO_INSTALL_DIR" != "" ] && [ -d "$PEANO_INSTALL_DIR" ]; then
CMAKE_ARGS+=(-DPEANO_INSTALL_DIR="$PEANO_INSTALL_DIR")
fi

if [[ "$OSTYPE" == "linux-gnu"* ]]; then
cmake $CMAKE_ARGS \
-DCMAKE_EXE_LINKER_FLAGS_INIT="-fuse-ld=lld" \
-DCMAKE_SHARED_LINKER_FLAGS_INIT="-fuse-ld=lld" \
-DCMAKE_MODULE_LINKER_FLAGS_INIT="-fuse-ld=lld" \
-DCMAKE_C_COMPILER="${CC}" \
-DCMAKE_CXX_COMPILER="${CXX}" \
-DLLVM_TARGET_ARCH=X86 \
-DLLVM_TARGETS_TO_BUILD=X86 \
-DIREE_EXTERNAL_HAL_DRIVERS=xrt \
-S $iree_dir -B $build_dir
if [ -d "$llvm_install_dir" ]; then
CMAKE_ARGS+=(
-DIREE_BUILD_BUNDLED_LLVM=OFF
-DClang_DIR="$llvm_install_dir/lib/cmake/clang"
-DLLD_DIR="$llvm_install_dir/lib/cmake/lld"
-DMLIR_DIR="$llvm_install_dir/lib/cmake/mlir"
-DLLVM_DIR="$llvm_install_dir/lib/cmake/llvm"
)
fi

if [[ "$OSTYPE" == "linux"* ]]; then
CMAKE_ARGS+=(
-DCMAKE_EXE_LINKER_FLAGS_INIT="-fuse-ld=lld"
-DCMAKE_SHARED_LINKER_FLAGS_INIT="-fuse-ld=lld"
-DCMAKE_MODULE_LINKER_FLAGS_INIT="-fuse-ld=lld"
-DCMAKE_C_COMPILER="${CC}"
-DCMAKE_CXX_COMPILER="${CXX}"
-DLLVM_TARGET_ARCH=X86
-DLLVM_TARGETS_TO_BUILD=X86
-DIREE_EXTERNAL_HAL_DRIVERS="xrt;xrt-lite"
-S
"$iree_dir"
-B
"$build_dir"
)
elif [[ "$OSTYPE" == "darwin"* ]]; then
cmake $CMAKE_ARGS \
-DLLVM_TARGET_ARCH="X86;ARM" \
-DLLVM_TARGETS_TO_BUILD="X86;ARM" \
-S $iree_dir -B $build_dir
CMAKE_ARGS+=(
-DLLVM_TARGET_ARCH="X86;ARM"
-DLLVM_TARGETS_TO_BUILD="X86;ARM"
-S
"$iree_dir"
-B
"$build_dir"
)
fi

cmake "${CMAKE_ARGS[@]}"

echo "Building all"
echo "------------"
cmake --build "$build_dir" -- -k 0
Expand All @@ -123,8 +142,8 @@ cmake --build "$build_dir" --target iree-install-dist

echo "CTest"
echo "-----"
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
ctest --test-dir "$build_dir" -R amd-aie --output-on-failure -j
if [[ "$OSTYPE" == "linux"* ]]; then
ctest --test-dir "$build_dir" -R amd-aie -E "driver/xrt-lite" --output-on-failure -j
elif [[ "$OSTYPE" == "darwin"* ]]; then
ctest --test-dir "$build_dir" -R amd-aie -E "matmul_pack_peel_air_e2e|matmul_elementwise_pack_peel_air_e2e|conv_fill_spec_pad" --output-on-failure -j --repeat until-pass:5
fi
Expand Down
5 changes: 4 additions & 1 deletion build_tools/download_peano.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ $ErrorActionPreference = 'Stop'
$this_dir = Split-Path -Path $MyInvocation.MyCommand.Path -Parent
$RELEASE = (Get-Content -Path "$this_dir/peano_commit.txt")
pip download llvm_aie==$RELEASE -f https://github.com/Xilinx/llvm-aie/releases/expanded_assets/nightly
Expand-Archive (Get-ChildItem -Filter llvm*.whl).FullName -DestinationPath $PWD.Path
$peano = (Get-ChildItem -Filter llvm*.whl)
$new_name = ($peano.Basename + ".zip")
Rename-Item -Path $peano.Name -NewName $new_name
Expand-Archive $new_name -DestinationPath $PWD.Path
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,11 @@ struct amdxdna_cu_config {
* @pad: MBZ
* @cu_configs: Array of CU configurations of struct amdxdna_cu_config
*/
struct amdxdna_hwctx_param_config_cu {
__u16 num_cus;
__u16 pad[3];
struct amdxdna_cu_config cu_configs[] __counted_by(num_cus);
};
// struct amdxdna_hwctx_param_config_cu {
// __u16 num_cus;
// __u16 pad[3];
// struct amdxdna_cu_config cu_configs[] __counted_by(num_cus);
// };

enum amdxdna_drm_config_hwctx_param {
DRM_AMDXDNA_HWCTX_CONFIG_CU,
Expand Down
17 changes: 9 additions & 8 deletions runtime/src/iree-amd-aie/driver/xrt-lite/shim/linux/kmq/bo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
#include <unistd.h>
#include <x86intrin.h>

#include "pcidev.h"
#include "shim_debug.h"

namespace {

uint32_t alloc_drm_bo(const shim_xdna::pdev& dev, amdxdna_bo_type type,
void* buf, size_t size) {
amdxdna_drm_create_bo cbo = {
.type = type,
.type = static_cast<uint32_t>(type),
.vaddr = reinterpret_cast<uintptr_t>(buf),
.size = size,
};
Expand All @@ -38,7 +39,7 @@ void get_drm_bo_info(const shim_xdna::pdev& dev, uint32_t boh,
void* map_parent_range(size_t size) {
auto p = ::mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS,
-1, 0);
if (!p) shim_err(errno, "mmap(len=%ld) failed", size);
if (!p) shim_xdna::shim_err(errno, "mmap(len=%ld) failed", size);

return p;
}
Expand Down Expand Up @@ -101,7 +102,7 @@ bool is_power_of_two(size_t x) { return (x > 0) && ((x & (x - 1)) == 0); }

void* addr_align(void* p, size_t align) {
if (!is_power_of_two(align))
shim_err(EINVAL, "Alignment 0x%lx is not power of two", align);
shim_xdna::shim_err(EINVAL, "Alignment 0x%lx is not power of two", align);

return (void*)(((uintptr_t)p + align) & ~(align - 1));
}
Expand Down Expand Up @@ -129,7 +130,8 @@ inline void clflush_data(const void* base, size_t offset, size_t len) {

if (!cacheline_size) {
long sz = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
if (sz <= 0) shim_err(EINVAL, "Invalid cache line size: %ld", sz);
if (sz <= 0)
shim_xdna::shim_err(EINVAL, "Invalid cache line size: %ld", sz);
cacheline_size = sz;
}

Expand Down Expand Up @@ -313,8 +315,7 @@ std::unique_ptr<shared_handle> bo::share() const {

amdxdna_bo_type bo::get_type() const { return m_type; }

bo::bo(const device& device, hw_ctx::slot_id ctx_id, size_t size,
uint64_t flags)
bo::bo(const device& device, uint32_t ctx_id, size_t size, uint64_t flags)
: bo(device, ctx_id, size, flags, flag_to_type(flags)) {
if (m_type == AMDXDNA_BO_INVALID)
shim_err(EINVAL, "Invalid BO flags: 0x%lx", flags);
Expand All @@ -323,8 +324,8 @@ bo::bo(const device& device, hw_ctx::slot_id ctx_id, size_t size,
bo::bo(const device& device, size_t size, amdxdna_bo_type type)
: bo(device, AMDXDNA_INVALID_CTX_HANDLE, size, 0, type) {}

bo::bo(const device& device, hw_ctx::slot_id ctx_id, size_t size,
uint64_t flags, amdxdna_bo_type type)
bo::bo(const device& device, uint32_t ctx_id, size_t size, uint64_t flags,
amdxdna_bo_type type)
: m_pdev(device.get_pdev()),
m_aligned_size(size),
m_flags(flags),
Expand Down
15 changes: 9 additions & 6 deletions runtime/src/iree-amd-aie/driver/xrt-lite/shim/linux/kmq/bo.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
#define _BO_XDNA_H_

#include <atomic>
#include <map>
#include <mutex>
#include <string>

#include "amdxdna_accel.h"
#include "device.h"
#include "hwctx.h"
#include "pcidev.h"
#include "shared.h"
#include "shim_debug.h"

Expand Down Expand Up @@ -62,6 +61,9 @@ struct xcl_bo_flags {
};
};

struct device;
struct pdev;

struct bo {
// map_type - determines how a buffer is mapped
enum class map_type { read, write };
Expand All @@ -87,10 +89,11 @@ struct bo {
uint64_t kmhdl; // kernel mode handle
};

bo(const device& device, hw_ctx::slot_id ctx_id, size_t size, uint64_t flags,
using uint32_t = uint32_t;
bo(const device& device, uint32_t ctx_id, size_t size, uint64_t flags,
amdxdna_bo_type type);

bo(const device& device, hw_ctx::slot_id ctx_id, size_t size, uint64_t flags);
bo(const device& device, uint32_t ctx_id, size_t size, uint64_t flags);

bo(const device& device, shared_handle::export_handle ehdl);

Expand Down Expand Up @@ -171,7 +174,7 @@ struct bo {

// Used when exclusively assigned to a HW context. By default, BO is shared
// among all HW contexts.
hw_ctx::slot_id m_owner_ctx_id = AMDXDNA_INVALID_CTX_HANDLE;
uint32_t m_owner_ctx_id = AMDXDNA_INVALID_CTX_HANDLE;

void bind_at(size_t pos, const bo* bh, size_t offset, size_t size);

Expand Down
19 changes: 8 additions & 11 deletions runtime/src/iree-amd-aie/driver/xrt-lite/shim/linux/kmq/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@

#include "device.h"

#include <sys/syscall.h>
#include <unistd.h>

#include <any>
#include <filesystem>

#include "bo.h"
#include "hwctx.h"
#include "pcidev.h"

namespace shim_xdna {

device::device(const pdev& pdev, handle_type shim_handle)
device::device(const pdev& pdev, void* shim_handle)
: m_pdev(pdev), m_handle(shim_handle) {
shim_debug("Created KMQ device (%s) ...", get_pdev().m_sysfs_name.c_str());
}
Expand All @@ -24,16 +21,16 @@ device::~device() {
m_pdev.close();
}

std::unique_ptr<hw_ctx> device::create_hw_context(
const device& dev, const hw_ctx::qos_type& qos) const {
return std::make_unique<hw_ctx>(dev, qos);
}
// std::unique_ptr<hw_ctx> device::create_hw_context(
// const device& dev, const hw_ctx::qos_type& qos) const {
// return std::make_unique<hw_ctx>(dev, qos);
// }

std::unique_ptr<bo> device::alloc_bo(void* userptr, hw_ctx::slot_id ctx_id,
std::unique_ptr<bo> device::alloc_bo(void* userptr, uint32_t ctx_id,
size_t size, uint64_t flags) {
if (userptr) shim_not_supported_err("User ptr BO");

auto b = bo(this->m_pdev, ctx_id, size, flags);
auto b = bo(*this, ctx_id, size, flags);
return std::make_unique<bo>(*this, ctx_id, size, flags);
}

Expand Down
Loading

0 comments on commit 9644459

Please sign in to comment.