diff --git a/.dockerignore b/.dockerignore index c1cd414..3a12b04 100644 --- a/.dockerignore +++ b/.dockerignore @@ -9,4 +9,5 @@ !launch.sh # YOUR FILES LISTED BELOW THIS LINE (IMPORTANT: PREPEND !) +!install_torch.sh # ---------------------------------------------------------------------------- diff --git a/Dockerfile b/Dockerfile index c5e59c2..0626a46 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,9 +8,32 @@ ARG MAJOR=daffy ARG BASE_TAG=${MAJOR}-${ARCH} ARG BASE_IMAGE=dt-core + # define base image FROM duckietown/${BASE_IMAGE}:${BASE_TAG} +ENV PATH /usr/local/nvidia/bin:/usr/local/cuda/bin:${PATH} +ENV LD_LIBRARY_PATH /usr/local/nvidia/lib:/usr/local/nvidia/lib64 + +ENV NVIDIA_VISIBLE_DEVICES all +ENV NVIDIA_DRIVER_CAPABILITIES all + +ENV CUDA_VERSION 10.2.89 +ENV CUDA_PKG_VERSION 10-2=$CUDA_VERSION-1 +ENV NCCL_VERSION 2.8.4 +ENV CUDNN_VERSION 8.1.1.33 + +ENV PYTORCH_VERSION 1.7.0 +ENV PYTORCHVISION_VERSION 0.8.0a0+2f40a48 + +ENV TENSORRT_VERSION 7.1.3.4 + +ENV PYCUDA_VERSION 2021.1 + +ARG PIP_INDEX_URL="https://pypi.org/simple" +ENV PIP_INDEX_URL=${PIP_INDEX_URL} + +RUN ln -s /usr/local/cuda-10.2 /usr/local/cuda # define repository path ARG REPO_NAME ARG REPO_PATH="${CATKIN_WS_DIR}/src/${REPO_NAME}" @@ -34,13 +57,17 @@ RUN apt-get update \ # install python dependencies RUN pip install -r ${REPO_PATH}/dependencies-py.txt - # copy the source code COPY . "${REPO_PATH}/" +RUN pwd ${REPO_PATH}/ +RUN ls ${REPO_PATH}/ + RUN cp -r "${REPO_PATH}/packages/dt-core" "${CATKIN_WS_DIR}/src/" RUN rm -r "${REPO_PATH}/packages/dt-core" +RUN bash ${REPO_PATH}/install_torch.sh + # build packages RUN . /opt/ros/${ROS_DISTRO}/setup.sh && \ catkin build \ diff --git a/dependencies-py.txt b/dependencies-py.txt index 0645b4e..43371c0 100644 --- a/dependencies-py.txt +++ b/dependencies-py.txt @@ -1 +1,2 @@ # LIST YOUR PYTHON PACKAGES HERE +# torch \ No newline at end of file diff --git a/install_torch.sh b/install_torch.sh new file mode 100644 index 0000000..4ed01c7 --- /dev/null +++ b/install_torch.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +set -e + +apt-get update +apt-get install -y --no-install-recommends \ + libopenblas-base \ + libopenmpi-dev \ + g++-8 \ + unzip +rm -rf /var/lib/apt/lists/* + +# download PyTorch +echo "Downloading PyTorch v${PYTORCH_VERSION}..." +PYTORCH_WHEEL_NAME="torch-${PYTORCH_VERSION}.cuda.cudnn-cp38-cp38-linux_aarch64.whl" +WHEEL_URL="https://duckietown-public-storage.s3.amazonaws.com/assets/python/wheels/${PYTORCH_WHEEL_NAME}" +wget -q "${WHEEL_URL}" -O "/tmp/${PYTORCH_WHEEL_NAME}" +# install PyTorch +echo "Installing PyTorch v${PYTORCH_VERSION}..." +pip3 install "/tmp/${PYTORCH_WHEEL_NAME}" +rm "/tmp/${PYTORCH_WHEEL_NAME}" + +# download TensorRT +echo "Downloading TensorRT v${TENSORRT_VERSION}..." +TENSORRT_WHEEL_NAME=tensorrt-${TENSORRT_VERSION}-cp38-cp38-linux_aarch64.whl +TENSORRT_WHEEL_URL="https://duckietown-public-storage.s3.amazonaws.com/assets/python/wheels/${TENSORRT_WHEEL_NAME}" +wget -q "${TENSORRT_WHEEL_URL}" -O "/tmp/${TENSORRT_WHEEL_NAME}" +# install TensorRT +echo "Installing TensorRT v${TENSORRT_VERSION}..." +pip3 install "/tmp/${TENSORRT_WHEEL_NAME}" +rm "/tmp/${TENSORRT_WHEEL_NAME}" + +# download PyCUDA +echo "Downloading PyCUDA v${PYCUDA_VERSION}..." +PYCUDA_WHEEL_NAME=pycuda-${PYCUDA_VERSION}-cp38-cp38-linux_aarch64.whl +PYCUDA_WHEEL_URL="https://duckietown-public-storage.s3.amazonaws.com/assets/python/wheels/${PYCUDA_WHEEL_NAME}" +wget -q "${PYCUDA_WHEEL_URL}" -O "/tmp/${PYCUDA_WHEEL_NAME}" +# install PyCUDA +echo "Installing PyCUDA v${PYCUDA_VERSION}..." +pip3 install "/tmp/${PYCUDA_WHEEL_NAME}" +rm "/tmp/${PYCUDA_WHEEL_NAME}" + +# clean +pip3 uninstall -y dataclasses \ No newline at end of file diff --git a/launch.sh b/launch.sh index bc03a90..0a9d04a 100755 --- a/launch.sh +++ b/launch.sh @@ -5,11 +5,12 @@ set -e # YOUR CODE BELOW THIS LINE # ---------------------------------------------------------------------------- echo "This is an empty launch script. Update it to launch your application." -#roslaunch circle_drive circle_drive.launch + +roslaunch circle_drive circle_drive.launch #roslaunch duckietown_demos lane_following.launch -roslaunch --wait circle_drive indefinite_navigation2.launch & +#roslaunch --wait circle_drive indefinite_navigation2.launch & #roslaunch --wait launchfile.launch & -sleep 5 +#sleep 5 # we put a short sleep in here because rostopic will fail if there's no roscore yet -rostopic pub /$VEHICLE_NAME/fsm_node/mode duckietown_msgs/FSMState '{header: {}, state: "LANE_FOLLOWING"}' +#rostopic pub /$VEHICLE_NAME/fsm_node/mode duckietown_msgs/FSMState '{header: {}, state: "LANE_FOLLOWING"}' diff --git a/packages/circle_drive/scripts/circle_drive.py b/packages/circle_drive/scripts/circle_drive.py index 3d9da79..4baf8c3 100755 --- a/packages/circle_drive/scripts/circle_drive.py +++ b/packages/circle_drive/scripts/circle_drive.py @@ -3,6 +3,7 @@ import rospy from duckietown.dtros import DTROS, NodeType from duckietown_msgs.msg import Twist2DStamped, StopLineReading +import torch class MyNode(DTROS): @@ -20,15 +21,15 @@ def run(self): # publish message every 1 second rate = rospy.Rate(0.5) # 1Hz while not rospy.is_shutdown(): - continue msg = Twist2DStamped() - msg.v = 0.0 + msg.v = 0.1 msg.omega = 1.0 - rospy.loginfo("Publishing message") + rospy.loginfo("Publishing message run") + rospy.loginfo("GPU available: {}".format(torch.cuda.is_available())) self.pub.publish(msg) rate.sleep() msg.omega = 0.0 - rospy.loginfo("Publishing message -") + rospy.loginfo("Publishing message stop") self.pub.publish(msg) rate.sleep()