nvprof / ncuを使用するには、ユーザーにsudo権限を付与する必要がありますか、またはCAP_SYS_ADMIN機能を追加する必要がありますか?なぜ?

nvprof / ncuを使用するには、ユーザーにsudo権限を付与する必要がありますか、またはCAP_SYS_ADMIN機能を追加する必要がありますか?なぜ?

nvprofCUDA 10.1以降、nsightcomputeやnsightcomputeなどのCUDAプロファイリングツールを使用して高度なncuメトリックを収集するには、ユーザーにsudo権限が必要です。

この問題の代替ソリューションは次のとおりです。

上記のリンクには、CAP_SYS_ADMINを使用してこれらの指標収集を有効にできることが記載されています。

問題を理解するために、次の洞察力のあるスタックオーバーフロー応答を見つけました。

私が間違っている場合は訂正してください。ただし、CAP_SYS_ADMINパスを引き続き使用するには、アプリケーションの機能を有効にする必要があります。そしてユーザー(ルートではない場合)

私はLinux機能に初めてアクセスし、ユーザー/アプリケーションにCAP_SYS_ADMINを提供する方が良いか、ユーザーにSUDOアクセスを許可する方が良いかわかりません。なぜ一つが他のものよりも優れているのですか?


編集:今ではまだ機能していません。

# First I executed
$ sudo setcap cap_sys_admin+ep /usr/local/cuda/bin/nvprof
# This is the command that I am executing after installing the CUDA toolkit 10.2.
$ /usr/local/cuda/bin/nvprof -o output-detailed.nvvp -f --analysis-metrics /usr/local/cuda/extras/demo_suite/vectorAdd

[Vector addition of 50000 elements]
==142443== NVPROF is profiling process 142443, command: /usr/local/cuda/extras/demo_suite/vectorAdd
Copy input data from the host memory to the CUDA device
CUDA kernel launch with 196 blocks of 256 threads
==142443== Some kernel(s) will be replayed on device 0 in order to collect all events/metrics.
==142443== Warning: ERR_NVGPUCTRPERM - The user does not have permission to profile on the target device. See the following link for instructions to enable permissions and get more information: https://developer.nvidia.com/ERR_NVGPUCTRPERM
Failed to launch vectorAdd kernel (error code unknown error)!
==142443== Warning: ERR_NVGPUCTRPERM - The user does not have permission to profile on the target device. See the following link for instructions to enable permissions and get more information: https://developer.nvidia.com/ERR_NVGPUCTRPERM
==142443== Warning: Some profiling data are not recorded. Make sure cudaProfilerStop() or cuProfilerStop() is called before application exit to flush profile data.
==142443== Generated result file: /results/nvprof/output-detailed.nvvp

しかし、sudoで実行した場合にのみ機能します。

$ sudo /usr/local/cuda/bin/nvprof -o output-detailed.nvvp -f --analysis-metrics /usr/local/cuda/extras/demo_suite/vectorAdd

[Vector addition of 50000 elements]
==142687== NVPROF is profiling process 142687, command: /usr/local/cuda/extras/demo_suite/vectorAdd
Copy input data from the host memory to the CUDA device
CUDA kernel launch with 196 blocks of 256 threads
==142687== Some kernel(s) will be replayed on device 0 in order to collect all events/metrics.
Replaying kernel "vectorAdd(float const *, float const *, float*, int)" (done)
Copy output data from the CUDA device to the host memory
Test PASSED
Done
==142687== Generated result file: /home/agostini/Development/nvprof/output-detailed.nvvp

実行可能ファイルに機能を付与し、スーパーユーザーにsudoなしでアプリケーションを実行させるだけでは十分ではありません。 sudoグループのユーザーにもPAM設定が必要ですか?

ベストアンサー1

正確にはどのように機能するのかわかりませんがCAP_SYS_ADMIN、従うのが簡単かもしれません。説明するこれにより、root以外のユーザーもプロファイラを使用できます。

echo 'options nvidia "NVreg_RestrictProfilingToAdminUsers=0"' | sudo tee -a /etc/modprobe.d/nvidia.conf
sudo update-initramfs -u 
sudo reboot

おすすめ記事