1
0
This commit is contained in:
2025-01-11 13:56:41 +08:00
parent c0d101ca1b
commit 81367980c1
13 changed files with 610 additions and 40 deletions

112
tf/gpu.ipynb Normal file
View File

@@ -0,0 +1,112 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2025-01-09 10:12:54.526706: I tensorflow/core/util/port.cc:153] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.\n",
"2025-01-09 10:12:54.541661: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:485] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered\n",
"2025-01-09 10:12:54.560110: E external/local_xla/xla/stream_executor/cuda/cuda_dnn.cc:8473] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered\n",
"2025-01-09 10:12:54.565525: E external/local_xla/xla/stream_executor/cuda/cuda_blas.cc:1471] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered\n",
"2025-01-09 10:12:54.578678: I tensorflow/core/platform/cpu_feature_guard.cc:211] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.\n",
"To enable the following instructions: SSE3 SSE4.1 SSE4.2 AVX, in other operations, rebuild TensorFlow with the appropriate compiler flags.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"b'Hello, TensorFlow!'\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2025-01-09 10:12:58.748603: I tensorflow/core/common_runtime/gpu/gpu_device.cc:2021] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 1143 MB memory: -> device: 0, name: NVIDIA A800 80GB PCIe, pci bus id: 0000:35:00.0, compute capability: 8.0\n",
"2025-01-09 10:12:58.751140: I tensorflow/core/common_runtime/gpu/gpu_device.cc:2021] Created device /job:localhost/replica:0/task:0/device:GPU:1 with 78412 MB memory: -> device: 1, name: NVIDIA A800 80GB PCIe, pci bus id: 0000:36:00.0, compute capability: 8.0\n",
"2025-01-09 10:12:58.752975: I tensorflow/core/common_runtime/gpu/gpu_device.cc:2021] Created device /job:localhost/replica:0/task:0/device:GPU:2 with 78412 MB memory: -> device: 2, name: NVIDIA A800 80GB PCIe, pci bus id: 0000:39:00.0, compute capability: 8.0\n",
"2025-01-09 10:12:58.754821: I tensorflow/core/common_runtime/gpu/gpu_device.cc:2021] Created device /job:localhost/replica:0/task:0/device:GPU:3 with 78412 MB memory: -> device: 3, name: NVIDIA A800 80GB PCIe, pci bus id: 0000:3d:00.0, compute capability: 8.0\n",
"2025-01-09 10:12:58.756707: I tensorflow/core/common_runtime/gpu/gpu_device.cc:2021] Created device /job:localhost/replica:0/task:0/device:GPU:4 with 78412 MB memory: -> device: 4, name: NVIDIA A800 80GB PCIe, pci bus id: 0000:9c:00.0, compute capability: 8.0\n",
"2025-01-09 10:12:58.758405: I tensorflow/core/common_runtime/gpu/gpu_device.cc:2021] Created device /job:localhost/replica:0/task:0/device:GPU:5 with 78412 MB memory: -> device: 5, name: NVIDIA A800 80GB PCIe, pci bus id: 0000:9d:00.0, compute capability: 8.0\n",
"2025-01-09 10:12:58.760115: I tensorflow/core/common_runtime/gpu/gpu_device.cc:2021] Created device /job:localhost/replica:0/task:0/device:GPU:6 with 78412 MB memory: -> device: 6, name: NVIDIA A800 80GB PCIe, pci bus id: 0000:a0:00.0, compute capability: 8.0\n",
"2025-01-09 10:12:58.761971: I tensorflow/core/common_runtime/gpu/gpu_device.cc:2021] Created device /job:localhost/replica:0/task:0/device:GPU:7 with 77296 MB memory: -> device: 7, name: NVIDIA A800 80GB PCIe, pci bus id: 0000:a4:00.0, compute capability: 8.0\n"
]
}
],
"source": [
"import tensorflow as tf\n",
"# 创建一个TensorFlow常量\n",
"hello = tf.constant('Hello, TensorFlow!')\n",
"# 将TensorFlow张量转换为NumPy数组\n",
"numpy_array = hello.numpy()\n",
"print(numpy_array) # 输出: b'Hello, TensorFlow!'"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"WARNING:tensorflow:From /tmp/ipykernel_137363/2801978163.py:2: is_gpu_available (from tensorflow.python.framework.test_util) is deprecated and will be removed in a future version.\n",
"Instructions for updating:\n",
"Use `tf.config.list_physical_devices('GPU')` instead.\n",
"True\n",
"[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU'), PhysicalDevice(name='/physical_device:GPU:1', device_type='GPU'), PhysicalDevice(name='/physical_device:GPU:2', device_type='GPU'), PhysicalDevice(name='/physical_device:GPU:3', device_type='GPU'), PhysicalDevice(name='/physical_device:GPU:4', device_type='GPU'), PhysicalDevice(name='/physical_device:GPU:5', device_type='GPU'), PhysicalDevice(name='/physical_device:GPU:6', device_type='GPU'), PhysicalDevice(name='/physical_device:GPU:7', device_type='GPU')] [PhysicalDevice(name='/physical_device:CPU:0', device_type='CPU')]\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2025-01-09 10:13:03.154945: I tensorflow/core/common_runtime/gpu/gpu_device.cc:2021] Created device /device:GPU:0 with 1143 MB memory: -> device: 0, name: NVIDIA A800 80GB PCIe, pci bus id: 0000:35:00.0, compute capability: 8.0\n",
"2025-01-09 10:13:03.156613: I tensorflow/core/common_runtime/gpu/gpu_device.cc:2021] Created device /device:GPU:1 with 78412 MB memory: -> device: 1, name: NVIDIA A800 80GB PCIe, pci bus id: 0000:36:00.0, compute capability: 8.0\n",
"2025-01-09 10:13:03.158071: I tensorflow/core/common_runtime/gpu/gpu_device.cc:2021] Created device /device:GPU:2 with 78412 MB memory: -> device: 2, name: NVIDIA A800 80GB PCIe, pci bus id: 0000:39:00.0, compute capability: 8.0\n",
"2025-01-09 10:13:03.159472: I tensorflow/core/common_runtime/gpu/gpu_device.cc:2021] Created device /device:GPU:3 with 78412 MB memory: -> device: 3, name: NVIDIA A800 80GB PCIe, pci bus id: 0000:3d:00.0, compute capability: 8.0\n",
"2025-01-09 10:13:03.161049: I tensorflow/core/common_runtime/gpu/gpu_device.cc:2021] Created device /device:GPU:4 with 78412 MB memory: -> device: 4, name: NVIDIA A800 80GB PCIe, pci bus id: 0000:9c:00.0, compute capability: 8.0\n",
"2025-01-09 10:13:03.162507: I tensorflow/core/common_runtime/gpu/gpu_device.cc:2021] Created device /device:GPU:5 with 78412 MB memory: -> device: 5, name: NVIDIA A800 80GB PCIe, pci bus id: 0000:9d:00.0, compute capability: 8.0\n",
"2025-01-09 10:13:03.163784: I tensorflow/core/common_runtime/gpu/gpu_device.cc:2021] Created device /device:GPU:6 with 78412 MB memory: -> device: 6, name: NVIDIA A800 80GB PCIe, pci bus id: 0000:a0:00.0, compute capability: 8.0\n",
"2025-01-09 10:13:03.165104: I tensorflow/core/common_runtime/gpu/gpu_device.cc:2021] Created device /device:GPU:7 with 77296 MB memory: -> device: 7, name: NVIDIA A800 80GB PCIe, pci bus id: 0000:a4:00.0, compute capability: 8.0\n"
]
}
],
"source": [
"import tensorflow as tf\n",
"print(tf.test.is_gpu_available())\n",
"gpus = tf.config.experimental.list_physical_devices(device_type='GPU')\n",
"cpus = tf.config.experimental.list_physical_devices(device_type='CPU')\n",
"print(gpus, cpus)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}