crGPU is simple demo that leverages GPUs on Cloud Run to accelerate OpenCV workloads with CUDA.
- This sample demo uses Farneback algorithm for estimating optical flow. It supports both CPU and GPU (CUDA based) implementations from OpenCV.
- Python 3.x
- Docker
- Terraform
- Google Cloud Storage bucket
- Clone this repository
git clone git@github.com:NucleusEngineering/cloudrun-gpu-opencv-demo.git
- Build the container
docker build -t crgpu:latest .
- Start the Docker containers
docker run -p 8080:8080 bash crgpu:latest
- Access the application at: http://localhost:8080
- Build the image
docker build -t {GCP_REGION}-docker.pkg.dev/{YOUR_PROJECT_ID}/{YOUR_ARTIFACT_REGISTRY_NAME}/crgpu:latest .
- Push
docker push {GCP_REGION}-docker.pkg.dev/{YOUR_PROJECT_ID}/{YOUR_ARTIFACT_REGISTRY_NAME}/crgpu:latest
- Deploy
gcloud alpha run deploy {YOUR_SERVICE_NAME} \
--project {YOUR_PROJECT_ID} \
--image {GCP_REGION}-docker.pkg.dev/{YOUR_PROJECT_ID}/{YOUR_ARTIFACT_REGISTRY_NAME}/crgpu:latest \
--cpu {CPU_QTY} \
--memory {MEMORY} \
--gpu {GPU_QTY} \
--no-cpu-throttling \
--gpu-type {GPU} \
--max-instances {MAX_INSTANCES} \
--region {GCP_REGION} \
--execution-environment gen2 \
--allow-unauthenticated
- (optional) Set GCP bucket as the storage backend
gcloud beta run services update {YOUR_SERVICE_NAME} \
--project {YOUR_PROJECT_ID} \
--region {GCP_REGION} \
--add-volume name=videos,type=cloud-storage,bucket=${YOUR_GCP_BUCKET_NAME} \
--add-volume-mount volume=videos,mount-path=/app/videos \
- Create a GCS bucket (ideally in the same region where you will deploy this demo)
- In the root project folder, execute Cloud Build
gcloud builds submit --config cloudbuild.yaml --substitutions _SERVICE_NAME=your-service-name,_REGION=your-gcp-region,_BUCKET=your-gcs-bucket-name
- Get the URL where the demo was deployed
gcloud run services list | grep -i crgpu
- Check the available substitutions inside
cloudbuild.yaml
for more tailored configuration (_CPU_QTY: '8'
,_GPU_QTY: '1'
,_MAX_INSTANCES: '3'
,_MEMORY: 32Gi
,_GPU: nvidia-l4
)
Open the local or deployed url and select whether you want the video to be processed on the CPU or the GPU. Also select the post-processing effect and the resolution. Compare the stats for multiple resolutions to observe what improvments in performance GPUs bring.
⚠️ Warning This demo in its default state uses relatively expensive GPU resources. Running this demo for an extended amount of time may incur significant costs.
Apache License 2.0. See the LICENSE file.
This is not an officially supported Google product