1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

cudaデバイスを使っているモジュールA、もう一つのモジュールBがあるとき、
両方のモジュールを使おうとしたきに動かなかった。
この記事は、そのような場合の解決事例の1つである。

動作環境

  • NVIDIA Jetson AGX Orin
  • JetPack 5.1
  • python 3.8

問題の再現方法

  1. モジュールAを動作させるpython スクリプトが問題なく動作することを確認
  2. モジュールB(TensortRTを利用)を動作させるpython スクリプトが問題なく動作することを確認
  3. モジュールAとモジュールBをimport とした状態でモジュールBの関数を実行して動作を確認した。
  4. モジュールAとモジュールBをimport とした状態でモジュールAの関数を実行したあとで、モジュールBの関数を実行して、問題が発覚した。

error 内容

TensorRTを利用しているモジュールBの関数を実行時に以下の内容のエラーを生じた。

[07/03/2024-02:17:47] [TRT] [E] 1: [resizeRunner.cpp::execute::89] Error Code 1: Cuda Runtime (invalid resource handle)

Cuda Runtime が上記のエラーを表示しても、
推論結果にはダミーの値が入っていて、
スクリプト自体は実行を継続していた。

分かること

TRT の実行時にエラーを生じていること。

実際、私の問題の生じた部分は、TRT(TensorRT)のコードの実行部分だった。


I had a similar error and that is what helped me in this case:

Remove import pycuda.autoinit and do

import pycuda.driver as cuda
...
cuda.init()
device = cuda.Device(0)
cuda_driver_context = device.make_context() 

Wrap the piece of code that does inference with TensorRT like this:

cuda_driver_context.push()
# copy data to device memory, run inference, copy data from device memory
cuda_driver_context.pop()

私の場合

cuda_driver_context 関わるコードに対応する変更を加えることで、
2つのモジュールを呼び出しても、推論が行われて、上記のエラーを生じなくなった。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?