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

add qdma support #25

Open
wants to merge 2 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
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ homepage = "https://www.ingonyama.com"
repository = "https://github.com/ingonyama-zk/blaze"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
qdma = []

[dependencies]
libc = "0.2.126"
Expand Down Expand Up @@ -38,3 +40,4 @@ serde-hex = "0.1.0"
thiserror = "1.0"
num-bigint = "0.4"
num-traits = "0.2.15"
memmap2 = "0.7.1"
45 changes: 45 additions & 0 deletions parse_log_to_csv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import csv
import re

log_file = "test.log"
output_file = "output.csv"

# Regular expression patterns to match timestamps and values
timestamp_pattern = r"\[(.*?)\]"
value_pattern = r"value:\s+(.*?)$"

data = []

# Read the log file
with open(log_file, "r") as file:
lines = file.readlines()

# Iterate over each line in the log file
for i in range(len(lines)):
line = lines[i]
if "===" in line and "api values" in line:
values = []
for j in range(i+1, len(lines)):
inner_line = lines[j]
if "value:" in inner_line:
value_match = re.search(value_pattern, inner_line)
if value_match:
value = value_match.group(1)
values.append(value)
elif "===" in inner_line and "api values" in inner_line:
break
if len(values) == 3:
timestamp_match = re.search(timestamp_pattern, line)
if timestamp_match:
timestamp = timestamp_match.group(1)
data.append([timestamp] + values)

# Write the data to a CSV file
with open(output_file, "w", newline="") as csv_file:
writer = csv.writer(csv_file)
writer.writerow(["Timestamp", "ADDR_HIF2CPU_C_NOF_ELEMENTS_PENDING_ON_DMA_FIFO", "ADDR_HIF2CPU_C_NOF_RESULTS_PENDING_ON_DMA_FIFO", "ADDR_HIF2CPU_C_MAX_RECORDED_PENDING_RESULTS"]) # Write header row

# Write data rows
writer.writerows(data)

print("CSV file created successfully.")
28 changes: 28 additions & 0 deletions src/driver_client/dclient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::{
error::*,
utils::{deserialize_hex, open_channel, AccessFlags},
};
use memmap2::{MmapMut};
use serde::Deserialize;
use std::{fmt::Debug, os::unix::fs::FileExt, thread::sleep, time::Duration};

Expand Down Expand Up @@ -96,7 +97,10 @@ pub struct DriverClient {
/// Read only channel from core using DMA bus.
pub dma_c2h_read: std::fs::File,
/// Read and write file descriptor for working with a register space that uses AXI-lite protocol.
#[cfg(not(feature = "qdma"))]
pub ctrl: std::fs::File,
#[cfg(feature = "qdma")]
pub ctrl: MmapMut,
}

impl DriverClient {
Expand All @@ -117,6 +121,7 @@ impl DriverClient {
///
/// let dclient = DriverClient::new("0", DriverConfig::driver_client_c1100_cfg());
/// ```
#[cfg(not(feature = "qdma"))]
pub fn new(id: &str, cfg: DriverConfig) -> Self {
DriverClient {
cfg,
Expand All @@ -126,6 +131,24 @@ impl DriverClient {
}
}

#[cfg(feature = "qdma")]
pub fn new(bus: &str, device: &str, function: &str, cfg: DriverConfig) -> Self {
use memmap2::MmapOptions;

let device_id = &format!("{}{}{}", bus, device, function);
let mode = "-MM-0";

let ctrl_fd = open_channel(&format!("'/sys/bus/pci/devices/0000:{}:{}.{}/resource2", bus, device, function), AccessFlags::RdwrMode);
let ctrl = unsafe { MmapOptions::new().len(128 * 1024 * 1024).map_mut(&ctrl_fd) };

DriverClient {
cfg,
dma_h2c_write: open_channel(&format!("/dev/qdma{}{}", device_id, mode), AccessFlags::WrMode),
dma_c2h_read: open_channel(&format!("/dev/qdma{}{}", device_id, mode), AccessFlags::RdMode),
ctrl: ctrl.unwrap(),
}
}

// ==== DFX ====
/// Method for checking decouple status.
pub fn get_dfx_decoupling(&self) -> Result<u32> {
Expand All @@ -136,6 +159,7 @@ impl DriverClient {
}

/// Setup decouple signal to isolate the user logic during reconfiguration, protecting the shell from spurious signals.
#[cfg(not(feature = "qdma"))]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why you marked not feature only this scope of function?

pub fn set_dfx_decoupling(&self, signal: u8) -> Result<()> {
self.ctrl
.write_all_at(
Expand Down Expand Up @@ -323,6 +347,7 @@ impl DriverClient {
/// FIREWALL_ADDR::STATUS,
/// );
/// ```
#[cfg(not(feature = "qdma"))]
pub fn ctrl_read_u32<T: Debug + Into<u64> + Copy>(
&self,
base_address: u64,
Expand All @@ -349,6 +374,7 @@ impl DriverClient {
/// * `offset`: an enum which represent the specific offset for given `base_address`.
///
/// returns: u64
#[cfg(not(feature = "qdma"))]
pub fn ctrl_read_u64<T: Debug + Into<u64> + Copy>(
&self,
base_address: u64,
Expand Down Expand Up @@ -398,6 +424,7 @@ impl DriverClient {
/// 32,
/// );
/// ```
#[cfg(not(feature = "qdma"))]
pub fn ctrl_write_u32<T: Debug + Into<u64> + Copy>(
&self,
base_address: u64,
Expand Down Expand Up @@ -428,6 +455,7 @@ impl DriverClient {
/// * `offset`: an enum which represent the specific offset for given `base_address`.
/// * `data`: a byte slice containing the data to be written.
///
#[cfg(not(feature = "qdma"))]
pub fn ctrl_write<T: Debug + Into<u64> + Copy>(
&self,
base_address: u64,
Expand Down
Loading