Commit 78bf5409 authored by Jens Korinth's avatar Jens Korinth
Browse files

Software support for PE-local memories

* alpha version of software API: supports PE-local memories in transfers
  and job executions
* see documentation/pe-local-memories.md for more details
parent 7a8b1f16
Pipeline #320 passed with stage
in 2 minutes and 54 seconds
......@@ -15,7 +15,7 @@ set(GCMNDIR "${TAPASCO_HOME}/common")
set(PLATFORMDIR "${TAPASCO_HOME}/platform")
set(LIBPLATFORM_STATIC "${TAPASCO_HOME}/platform/lib/${TAPASCO_TARGET}/static/libplatform.a")
set(BASELINE_SOURCES "${SRCDIR}/tapasco_init.c"
set(AXI4MM_SOURCES "${SRCDIR}/tapasco_init.c"
"${SRCDIR}/tapasco_device.c"
"${SRCDIR}/tapasco_address_map.c")
set(COMMON_SOURCES "${CMNDIR}/tapasco_logging.c"
......@@ -26,6 +26,8 @@ set(COMMON_SOURCES "${CMNDIR}/tapasco_logging.c"
"${CMNDIR}/tapasco_status.c"
"${CMNDIR}/tapasco_version.c"
"${CMNDIR}/tapasco_memory.c"
"${CMNDIR}/tapasco_local_mem.c"
"${GCMNDIR}/src/gen_mem.c"
"${GCMNDIR}/src/gen_queue.c")
set(TAPASCO_LIBS_DIR "${TAPASCO_HOME}/arch/lib")
......@@ -34,9 +36,9 @@ link_directories("${PLATFORMDIR}/lib/${TAPASCO_TARGET}")
add_definitions(-DUSE_ASSERTIONS)
set_source_files_properties(${BASELINE_SOURCES} ${COMMON_SOURCES} PROPERTIES COMPILE_FLAGS "-g -O3 -Wall -Werror -std=gnu11")
add_library(tapasco SHARED ${BASELINE_SOURCES} ${COMMON_SOURCES})
add_library(libtapasco-static STATIC ${BASELINE_SOURCES} ${COMMON_SOURCES} ${LIBPLATFORM_STATIC})
set_source_files_properties(${AXI4MM_SOURCES} ${COMMON_SOURCES} PROPERTIES COMPILE_FLAGS "-g -O3 -Wall -Werror -std=gnu11")
add_library(tapasco SHARED ${AXI4MM_SOURCES} ${COMMON_SOURCES})
add_library(libtapasco-static STATIC ${AXI4MM_SOURCES} ${COMMON_SOURCES} ${LIBPLATFORM_STATIC})
target_link_libraries(tapasco platform atomic pthread)
set_target_properties(libtapasco-static PROPERTIES OUTPUT_NAME tapasco)
......
......@@ -30,6 +30,7 @@
#include <tapasco_scheduler.h>
#include <tapasco_logging.h>
#include <tapasco_status.h>
#include <tapasco_local_mem.h>
#include <platform.h>
#include <platform_errors.h>
......@@ -40,8 +41,24 @@ struct tapasco_dev_ctx {
tapasco_ctx_t *ctx;
tapasco_dev_id_t id;
tapasco_status_t *status;
tapasco_local_mem_t *lmem;
};
tapasco_functions_t *tapasco_device_functions(tapasco_dev_ctx_t *ctx)
{
return ctx->functions;
}
tapasco_status_t *tapasco_device_status(tapasco_dev_ctx_t *ctx)
{
return ctx->status;
}
tapasco_local_mem_t *tapasco_device_local_mem(tapasco_dev_ctx_t *ctx)
{
return ctx->lmem;
}
/** Interrupt handler callback. */
void irq_handler(int const event);
......@@ -65,6 +82,7 @@ tapasco_res_t tapasco_create_device(tapasco_ctx_t *ctx, tapasco_dev_id_t const d
res = res == TAPASCO_SUCCESS ? tapasco_functions_init(p->status,
&p->functions) : res;
res = res == TAPASCO_SUCCESS ? tapasco_jobs_init(&p->jobs) : res;
res = res == TAPASCO_SUCCESS ? tapasco_local_mem_init(p->status, &p->lmem) : res;
if (res != TAPASCO_SUCCESS) return res;
p->ctx = ctx;
p->id = dev_id;
......@@ -80,6 +98,7 @@ tapasco_res_t tapasco_create_device(tapasco_ctx_t *ctx, tapasco_dev_id_t const d
void tapasco_destroy_device(tapasco_ctx_t *ctx, tapasco_dev_ctx_t *dev_ctx)
{
platform_stop(0);
tapasco_local_mem_deinit(dev_ctx->lmem);
tapasco_jobs_deinit(dev_ctx->jobs);
tapasco_functions_deinit(dev_ctx->functions);
tapasco_status_deinit(dev_ctx->status);
......
......@@ -136,6 +136,8 @@ typedef enum {
TAPASCO_DEVICE_COPY_BLOCKING = 0,
/** return immediately after transfer was scheduled **/
TAPASCO_DEVICE_COPY_NONBLOCKING = 1,
/** copy to local memory **/
TAPASCO_DEVICE_COPY_PE_LOCAL = 2,
} tapasco_device_copy_flag_t;
/** Flags for calls to tapasco_device_acquire_job_id. **/
......@@ -301,8 +303,9 @@ tapasco_res_t tapasco_device_load_bitstream(tapasco_dev_ctx_t *dev_ctx, size_t c
* @param flags device memory allocation flags
* @return TAPASCO_SUCCESS if successful, error code otherwise
**/
tapasco_res_t tapasco_device_alloc(tapasco_dev_ctx_t *dev_ctx, tapasco_handle_t *handle,
size_t const len, tapasco_device_alloc_flag_t const flags);
tapasco_res_t tapasco_device_alloc(tapasco_dev_ctx_t *dev_ctx,
tapasco_handle_t *handle, size_t const len,
tapasco_device_alloc_flag_t const flags, ...);
/**
* Frees a previously allocated chunk of device memory.
......@@ -311,7 +314,7 @@ tapasco_res_t tapasco_device_alloc(tapasco_dev_ctx_t *dev_ctx, tapasco_handle_t
* @param flags device memory allocation flags
**/
void tapasco_device_free(tapasco_dev_ctx_t *dev_ctx, tapasco_handle_t handle,
tapasco_device_alloc_flag_t const flags);
tapasco_device_alloc_flag_t const flags, ...);
/**
* Copys memory from main memory to the FPGA device.
......@@ -322,9 +325,9 @@ void tapasco_device_free(tapasco_dev_ctx_t *dev_ctx, tapasco_handle_t handle,
* @param flags flags for copy operation, e.g., TAPASCO_COPY_NONBLOCKING
* @return TAPASCO_SUCCESS if copy was successful, TAPASCO_FAILURE otherwise
**/
tapasco_res_t tapasco_device_copy_to(tapasco_dev_ctx_t *dev_ctx, void const *src,
tapasco_handle_t dst, size_t len,
tapasco_device_copy_flag_t const flags);
tapasco_res_t tapasco_device_copy_to(tapasco_dev_ctx_t *dev_ctx,
void const *src, tapasco_handle_t dst, size_t len,
tapasco_device_copy_flag_t const flags, ...);
/**
* Copys memory from FPGA device memory to main memory.
......@@ -335,8 +338,9 @@ tapasco_res_t tapasco_device_copy_to(tapasco_dev_ctx_t *dev_ctx, void const *src
* @param flags flags for copy operation, e.g., TAPASCO_COPY_NONBLOCKING
* @return TAPASCO_SUCCESS if copy was successful, TAPASCO_FAILURE otherwise
**/
tapasco_res_t tapasco_device_copy_from(tapasco_dev_ctx_t *dev_ctx, tapasco_handle_t src,
void *dst, size_t len, tapasco_device_copy_flag_t const flags);
tapasco_res_t tapasco_device_copy_from(tapasco_dev_ctx_t *dev_ctx,
tapasco_handle_t src, void *dst, size_t len,
tapasco_device_copy_flag_t const flags, ...);
/** @} **/
......
......@@ -25,7 +25,11 @@
#include <tapasco.h>
#include <tapasco_functions.h>
#include <tapasco_status.h>
#include <tapasco_local_mem.h>
tapasco_functions_t *tapasco_device_functions(tapasco_dev_ctx_t *dev_ctx);
tapasco_status_t *tapasco_device_status(tapasco_dev_ctx_t *dev_ctx);
tapasco_local_mem_t *tapasco_device_local_mem(tapasco_dev_ctx_t *dev_ctx);
#endif /* TAPASCO_DEVICE_H__ */
//
// Copyright (C) 2018 Jens Korinth, TU Darmstadt
//
// This file is part of Tapasco (TPC).
//
// Tapasco is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Tapasco is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with Tapasco. If not, see <http://www.gnu.org/licenses/>.
//
//! @file tapasco_local_mem.h
//! @brief Helper methods to manage PE-local memories.
//! @authors J. Korinth, TU Darmstadt (jk@esa.cs.tu-darmstadt.de)
//!
#ifndef TAPASCO_LOCAL_MEM_H__
#define TAPASCO_LOCAL_MEM_H__
#include <tapasco.h>
#include <tapasco_functions.h>
#include <tapasco_status.h>
#include <gen_mem.h>
typedef struct tapasco_local_mem tapasco_local_mem_t;
tapasco_res_t tapasco_local_mem_init(tapasco_status_t const *status,
tapasco_local_mem_t **lmem);
void tapasco_local_mem_deinit(tapasco_local_mem_t *lmem);
tapasco_res_t tapasco_local_mem_alloc(tapasco_local_mem_t *lmem,
tapasco_func_slot_id_t slot_id, size_t const sz,
tapasco_handle_t *h);
void tapasco_local_mem_dealloc(tapasco_local_mem_t *lmem,
tapasco_func_slot_id_t slot_id, tapasco_handle_t h, size_t sz);
size_t tapasco_local_mem_get_size(tapasco_local_mem_t *lmem,
tapasco_func_slot_id_t slot_id);
addr_t tapasco_local_mem_get_base(tapasco_local_mem_t *lmem,
tapasco_func_slot_id_t slot_id);
#endif /* TAPASCO_LOCAL_MEM_H__ */
......@@ -34,8 +34,10 @@
* @param flags device memory allocation flags
* @return TAPASCO_SUCCESS if successful, error code otherwise
**/
tapasco_res_t tapasco_device_alloc(tapasco_dev_ctx_t *dev_ctx, tapasco_handle_t *handle,
size_t const len, tapasco_device_alloc_flag_t const flags);
tapasco_res_t tapasco_device_alloc(tapasco_dev_ctx_t *dev_ctx,
tapasco_handle_t *handle, size_t const len,
tapasco_device_alloc_flag_t const flags,
...);
/**
* Frees a previously allocated chunk of device memory.
......@@ -43,8 +45,10 @@ tapasco_res_t tapasco_device_alloc(tapasco_dev_ctx_t *dev_ctx, tapasco_handle_t
* @param handle memory chunk handle returned by @see tapasco_alloc
* @param flags device memory allocation flags
**/
void tapasco_device_free(tapasco_dev_ctx_t *dev_ctx, tapasco_handle_t handle,
tapasco_device_alloc_flag_t const flags);
void tapasco_device_free(tapasco_dev_ctx_t *dev_ctx,
tapasco_handle_t handle,
tapasco_device_alloc_flag_t const flags,
...);
/**
* Copys memory from main memory to the FPGA device.
......@@ -57,7 +61,8 @@ void tapasco_device_free(tapasco_dev_ctx_t *dev_ctx, tapasco_handle_t handle,
**/
tapasco_res_t tapasco_device_copy_to(tapasco_dev_ctx_t *dev_ctx, void const *src,
tapasco_handle_t dst, size_t len,
tapasco_device_copy_flag_t const flags);
tapasco_device_copy_flag_t const flags,
...);
/**
* Copys memory from FPGA device memory to main memory.
......@@ -68,7 +73,10 @@ tapasco_res_t tapasco_device_copy_to(tapasco_dev_ctx_t *dev_ctx, void const *src
* @param flags flags for copy operation, e.g., TAPASCO_COPY_NONBLOCKING
* @return TAPASCO_SUCCESS if copy was successful, TAPASCO_FAILURE otherwise
**/
tapasco_res_t tapasco_device_copy_from(tapasco_dev_ctx_t *dev_ctx, tapasco_handle_t src,
void *dst, size_t len, tapasco_device_copy_flag_t const flags);
tapasco_res_t tapasco_device_copy_from(tapasco_dev_ctx_t *dev_ctx,
tapasco_handle_t src,
void *dst, size_t len,
tapasco_device_copy_flag_t const flags,
...);
#endif /* TAPASCO_MEMORY_H__ */
//
// Copyright (C) 2018 Jens Korinth, TU Darmstadt
//
// This file is part of Tapasco (TPC).
//
// Tapasco is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Tapasco is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with Tapasco. If not, see <http://www.gnu.org/licenses/>.
//
/**
* @file tapasco_local_mem.c
* @brief Helper methods to manage PE-local memories.
* @author J. Korinth, TU Darmstadt (jk@esa.cs.tu-darmstadt.de)
**/
#include <tapasco_local_mem.h>
#include <tapasco_global.h>
#include <tapasco_errors.h>
#include <tapasco_logging.h>
#include <gen_mem.h>
#include <stdlib.h>
typedef struct {
addr_t base;
addr_t high;
} address_space_t;
struct tapasco_local_mem {
address_space_t as[TAPASCO_MAX_INSTANCES];
block_t *lmem[TAPASCO_MAX_INSTANCES];
};
tapasco_res_t tapasco_local_mem_init(tapasco_status_t const *status,
tapasco_local_mem_t **lmem)
{
LOG(LALL_MEM, "initialzing ...");
*lmem = (tapasco_local_mem_t *)malloc(sizeof(*lmem));
if (! *lmem) return TAPASCO_ERR_OUT_OF_MEMORY;
addr_t base = 0;
for (size_t idx = 0; idx < TAPASCO_MAX_INSTANCES; ++idx) {
size_t const sz = status->mem[idx];
LOG(LALL_MEM, "memory size for slot_id: %zd bytes", sz);
(*lmem)->lmem[idx] = sz > 0 ? gen_mem_create(base, sz) : NULL;
(*lmem)->as[idx].base = base;
(*lmem)->as[idx].high = base + sz;
if (! (*lmem)->lmem[idx]) return TAPASCO_ERR_OUT_OF_MEMORY;
if (sz) base += sz; else base = 0;
}
return TAPASCO_SUCCESS;
}
void tapasco_local_mem_deinit(tapasco_local_mem_t *lmem)
{
free(lmem);
LOG(LALL_MEM, "destroyed");
}
tapasco_res_t tapasco_local_mem_alloc(tapasco_local_mem_t *lmem,
tapasco_func_slot_id_t slot_id, size_t const sz,
tapasco_handle_t *h)
{
*h = INVALID_ADDRESS;
++slot_id;
while (*h == INVALID_ADDRESS && lmem->lmem[slot_id]) {
*h = gen_mem_malloc(&lmem->lmem[slot_id], sz);
++slot_id;
}
LOG(LALL_MEM, "request to allocate %zd bytes for slot_id #%d -> 0x%08lx",
sz, slot_id, (unsigned long)*h);
return *h != INVALID_ADDRESS ? TAPASCO_SUCCESS : TAPASCO_FAILURE;
}
void tapasco_local_mem_dealloc(tapasco_local_mem_t *lmem,
tapasco_func_slot_id_t slot_id, tapasco_handle_t h, size_t sz)
{
LOG(LALL_MEM, "request to free %zd bytes at slot_id #%d:0x%08lx",
sz, slot_id, (unsigned long)h);
++slot_id;
while (lmem->lmem[slot_id] && h > lmem->as[slot_id].high) slot_id++;
if (lmem->lmem[slot_id]) gen_mem_free(&lmem->lmem[slot_id], h, sz);
}
inline
size_t tapasco_local_mem_get_size(tapasco_local_mem_t *lmem,
tapasco_func_slot_id_t slot_id)
{
return lmem->as[slot_id].high - lmem->as[slot_id].base;
}
inline
addr_t tapasco_local_mem_get_base(tapasco_local_mem_t *lmem,
tapasco_func_slot_id_t slot_id)
{
return lmem->as[slot_id].base;
}
......@@ -25,20 +25,97 @@
#ifdef __cplusplus
#include <cstdint>
#include <cstring>
#include <cstdarg>
#else
#include <stdint.h>
#include <string.h>
#include <stdarg.h>
#endif
#include <platform.h>
#include <tapasco_memory.h>
#include <tapasco_logging.h>
#include <tapasco_errors.h>
#include <tapasco_device.h>
#include <tapasco_status.h>
#include <tapasco_local_mem.h>
#include <platform.h>
static
tapasco_res_t tapasco_device_alloc_local(tapasco_dev_ctx_t *dev_ctx,
tapasco_handle_t *h, size_t const len,
tapasco_device_alloc_flag_t const flags,
tapasco_func_slot_id_t slot_id)
{
LOG(LALL_MEM, "allocating %zd bytes of pe-local memory for function #%lu",
len, (unsigned long)slot_id);
return tapasco_local_mem_alloc(tapasco_device_local_mem(dev_ctx),
slot_id, len, h);
}
static
tapasco_res_t tapasco_device_free_local(tapasco_dev_ctx_t *dev_ctx,
tapasco_handle_t h, size_t const len,
tapasco_device_alloc_flag_t const flags,
tapasco_func_slot_id_t slot_id)
{
LOG(LALL_MEM, "freeing %zd bytes of pe-local memory for function #%lu",
len, (unsigned long)slot_id);
tapasco_local_mem_dealloc(tapasco_device_local_mem(dev_ctx), slot_id,
len, h);
return TAPASCO_SUCCESS;
}
tapasco_res_t tapasco_device_alloc(tapasco_dev_ctx_t *dev_ctx, tapasco_handle_t *h,
size_t const len, tapasco_device_alloc_flag_t const flags)
static
tapasco_res_t tapasco_device_copy_to_local(tapasco_dev_ctx_t *dev_ctx,
void const *src, tapasco_handle_t dst, size_t len,
tapasco_device_copy_flag_t const flags,
tapasco_func_slot_id_t slot_id)
{
platform_ctl_addr_t a = platform_address_get_slot_base(slot_id, 0);
addr_t lbase = tapasco_local_mem_get_base(tapasco_device_local_mem(dev_ctx), slot_id);
LOG(LALL_MEM, "copying locally to 0x%08lx of slot_id #%lu, bus address: 0x%08lx",
(unsigned long)dst, (unsigned long)slot_id, (unsigned long)a + (dst - lbase));
a += (dst - lbase);
uint32_t *lmem = (uint32_t *)src;
tapasco_res_t res = TAPASCO_SUCCESS;
for (size_t i = 0; res == TAPASCO_SUCCESS && i < len; i += sizeof(*lmem), a += sizeof(*lmem)) {
res = platform_write_ctl(a, sizeof(*lmem), &lmem[i], flags);
}
return res;
}
static
tapasco_res_t tapasco_device_copy_from_local(tapasco_dev_ctx_t *dev_ctx,
tapasco_handle_t src, void *dst, size_t len,
tapasco_device_copy_flag_t const flags,
tapasco_func_slot_id_t slot_id)
{
platform_ctl_addr_t a = platform_address_get_slot_base(slot_id, 0);
addr_t lbase = tapasco_local_mem_get_base(tapasco_device_local_mem(dev_ctx), slot_id);
LOG(LALL_MEM, "copying locally from 0x%08lx of slot_id #%lu, bus address: 0x%08lx",
(unsigned long)src, (unsigned long)slot_id, (unsigned long)a + (src - lbase));
a += (src - lbase);
uint32_t *lmem = (uint32_t *)dst;
tapasco_res_t res = TAPASCO_SUCCESS;
for (size_t i = 0; res == TAPASCO_SUCCESS && i < len; i += sizeof(*lmem), a += sizeof(*lmem)) {
res = platform_read_ctl(a, sizeof(*lmem), &lmem[i], flags);
}
return res;
}
tapasco_res_t tapasco_device_alloc(tapasco_dev_ctx_t *dev_ctx,
tapasco_handle_t *h, size_t const len,
tapasco_device_alloc_flag_t const flags,
...)
{
platform_mem_addr_t addr;
platform_res_t r;
if (flags & TAPASCO_DEVICE_ALLOC_FLAGS_PE_LOCAL) {
va_list ap; va_start(ap, flags);
tapasco_func_slot_id_t slot_id = va_arg(ap, tapasco_func_slot_id_t);
va_end(ap);
return tapasco_device_alloc_local(dev_ctx, h, len, flags, slot_id);
}
if ((r = platform_alloc(len, &addr, PLATFORM_ALLOC_FLAGS_NONE)) == PLATFORM_SUCCESS) {
LOG(LALL_MEM, "allocated %zd bytes at 0x%08x", len, addr);
*h = addr;
......@@ -50,32 +127,54 @@ tapasco_res_t tapasco_device_alloc(tapasco_dev_ctx_t *dev_ctx, tapasco_handle_t
}
void tapasco_device_free(tapasco_dev_ctx_t *dev_ctx, tapasco_handle_t handle,
tapasco_device_alloc_flag_t const flags)
tapasco_device_alloc_flag_t const flags, ...)
{
LOG(LALL_MEM, "freeing handle 0x%08x", (unsigned)handle);
if (flags & TAPASCO_DEVICE_ALLOC_FLAGS_PE_LOCAL) {
va_list ap; va_start(ap, flags);
tapasco_func_slot_id_t slot_id = va_arg(ap, tapasco_func_slot_id_t);
size_t len = va_arg(ap, size_t);
va_end(ap);
tapasco_device_free_local(dev_ctx, handle, len, flags, slot_id);
}
platform_dealloc(handle, PLATFORM_ALLOC_FLAGS_NONE);
}
tapasco_res_t tapasco_device_copy_to(tapasco_dev_ctx_t *dev_ctx, void const *src,
tapasco_handle_t dst, size_t len,
tapasco_device_copy_flag_t const flags)
tapasco_device_copy_flag_t const flags, ...)
{
LOG(LALL_MEM, "dst = 0x%08x, len = %zd, flags = %d", (unsigned)dst, len, flags);
if (flags & TAPASCO_DEVICE_COPY_NONBLOCKING)
return TAPASCO_ERR_NONBLOCKING_MODE_NOT_SUPPORTED;
if (flags & TAPASCO_DEVICE_COPY_PE_LOCAL) {
va_list ap;
va_start(ap, flags);
tapasco_func_slot_id_t slot_id = va_arg(ap, tapasco_func_slot_id_t);
va_end(ap);
return tapasco_device_copy_to_local(dev_ctx, src, dst, len, flags, slot_id);
}
if (flags)
return TAPASCO_ERR_NOT_IMPLEMENTED;
return platform_write_mem(dst, len, src, PLATFORM_MEM_FLAGS_NONE) == PLATFORM_SUCCESS ?
TAPASCO_SUCCESS : TAPASCO_FAILURE;
}
tapasco_res_t tapasco_device_copy_from(tapasco_dev_ctx_t *dev_ctx, tapasco_handle_t src,
void *dst, size_t len,
tapasco_device_copy_flag_t const flags)
tapasco_res_t tapasco_device_copy_from(tapasco_dev_ctx_t *dev_ctx,
tapasco_handle_t src, void *dst, size_t len,
tapasco_device_copy_flag_t const flags,
...)
{
LOG(LALL_MEM, "src = 0x%08x, len = %zd, flags = %d", (unsigned)src, len, flags);
if (flags & TAPASCO_DEVICE_COPY_NONBLOCKING)
return TAPASCO_ERR_NONBLOCKING_MODE_NOT_SUPPORTED;
if (flags & TAPASCO_DEVICE_COPY_PE_LOCAL) {
va_list ap;
va_start(ap, flags);
tapasco_func_slot_id_t slot_id = va_arg(ap, tapasco_func_slot_id_t);
va_end(ap);
return tapasco_device_copy_from_local(dev_ctx, src, dst, len, flags, slot_id);
}
if (flags)
return TAPASCO_ERR_NOT_IMPLEMENTED;
return platform_read_mem(src, len, dst, PLATFORM_MEM_FLAGS_NONE) == PLATFORM_SUCCESS ?
......
......@@ -29,18 +29,23 @@
#include <tapasco_logging.h>
#include <platform.h>
// TODO tapasco_scheduler needs refactoring
static inline
tapasco_res_t tapasco_transfer_to(tapasco_dev_ctx_t *dev_ctx,
tapasco_job_id_t const j_id, tapasco_transfer_t *t)
tapasco_job_id_t const j_id, tapasco_transfer_t *t,
tapasco_func_slot_id_t s_id)
{
LOG(LALL_SCHEDULER, "job %lu: executing transfer to with length %zd bytes",
(unsigned long)j_id, (unsigned long)t->len);
tapasco_res_t res = tapasco_device_alloc(dev_ctx, &t->handle, t->len, t->flags);
tapasco_res_t res = tapasco_device_alloc(dev_ctx, &t->handle, t->len,
t->flags, s_id);
if (res != TAPASCO_SUCCESS) {
ERR("job %lu: memory allocation failed!", (unsigned long)j_id);
return res;
}
res = tapasco_device_copy_to(dev_ctx, t->data, t->handle, t->len, t->flags);
res = tapasco_device_copy_to(dev_ctx, t->data, t->handle, t->len,
t->flags, s_id);
if (res != TAPASCO_SUCCESS) {
ERR("job %lu: transfer failed - %zd bytes -> 0x%08x with flags %lu",
(unsigned long)j_id, t->len,
......@@ -53,19 +58,19 @@ tapasco_res_t tapasco_transfer_to(tapasco_dev_ctx_t *dev_ctx,
static inline
tapasco_res_t tapasco_transfer_from(tapasco_dev_ctx_t *dev_ctx,
tapasco_jobs_t *jobs, tapasco_job_id_t const j_id,
tapasco_transfer_t *t)
tapasco_transfer_t *t, tapasco_func_slot_id_t s_id)
{
LOG(LALL_SCHEDULER, "job %lu: executing transfer from with length %zd bytes",
(unsigned long)j_id, (unsigned long)t->len);
tapasco_res_t res = tapasco_device_copy_from(dev_ctx, t->handle,
t->data, t->len, t->flags);
t->data, t->len, t->flags, s_id);
if (res != TAPASCO_SUCCESS) {
ERR("job %lu: transfer failed - %zd bytes <- 0x%08x with flags %lu",
(unsigned long)j_id, t->len,
(unsigned long)t->handle,
(unsigned long)t->flags);
}
tapasco_device_free(dev_ctx, t->handle, t->flags);
tapasco_device_free(dev_ctx, t->handle, t->flags, s_id, t->len);
return res;
}
......@@ -151,7 +156,7 @@ tapasco_res_t tapasco_scheduler_launch(
if (t->len > 0) {
LOG(LALL_SCHEDULER, "job %lu: transferring %zd byte arg #%u",
(unsigned long)j_id, t->len, a);
r = tapasco_transfer_to(dev_ctx, j_id, t);
r = tapasco_transfer_to(dev_ctx, j_id, t, slot_id);
if (r != TAPASCO_SUCCESS) { return r; }
LOG(LALL_SCHEDULER, "job %lu: writing handle to arg #%u (0x%08x)",
(unsigned long)j_id, a, t->handle);
......@@ -201,7 +206,7 @@ tapasco_res_t tapasco_scheduler_launch(
j_id, a);
r = tapasco_read_arg(dev_ctx, jobs, j_id, h, a);
if (r != TAPASCO_SUCCESS) { return r; }
r = tapasco_transfer_from(dev_ctx, jobs, j_id, t);
r = tapasco_transfer_from(dev_ctx, jobs, j_id, t, slot_id);
}
// ack the interrupt
......
......@@ -26,17 +26,6 @@
#ifndef GEN_MEM_H__
#define GEN_MEM_H__
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <assert.h>
#ifdef GEN_MEM_DEBUG
#define LOG(...) printf(__VA_ARGS__)
#else
#define LOG(...)
#endif
typedef uint32_t addr_t;
#define INVALID_ADDRESS ((addr_t)(-1))
......@@ -47,84 +36,13 @@ typedef struct block {
struct block *next;
} block_t;
extern
block_t *gen_mem_create(addr_t const base, size_t const range);
block_t *gen_mem_create(addr_t const base, size_t const range)
{
assert(base % sizeof(addr_t) == 0 || "base address in gen_mem_create must be aligned with word size");
assert(range % sizeof(addr_t) == 0 || "range in gen_mem_create must be aligned with word size");
block_t *b = (block_t *)malloc(sizeof(*b));
assert(b || "gen_mem_create ran out of memory!");
if (! b) return b;
b->base = base;
b->range = range;
b->next = NULL;