Python Forum
How to run detectron2, as python embedded code in C++, on GPU?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to run detectron2, as python embedded code in C++, on GPU?
#1
I want to run detectron2 prediction as a Python Code embedded in a WebRTC C++ code. I am using webrtc-streamer as a C++ server in which I want to embed detectron2 Python code to call a prediction function. Everything works fine when I run the executable of webrtc-streamer and call a test function in Python code. However, when I call the prediction function, the program just hangs there forever on the prediction call.

My question is, how can I embed a detectron2 python code in a C++ code such that the python code runs on Nvidia GPU?
Or if there is something else that prevents such embedding to not even executing and hang in the first place. Is it something related to the Python interpreter?

Please, let me know if more information is required.
Any help would be highly appreciated.
Thank you.


Expected behavior:
The embedded Python code of detectron2 should run on GPU.

Environment:
Output:
PyTorch version: 2.0.1 Is debug build: False CUDA used to build PyTorch: 11.7 ROCM used to build PyTorch: N/A OS: Ubuntu 22.04.2 LTS (x86_64) GCC version: (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0 Clang version: Could not collect CMake version: version 3.22.1 Libc version: glibc-2.35 Python version: 3.11.3 (main, Apr 19 2023, 23:54:32) [GCC 11.2.0] (64-bit runtime) Python platform: Linux-5.19.0-41-generic-x86_64-with-glibc2.35 Is CUDA available: True CUDA runtime version: Could not collect CUDA_MODULE_LOADING set to: LAZY GPU models and configuration: GPU 0: NVIDIA GeForce GTX 1080 Ti Nvidia driver version: 530.41.03 cuDNN version: Could not collect HIP runtime version: N/A MIOpen runtime version: N/A Is XNNPACK available: True CPU: Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Address sizes: 39 bits physical, 48 bits virtual Byte Order: Little Endian CPU(s): 2 On-line CPU(s) list: 0,1 Vendor ID: GenuineIntel Model name: Intel(R) Pentium(R) CPU G4400 @ 3.30GHz CPU family: 6 Model: 94 Thread(s) per core: 1 Core(s) per socket: 2 Socket(s): 1 Stepping: 3 CPU max MHz: 3300.0000 CPU min MHz: 800.0000 BogoMIPS: 6599.98 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust erms invpcid rdseed smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d arch_capabilities Virtualization: VT-x L1d cache: 64 KiB (2 instances) L1i cache: 64 KiB (2 instances) L2 cache: 512 KiB (2 instances) L3 cache: 3 MiB (1 instance) NUMA node(s): 1 NUMA node0 CPU(s): 0,1 Vulnerability Itlb multihit: KVM: Mitigation: VMX disabled Vulnerability L1tf: Mitigation; PTE Inversion; VMX conditional cache flushes, SMT disabled Vulnerability Mds: Mitigation; Clear CPU buffers; SMT disabled Vulnerability Meltdown: Mitigation; PTI Vulnerability Mmio stale data: Mitigation; Clear CPU buffers; SMT disabled Vulnerability Retbleed: Mitigation; IBRS Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization Vulnerability Spectre v2: Mitigation; IBRS, IBPB conditional, RSB filling, PBRSB-eIBRS Not affected Vulnerability Srbds: Mitigation; Microcode Vulnerability Tsx async abort: Not affected Versions of relevant libraries: [pip3] mypy-extensions==1.0.0 [pip3] numpy==1.24.3 [pip3] torch==2.0.1 [pip3] torchaudio==2.0.2 [pip3] torchvision==0.15.2 [pip3] triton==2.0.0 [conda] blas 1.0 mkl [conda] ffmpeg 4.3 hf484d3e_0 pytorch [conda] mkl 2023.1.0 h6d00ec8_46342 [conda] mkl-service 2.4.0 py311h5eee18b_1 [conda] mkl_fft 1.3.6 py311ha02d727_1 [conda] mkl_random 1.2.2 py311ha02d727_1 [conda] numpy 1.24.3 py311h08b1b3b_1 [conda] numpy-base 1.24.3 py311hf175353_1 [conda] pytorch 2.0.1 py3.11_cuda11.7_cudnn8.5.0_0 pytorch [conda] pytorch-cuda 11.7 h778d358_5 pytorch [conda] pytorch-mutex 1.0 cuda pytorch [conda] torchaudio 2.0.2 py311_cu117 pytorch [conda] torchtriton 2.0.0 py311 pytorch [conda] torchvision 0.15.2 py311_cu117 pytorch
Reply
#2
To do this in CMake, do this in your CMakeLists.txt file threes:

find_package(Python3 REQUIRED COMPONENTS Development)
include_directories(myProject ${Python3_INCLUDE_DIRS})
target_link_libraries(myProject PRIVATE ${Python3_LIBRARIES})
Reply
#3
(May-18-2023, 09:09 AM)Navarro Wrote: To do this in CMake, do this in your CMakeLists.txt file threes:

find_package(Python3 REQUIRED COMPONENTS Development)
include_directories(myProject ${Python3_INCLUDE_DIRS})
target_link_libraries(myProject PRIVATE ${Python3_LIBRARIES})

I have already added these lines in the CMakeLists.txt to make Python work.
Python test code executes, but the torch code that requires GPU does not. It just blocks there on the prediction function.
Reply
#4
Getting Started with Detectron2:
To run on your webcam, replace --input files with --webcam .
To run on a video, replace --input files with --video-input video. mp4 .
To run on cpu, add MODEL. DEVICE cpu after connect 4[/url]--opts .
To save outputs to a directory (for images) or a file (for webcam or video), use --output .
Gribouillis write Nov-02-2023, 05:03 PM:
Removed Off site link promotion, please read What to NOT include in a post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Adding libraries to embedded Python as a ZIP The_Oman 0 1,247 May-05-2023, 04:05 PM
Last Post: The_Oman
Bug Embedded Python Memory Leaks Alexei 1 1,036 Sep-16-2022, 01:15 PM
Last Post: Alexei
  Embedded Python in C++ Xeno 19 3,586 Aug-03-2022, 07:29 AM
Last Post: Gribouillis
  Embedded python fails to compile on Raspberry Pi tryfon 2 3,495 Dec-22-2020, 02:06 PM
Last Post: tryfon
  Can Embedded Python run any shared library on Android ? sprotz 0 2,334 Nov-08-2020, 12:21 PM
Last Post: sprotz
  How to split and combine embedded lines using less code pjfarley3 6 2,507 Aug-13-2020, 09:13 PM
Last Post: pjfarley3
  memory leak on embedded python in c++ asdf3721 3 3,408 Jul-16-2020, 06:33 AM
Last Post: Gribouillis
  Embedded Python PyObject_CallObject function JRHeisey 1 2,400 Nov-27-2019, 01:50 AM
Last Post: casevh
  Trying to implement Python into embedded OS thesurya7 2 2,417 Apr-02-2019, 06:38 PM
Last Post: ebolisa
  Multiple calls to Python interpreter embedded in C++ application yield segmentation f mmoelle1 0 2,843 Mar-21-2019, 08:54 PM
Last Post: mmoelle1

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020