web-dev-qa-db-ja.com

TensorFlow v2でcudaユニファイドメモリを有効にする方法

tensorflow 1.xには、使用されているCUDA UVMをトリガーする可能性があるuse_unified_memoryper_process_gpu_memory_fractionなどのオプションがあります。しかし、これはtensorflow 2.0でどのように実行できますか?

https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/protobuf/config.proto

// If true, uses CUDA unified memory for memory allocations. If
// per_process_gpu_memory_fraction option is greater than 1.0, then unified
// memory is used regardless of the value for this field. See comments for
// per_process_gpu_memory_fraction field for more details and requirements
// of the unified memory. This option is useful to oversubscribe memory if
// multiple processes are sharing a single GPU while individually using less
// than 1.0 per process memory fraction.
bool use_unified_memory = 2;
4
donglinjy

誰かが1.xでUVMを有効にしたい場合は、per_process_gpu_memory_fraction 1以上(任意の数に)。

use_unified_memoryは何もしません。

TensorFlowのもう1つの潜在的なバグ:セッションの確立後にモデル定義をに移動したい場合があります。お気に入り

with tf.Session(GPUOptions...) as s:
    model = xxx
    s.run(model)
1
user3723199

TensorFlow 2.0の場合、tf.config.experimental apiを使用できます。
TF 1.Xと同様に、gpuの使用を制限する方法は2つあります。

(1)GPUメモリの増加を許可する
最初のオプションは、tf.config.experimental.set_memory_growthを呼び出してメモリの増加をオンにすることです
例えば;

gpus = tf.config.experimental.list_physical_devices('GPU')
tf.config.experimental.set_memory_growth(gpus[0], True)

参照 https://www.tensorflow.org/versions/r2.0/api_docs/python/tf/config/experimental/set_memory_growth

(2)GPUメモリの増加にハード制限を設定します
2番目の方法は、tf.config.experimental.set_virtual_device_configurationを使用して仮想GPUデバイスを構成し、GPUに割り当てる合計メモリにハード制限を設定することです。
例えば;

gpus = tf.config.experimental.list_physical_devices('GPU')
tf.config.experimental.set_virtual_device_configuration(
          gpus[0],
            [tf.config.experimental.VirtualDeviceConfiguration(memory_limit=1024)])

詳細については、次のリンクを参照してください https://www.tensorflow.org/versions/r2.0/api_docs/python/tf/config/experimental/set_virtual_device_configuration

お役に立てれば。

0