Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jnider airbin #259

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
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
8 changes: 8 additions & 0 deletions .github/workflows/buildAndTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ jobs:
fetch-depth: 2
submodules: "true"

- name: Install necessary build tools for libelf
run: sudo apt install autoconf flex bison gawk autopoint -y

- name: Install libboost
run: sudo apt-get install -y libboost-all-dev

Expand Down Expand Up @@ -72,6 +75,9 @@ jobs:
- name: Rebuild and Install libxaie
run: utils/github-clone-build-libxaie.sh

- name: Rebuild and Install elfutils
run: utils/github-clone-build-elfutils.sh

- name: Rebuild and Install mlir-aie
run: utils/github-build-mlir-aie.sh

Expand All @@ -89,6 +95,7 @@ jobs:
-DMLIR_DIR=../llvm/install/lib/cmake/mlir/ \
-DLLVM_DIR=../llvm/install/lib/cmake/llvm/ \
-DAIE_DIR=`pwd`/../mlir-aie/install/lib/cmake/aie/ \
-DELFUTILS_DIR=$PWD/../elfutils \
-DLibXAIE_ROOT=`pwd`/../aienginev2/install \
-DAIR_RUNTIME_TARGETS:STRING="x86_64" \
-Dx86_64_TOOLCHAIN_FILE=`pwd`/../cmake/modules/toolchain_x86_64.cmake \
Expand All @@ -115,6 +122,7 @@ jobs:
-DMLIR_DIR=../llvm/install/lib/cmake/mlir/ \
-DLLVM_DIR=../llvm/install/lib/cmake/llvm/ \
-DAIE_DIR=`pwd`/../mlir-aie/install/lib/cmake/aie/ \
-DELFUTILS_DIR=$PWD/../elfutils \
-DLibXAIE_ROOT=`pwd`/../aienginev2/install \
-DAIR_RUNTIME_TARGETS:STRING="x86_64" \
-Dx86_64_TOOLCHAIN_FILE=`pwd`/../cmake/modules/toolchain_x86_64.cmake \
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ foreach(target ${AIR_RUNTIME_TARGETS})
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
-DLibXAIE_ROOT=${LibXAIE_ROOT}
-DAIE_DIR=${AIE_DIR}
-DELFUTILS_DIR=${ELFUTILS_DIR}
BUILD_ALWAYS true
STEP_TARGETS clean build install test
USES_TERMINAL_CONFIGURE true
Expand Down
25 changes: 25 additions & 0 deletions platforms/scripts/program_vck5000.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,30 @@
# CARD_IDX index of the card to be programmed, in JTAG scan-chain order (as seen by 'xsct')
# DEVICE_ID PCI BDI address of the card to be programmed
# VIVADO_INSTALL_DIR install directory of Vivado
# DRIVER_DIR directory of built driver

VIVADO_INSTALL_DIR=${VIVADO_INSTALL_DIR:=/proj/xbuilds/2022.1_released/installs/lin64/Vivado/2022.1}
DEVICE_ID=${DEVICE_ID:=0000:21:00.0}
DRIVER_DIR=${DRIVER_DIR:="../../driver"}

# these variables are used by load.tcl so they must be exported
export CARD_IDX=${CARD_IDX:=0}

# PDI file is optional
if [ -v PDI_FILE ]; then
if [[ ! -e $PDI_FILE ]]; then
echo "Can't find $PDI_FILE"
exit
fi
export PDI_FILE=$PDI_FILE
fi

# ELF file is optional
if [ -v ELF_FILE ]; then
if [[ ! -e $ELF_FILE ]]; then
echo "Can't find $ELF_FILE"
exit
fi
export ELF_FILE=$ELF_FILE
fi

