Skip to content

Commit 1aa54e4

Browse files
author
M.Mankali
committed
FIR 760- Integrate copy2fpga file transfer to llama.cpp
1 parent 15e7365 commit 1aa54e4

File tree

5 files changed

+84
-1
lines changed

5 files changed

+84
-1
lines changed

tools/flaskIfc/copy2fpga-setup.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
echo " Remove the device "
3+
sudo bash -c "echo 1 > /sys/bus/pci/devices/0000\:01\:00.0/remove"
4+
5+
echo "rescan"
6+
sudo bash -c "echo 1 > /sys/bus/pci/rescan"
7+
8+
echo " dump the pci data"
9+
/aws/proj/rel/sw/platform/release_v0.1.1.tsv026_04_15_2025/scripts/dump-pci.sh
10+
11+
echo " set the pci bit to access mem"
12+
sudo setpci -s 0000:01:00.0 COMMAND=0x02

tools/flaskIfc/copy2fpga-x86

21.4 KB
Binary file not shown.

tools/flaskIfc/copy2fpga-x86.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#! /bin/bash
2+
# This file runs the PCIE setup needed for file transfer.
3+
# Also, it invokes the file transfer utility: copy2fpga-x86
4+
# Note: sudo permissions are needed for file transfer
5+
#
6+
echo " Inside copy2fpga-x86.sh "
7+
sudo ./copy2fpga-setup.sh
8+
echo "sudo ./copy2fpga-x86 $1"
9+
sudo ./copy2fpga-x86 $1

tools/flaskIfc/flaskIfc.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import time
55
from werkzeug.utils import secure_filename
66
import os
7+
import subprocess
8+
import mmap
9+
710

811
job_status = {"running": False, "result": "", "thread": None}
912

@@ -13,7 +16,8 @@
1316
#port = '/dev/ttyUSB2'
1417
baudrate = '921600'
1518
#baudrate = '115200'
16-
exe_path = "/usr/bin/tsi/v0.1.1.tsv31_06_06_2025/bin/"
19+
#exe_path = "/usr/bin/tsi/v0.1.1.tsv31_06_06_2025/bin/"
20+
exe_path = "/usr/bin/tsi/v0.1.1*/bin/"
1721

1822
DEFAULT_REPEAT_PENALTY = 1.5
1923
DEFAULT_BATCH_SIZE = 1024
@@ -106,6 +110,50 @@ def upload_serial_command():
106110
# except subprocess.CalledProcessError as e:
107111
# return f"Error executing script: {e.stderr}", 500
108112

113+
@app.route('/uploadtofpga-file', methods=['GET', 'POST'])
114+
def uploadtofpga_file():
115+
setupprints = "Before:Copy2fpga-setup.sh"
116+
print(setupprints)
117+
118+
if request.method == 'POST':
119+
# Check if a file was submitted
120+
if 'file' not in request.files:
121+
return "No file part"
122+
file = request.files['file']
123+
124+
# Check if the file is empty
125+
if file.filename == '':
126+
return "No file selected"
127+
128+
# Save the file if it exists
129+
if file:
130+
filename = secure_filename(file.filename)
131+
process = subprocess.Popen(["./copy2fpga-x86.sh", filename], text=True)
132+
copy2fpgax86prints = "Starting copy2fpga-x86 sending file..."
133+
print (copy2fpgax86prints)
134+
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
135+
136+
script_path = "./recvFromHost "
137+
command = f"cd {exe_path}; {script_path} {filename}"
138+
def scriptRecvFromHost():
139+
try:
140+
result = subprocess.run(['python3', 'serial_script.py', port, baudrate, command], capture_output=True, text=True, check=True)
141+
job_status["result"] = result.stdout
142+
print("FPGA Target ready to receive file: recvFromHost started..\n")
143+
print(result.stdout)
144+
recv_output = result.stdout
145+
except subprocess.CalledProcessError as e:
146+
job_status["result"] = f"Error: {e.stderr}"
147+
finally:
148+
job_status["running"] = False
149+
thread = threading.Thread(target=scriptRecvFromHost)
150+
job_status = {"running": True, "result": "", "thread": thread}
151+
thread.start()
152+
153+
stdout, stderr = process.communicate()
154+
return render_template('uploadtofpga.html', apple = process, recvoutput=f"On FPGA Target, recvFromHost completed ; transf ered file:{filename} received")
155+
return render_template('upload.html') # Display the upload form
156+
109157
@app.route('/upload-file', methods=['GET', 'POST'])
110158
def upload_file():
111159
if request.method == 'POST':
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>File Transfer In Progress...</title>
5+
</head>
6+
<body>
7+
<h1> File Transfer Started. </h1>
8+
<h2> Running copy2fpga-x86.sh </h2>
9+
<pre>{{ apple }}</pre>
10+
<pre>{{ recvoutput }}</pre>
11+
<br>
12+
</body>
13+
</html>
14+

0 commit comments

Comments
 (0)