Skip to content

Commit

Permalink
Fixing umq log metadata to be inside umq src files
Browse files Browse the repository at this point in the history
Signed-off-by: Hayden Laccabue <[email protected]>
  • Loading branch information
hlaccabu committed Jan 14, 2025
1 parent 6a52983 commit bfaa683
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 70 deletions.
40 changes: 0 additions & 40 deletions src/shim/hwctx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ hw_ctx(const device& dev, const qos_type& qos, std::unique_ptr<hw_q> q, const xr
: m_device(dev)
, m_q(std::move(q))
, m_doorbell(0)
, m_log_buf(nullptr)
, m_syncobj(AMDXDNA_INVALID_FENCE_HANDLE)
{
shim_debug("Creating HW context...");
Expand Down Expand Up @@ -240,45 +239,6 @@ delete_ctx_on_device()
struct amdxdna_drm_destroy_hwctx arg = {};
arg.handle = m_handle;
m_device.get_pdev().ioctl(DRM_IOCTL_AMDXDNA_DESTROY_HWCTX, &arg);

fini_log_buf();
}

void
hw_ctx::
set_metadata(int num_cols, size_t size, uint64_t bo_paddr, uint8_t flag)
{
m_metadata.magic_no = CERT_MAGIC_NO;
m_metadata.major = 0;
m_metadata.minor = 1;
m_metadata.cert_log_flag = flag;
m_metadata.num_cols = num_cols;
for (int i = 0; i < num_cols; i++) {
m_metadata.col_paddr[i] = bo_paddr + size * i + sizeof(m_metadata);
m_metadata.col_size[i] = size;
}
}

void
hw_ctx::
init_log_buf()
{
size_t column_size = 1024;
auto log_buf_size = m_num_cols * column_size + sizeof(m_metadata);
m_log_bo = alloc_bo(nullptr, log_buf_size, XCL_BO_FLAGS_EXECBUF);
m_log_buf = m_log_bo->map(bo::map_type::write);
uint64_t bo_paddr = m_log_bo->get_properties().paddr;
set_metadata(m_num_cols, column_size, bo_paddr, 1);
std::memset(m_log_buf, 0, log_buf_size);
std::memcpy(m_log_buf, &m_metadata, sizeof(m_metadata));
}

void
hw_ctx::
fini_log_buf(void)
{
if (m_log_bo)
m_log_bo->unmap(m_log_buf);
}

void
Expand Down
31 changes: 2 additions & 29 deletions src/shim/hwctx.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,32 +67,15 @@ class hw_ctx : public xrt_core::hwctx_handle
protected:
const device&
get_device();
uint32_t m_num_cols;
std::unique_ptr<xrt_core::buffer_handle> m_log_bo;

struct cu_info {
std::string m_name;
size_t m_func;
std::vector<uint8_t> m_pdi;
};

enum cert_log_flag {
debug_buffer = 0,
trace_buffer
};

struct cert_log_metadata {
#define CERT_MAGIC_NO 0x43455254 // "CERT"
uint32_t magic_no;
uint8_t major;
uint8_t minor;
uint8_t cert_log_flag;
uint8_t num_cols; // how many valid cols, up to 8 for now
uint64_t col_paddr[8]; // device accessible address array for each valid col
uint32_t col_size[8]; // bo size for each valid col
};

void
set_metadata(int num_cols, size_t size, uint64_t bo_paddr, uint8_t flag);

const std::vector<cu_info>&
get_cu_info() const;

Expand All @@ -108,25 +91,15 @@ class hw_ctx : public xrt_core::hwctx_handle
void
create_ctx_on_device();

void
init_log_buf();

void
fini_log_buf();

private:
const device& m_device;
slot_id m_handle = AMDXDNA_INVALID_CTX_HANDLE;
amdxdna_qos_info m_qos = {};
std::vector<cu_info> m_cu_info;
struct cert_log_metadata m_metadata;
std::unique_ptr<hw_q> m_q;
uint32_t m_ops_per_cycle;
uint32_t m_num_cols;
uint32_t m_doorbell;
uint32_t m_syncobj;
std::unique_ptr<xrt_core::buffer_handle> m_log_bo;
void *m_log_buf;

void
delete_ctx_on_device();
Expand Down
42 changes: 41 additions & 1 deletion src/shim/umq/hwctx.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2023-2024, Advanced Micro Devices, Inc. All rights reserved.

#include "bo.h"
#include "hwctx.h"
#include "hwq.h"

Expand All @@ -12,8 +13,9 @@ namespace shim_xdna {
hw_ctx_umq::
hw_ctx_umq(const device& device, const xrt::xclbin& xclbin, const xrt::hw_context::qos_type& qos)
: hw_ctx(device, qos, std::make_unique<hw_q_umq>(device, 8), xclbin)
, m_metadata()
{
hw_ctx::init_log_buf();
init_log_buf();
hw_ctx::create_ctx_on_device();

shim_debug("Created UMQ HW context (%d)", get_slotidx());
Expand All @@ -23,6 +25,7 @@ hw_ctx_umq::
~hw_ctx_umq()
{
shim_debug("Destroying UMQ HW context (%d)...", get_slotidx());
fini_log_buf();
}

std::unique_ptr<xrt_core::buffer_handle>
Expand All @@ -35,4 +38,41 @@ alloc_bo(void* userptr, size_t size, uint64_t flags)
return dev.alloc_bo(userptr, AMDXDNA_INVALID_CTX_HANDLE, size, flags);
}

void
hw_ctx_umq::
init_log_buf()
{
size_t column_size = 1024;
auto log_buf_size = hw_ctx::m_num_cols * column_size + sizeof(m_metadata);
hw_ctx::m_log_bo = alloc_bo(nullptr, log_buf_size, XCL_BO_FLAGS_EXECBUF);
m_log_buf = hw_ctx::m_log_bo->map(xrt_core::buffer_handle::map_type::write);
uint64_t bo_paddr = hw_ctx::m_log_bo->get_properties().paddr;
set_metadata(hw_ctx::m_num_cols, column_size, bo_paddr, UMQ_DEBUG_BUFFER);
std::memset(m_log_buf, 0, log_buf_size);
std::memcpy(m_log_buf, &m_metadata, sizeof(m_metadata));
}

void
hw_ctx_umq::
fini_log_buf(void)
{
if (hw_ctx::m_log_bo)
hw_ctx::m_log_bo->unmap(m_log_buf);
}

void
hw_ctx_umq::
set_metadata(int num_cols, size_t size, uint64_t bo_paddr, enum umq_log_flag flag)
{
m_metadata.magic_no = LOG_MAGIC_NO;
m_metadata.major = 0;
m_metadata.minor = 1;
m_metadata.umq_log_flag = flag;
m_metadata.num_cols = num_cols;
for (int i = 0; i < num_cols; i++) {
m_metadata.col_paddr[i] = bo_paddr + size * i + sizeof(m_metadata);
m_metadata.col_size[i] = size;
}
}

} // shim_xdna
24 changes: 24 additions & 0 deletions src/shim/umq/hwctx.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,30 @@ class hw_ctx_umq : public hw_ctx {
std::unique_ptr<xrt_core::buffer_handle>
alloc_bo(void* userptr, size_t size, uint64_t flags) override;

private:
#define LOG_MAGIC_NO 0x43455254

enum umq_log_flag {
UMQ_DEBUG_BUFFER = 0,
UMQ_TRACE_BUFFER
};

struct umq_log_metadata {
uint32_t magic_no;
uint8_t major;
uint8_t minor;
uint8_t umq_log_flag;
uint8_t num_cols; // how many valid cols, up to 8 for now
uint64_t col_paddr[8]; // device accessible address array for each valid col
uint32_t col_size[8]; // bo size for each valid col
};

struct umq_log_metadata m_metadata;
void *m_log_buf;

void init_log_buf();
void fini_log_buf();
void set_metadata(int num_cols, size_t size, uint64_t bo_paddr, enum umq_log_flag flag);
};

} // shim_xdna
Expand Down

0 comments on commit bfaa683

Please sign in to comment.