Expand All @@ -46,6 +56,15 @@ script_path=${this_script%/*}
# start the hardware server in daemon mode (if it is not already running)
hw_server -d

# if the driver is loaded, stop it
driver_loaded=0
lsmod | grep amdair
if [[ $? == 0 ]]; then
echo "Unloading driver"
sudo rmmod amdair
driver_loaded=1
fi

# remove the PCI device in case it is already loaded
echo "Removing device"
sudo sh -c "echo 1 > /sys/bus/pci/devices/$DEVICE_ID/remove"
Expand All @@ -57,3 +76,9 @@ xsct $script_path/load.tcl
# rescan PCIe bus
echo "Scanning for new devices"
sudo sh -c "echo '1' > /sys/bus/pci/rescan"

# reload the driver if needed
if [[ $driver_loaded == 1 ]]; then
echo "Reloading driver"
sudo insmod $DRIVER_DIR/amdair.ko
fi
11 changes: 11 additions & 0 deletions runtime_lib/airhost/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/include
${AIE_INCLUDE_DIRS}/../runtime_lib/x86_64/test_lib/include
${ELFUTILS_DIR}/libelf
)

add_definitions(-DLIBXAIENGINEV2)
Expand Down Expand Up @@ -39,11 +40,21 @@ add_library(airhost_shared SHARED
)
set_property(TARGET airhost_shared PROPERTY POSITION_INDEPENDENT_CODE ON)

add_library(libelf_pic STATIC IMPORTED)
set_target_properties(libelf_pic PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${ELFUTILS_DIR}/libelf"
IMPORTED_LOCATION "${ELFUTILS_DIR}/libelf/libelf_pic.a"
)

target_link_libraries(airhost
${AIR_LIBXAIE_LIBS}
dl
)

target_link_libraries(airhost_shared
libelf_pic
)

set_target_properties(airhost PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/runtime_lib)
install(TARGETS airhost DESTINATION ${CMAKE_INSTALL_PREFIX}/runtime_lib/airhost)
Expand Down
2 changes: 2 additions & 0 deletions runtime_lib/airhost/include/air.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ inline hsa_status_t air_get_agents(std::vector<air_agent_t> &agents) {

uint64_t air_wait_all(std::vector<uint64_t> &signals);

int air_load_airbin(queue_t *q, const char *filename, uint8_t column,
uint32_t device_id = 0);
#endif
12 changes: 12 additions & 0 deletions runtime_lib/airhost/include/air_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ hsa_status_t air_get_agent_info(queue_t *queue, air_agent_info_t attribute,
hsa_status_t air_packet_rw32_init(dispatch_packet_t *pkt, bool is_write,
uint64_t address, uint32_t value);

hsa_status_t air_packet_load_airbin(dispatch_packet_t *pkt, uint64_t table);

#ifdef AIR_PCIE
hsa_status_t air_get_physical_devices();
#endif
Expand All @@ -90,9 +92,19 @@ of memory backed by the device DDR BAR and returns the virtual address to that
region. */
void *air_dev_mem_alloc(uint32_t size);

#ifndef AIR_PCIE
/* Used to obtain the physical address of a buffer allocated using the
device memory allocator. */
uint64_t air_dev_mem_get_pa(void *buff_va);
#endif // AIR_PCIE

/*
Get an offset relative to the start of device memory
This is necessary to share data structures with the device. The input address
points to device memory that is mapped in HVA (host virtual address) space.
Valid buffers are returned by air_dev_mem_alloc().
*/
uint64_t air_dev_mem_get_offset(void *buff_va);

// memory operations
//
Expand Down
5 changes: 3 additions & 2 deletions runtime_lib/airhost/include/air_host_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ typedef struct air_physical_device_s {

typedef struct air_dev_mem_allocator_s {
void *dev_mem;
uint64_t dev_mem_ptr;
uint64_t dev_mem_size;
uint64_t ptr;
uint64_t size;
uint64_t offset; // offset passed to the driver indicating location in device memory
} air_dev_mem_allocator_t;

// AIE config functions generated by AIE dialect lowering
Expand Down
1 change: 1 addition & 0 deletions runtime_lib/airhost/include/air_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#define AIR_PKT_TYPE_POST_RDMA_RECV 0x041L

#define AIR_PKT_TYPE_RW32 0x50L
#define AIR_PKT_TYPE_AIRBIN 0x51L

#define AIR_PKT_TYPE_SHIM_DMA_MEMCPY 0x0100L
#define AIR_PKT_TYPE_HERD_SHIM_DMA_MEMCPY 0x0101L
Expand Down
15 changes: 15 additions & 0 deletions runtime_lib/airhost/include/airbin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef AIRBIN_H
#define AIRBIN_H

/*
Each entry describes a loadable section in device memory. The device uses
this information to load the data into AIE memory. This definition is shared
with the device firmware.
*/
struct airbin_table_entry {
uint32_t offset; // offset into allocated device memory
uint32_t size; // size of the loadable section
uint64_t addr; // base address to load the data
};

#endif
61 changes: 48 additions & 13 deletions runtime_lib/airhost/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,33 @@ int air_init_dev_mem_allocator(uint64_t dev_mem_size, uint32_t device_id) {
}

// Initializing new struct
dev_mem_allocator->dev_mem_size = dev_mem_size;
dev_mem_allocator->dev_mem_ptr = 0;
dev_mem_allocator->size = dev_mem_size;
dev_mem_allocator->ptr = 0;

// Getting userspace pointers to device memory
#ifdef AIR_PCIE
uint64_t offset = 0x1000000;
if (dev_mem_size > 0x8000000) {
// The driver currently uses 0x8000000 as the offset for BRAM. This is not
// a fundamental limit, just short-sightedness. Once that is fixed, this
// limitation can be removed.
printf("[ERROR] Can't allocate more than 100MB because the driver is limited\n");
return -2;
}

int fd = open(air_get_driver_name(), O_RDWR | O_SYNC);
if (fd < 0) {
printf("[ERROR] Could not open DDR BAR\n");
return 1;
printf("[ERROR] Could not open driver %s\n", air_get_driver_name());
return -3;
}
dev_mem_allocator->dev_mem =
(uint32_t *)mmap(NULL, dev_mem_size /*0x8000*/, PROT_READ | PROT_WRITE,
MAP_SHARED, fd, 0x1C0000);
dev_mem_allocator->dev_mem = (uint32_t *)mmap(
NULL, dev_mem_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, offset);
if (dev_mem_allocator->dev_mem == MAP_FAILED) {
printf("[ERROR] Could not map DDR BAR\n");
return 1;
printf("[ERROR] Could not map DRAM offset %lx\n", offset);
return -4;
}
dev_mem_allocator->offset = offset;
close(fd);
#else

#ifndef __aarch64__
Expand All @@ -151,7 +161,7 @@ int air_init_dev_mem_allocator(uint64_t dev_mem_size, uint32_t device_id) {
// Freeing the device_memory_allocator
void air_dev_mem_allocator_free() {

munmap(dev_mem_allocator->dev_mem, dev_mem_allocator->dev_mem_size);
munmap(dev_mem_allocator->dev_mem, dev_mem_allocator->size);
dev_mem_allocator = NULL;
free(dev_mem_allocator);
}
Expand All @@ -170,7 +180,7 @@ void *air_dev_mem_alloc(uint32_t size) {
}

// Making sure we have enough space on the device
if (size + dev_mem_allocator->dev_mem_ptr > dev_mem_allocator->dev_mem_size) {
if (size + dev_mem_allocator->ptr > dev_mem_allocator->size) {
printf("[ERROR] Device memory cannot accept this allocation due to lack of "
"space\n");
return NULL;
Expand All @@ -179,10 +189,10 @@ void *air_dev_mem_alloc(uint32_t size) {
// Setting the user pointer equal to the next portion
// of available memory
void *user_ptr = (void *)((unsigned char *)dev_mem_allocator->dev_mem +
dev_mem_allocator->dev_mem_ptr);
dev_mem_allocator->ptr);

// Incrementing pointer by the size of memory allocated
dev_mem_allocator->dev_mem_ptr += size;
dev_mem_allocator->ptr += size;

return user_ptr;
}
Expand All @@ -192,6 +202,7 @@ void *air_dev_mem_alloc(uint32_t size) {
// in both platforms, the offsets of the virtual and physical
// address are the same, and we can directly convert between
// the two.
#ifndef AIR_PCIE
uint64_t air_dev_mem_get_pa(void *buff_va) {

// Making sure we have a real allocator
Expand All @@ -208,6 +219,30 @@ uint64_t air_dev_mem_get_pa(void *buff_va) {
// Adding that offset to our base physical address
return offset + (uint64_t)AIR_BBUFF_BASE;
}
#endif // AIR_PCIE

uint64_t air_dev_mem_get_offset(void *buff_va)
{
// Making sure we have a real allocator
if (dev_mem_allocator == NULL) {
printf(
"[ERROR] Attempting to get a physical address without a valid device "
"memory allocator. Call air_init_dev_mem_allocator() first\n");
return (uint64_t)-1;
}

if (buff_va < dev_mem_allocator->dev_mem)
return (uint64_t)-2;

if ((uint64_t)buff_va > ((uint64_t)dev_mem_allocator->dev_mem + dev_mem_allocator->size))
return (uint64_t)-3;

// Get the virtual address offset
uint64_t offset = (uint64_t)buff_va - (uint64_t)(dev_mem_allocator->dev_mem);

// Adding that offset to the allocated range
return offset + dev_mem_allocator->offset;
}

static int64_t shim_location_data(air_herd_shim_desc_t *sd, int i, int j,
int k) {
Expand Down
Loading