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

Get server running inside Docker #1

Open
wants to merge 2 commits into
base: master
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
20 changes: 10 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
FROM ubuntu:18.04

# Use the official Python image.
# https://hub.docker.com/_/python
FROM python:3.7
RUN apt-get -y update
RUN apt-get -y install wget
RUN wget https://www.xilinx.com/bin/public/openDownload?filename=xrt_201920.2.3.1301_18.04-xrt.deb -O xrt_201920.2.3.1301_18.04-xrt.deb

RUN apt-get -y install /xrt_201920.2.3.1301_18.04-xrt.deb

# Copy local code to the container image.
ENV APP_HOME /app
WORKDIR $APP_HOME
COPY . .

# Install production dependencies.
# RUN pip install gunicorn
RUN pip install grpcio
RUN pip install tensorflow
RUN pip install keras
RUN apt-get -y install python3-pip
RUN pip3 install grpcio tensorflow keras

# Run the web service on container startup. Here we use the gunicorn
# webserver, with one worker process and 8 threads.
Expand All @@ -22,5 +22,5 @@ RUN pip install keras
#CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 app:app

#EXPOSE 50051

CMD ["python", "./server.py"]
COPY go.sh /go.sh
CMD /go.sh
1 change: 0 additions & 1 deletion IP.txt

This file was deleted.

11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ source /opt/xilinx/xrt/setup.sh
python3 server.py &
```

To build server from Docker:
```
docker build -t fpga-server-grpc .
```

To run server from Docker:
```
export PORT=50051
./docker_run_xilinx.sh -p ${PORT}:${PORT} -e FPGA_SERVER_PORT=${PORT} -v ${PWD}:/app fpga-server-grpc
```

To run client (from anywhere):
```
python3 client-wait.py
Expand Down
17 changes: 10 additions & 7 deletions client-wait.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
import logging, grpc, time

import numpy as np
from optparse import OptionParser

import os
import server_tools_pb2
import server_tools_pb2_grpc

import keras
from keras.models import model_from_json

PORT = '50051'
f = open("IP.txt")
IP = f.read()
if IP[-1] == '\n':
IP = IP[:-1]
f.close()

def run(max_events=32):
# Get a handle to the server
channel = grpc.insecure_channel(IP+':'+PORT)
Expand Down Expand Up @@ -57,6 +52,14 @@ def run(max_events=32):

if __name__ == '__main__':
logging.basicConfig()
parser = OptionParser()
parser.add_option("-p", "--port", dest="PORT", default='50051')
parser.add_option("-s", "--server", dest="IP", default='prp-gpu-1.t2.ucsd.edu')
(options, args) = parser.parse_args()

PORT = os.getenv("FPGA_SERVER_PORT", options.PORT)
IP = os.getenv("FPGA_SERVER_NAME", options.IP)

# Repeat so that you can change the image
while input('Run? ') == '':
run(max_events = 16384)
26 changes: 26 additions & 0 deletions docker_run_xilinx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
user=`whoami`

xclmgmt_driver="$(find /dev -name xclmgmt\*)"
docker_devices=""
echo "Found xclmgmt driver(s) at ${xclmgmt_driver}"
for i in ${xclmgmt_driver} ;
do
docker_devices+="--device=$i "
done

render_driver="$(find /dev/dri -name renderD\*)"
echo "Found render driver(s) at ${render_driver}"
for i in ${render_driver} ;
do
docker_devices+="--device=$i "
done

#sudo \
docker run \
--rm \
-it \
$docker_devices \
--name fpga-server-grpc \
$*

4 changes: 4 additions & 0 deletions go.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

source /opt/xilinx/xrt/setup.sh
python3 /app/server.py
9 changes: 8 additions & 1 deletion server.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@
# limitations under the License.

from concurrent import futures
from optparse import OptionParser

import logging, grpc, time
import numpy as np
import os
import ml_functions as ml
import threading

import server_tools_pb2
import server_tools_pb2_grpc

_ONE_DAY_IN_SECONDS = 60 * 60 * 24
PORT='50051'

global processes, max_id, results, max_client_ids, max_client_id, new_client_permitted, times
processes = {}
Expand Down Expand Up @@ -99,6 +101,7 @@ def serve():
server_tools_pb2_grpc.add_MnistServerServicer_to_server(MnistServer(), server)
server.add_insecure_port('[::]:'+PORT)
server.start()
print(f"Listening on port {PORT}")
print("READY")
try:
while True:
Expand All @@ -110,4 +113,8 @@ def serve():

if __name__ == '__main__':
logging.basicConfig()
parser = OptionParser()
parser.add_option("-p", "--port", dest="PORT", default='50051')
(options, args) = parser.parse_args()
PORT = os.getenv("FPGA_SERVER_PORT", options.PORT)
serve()