How to verify your CUDA and pytorch

1.Test CUDA

This script will attempt to create a tensor on the GPU and perform a simple computation.

python 复制代码
import torch

def test_cuda():
    # Check CUDA availability
    if torch.cuda.is_available():
        print("CUDA is available on this device.")
        # Set device to CUDA
        device = torch.device("cuda")
        # Create a tensor and move it to CUDA
        x = torch.rand(10, 10).to(device)
        print("Successfully created a tensor on CUDA:", x)
        # Perform a simple computation
        y = x * x
        print("Output of the computation:", y)
    else:
        print("CUDA is not available. Check your installation and driver.")

if __name__ == "__main__":
    test_cuda()

Run the script: Use a terminal or command prompt to run the script with Python.

bash 复制代码
python test_cuda.py

The script should print whether CUDA is available, show the tensor created on the GPU, and display the output of a simple multiplication operation. If there are any errors during these steps, they will help pinpoint what might be wrong with your CUDA setup.

2.Check PyTorch Compatibility

python 复制代码
# test_torch.py
import torch
print(torch.__version__)
print(torch.cuda.is_available())

Run the script: Use a terminal or command prompt to run the script with Python.

bash 复制代码
python test_torch.py

If torch.cuda.is_available() returns True, then PyTorch is able to use CUDA.

相关推荐
L、2185 小时前
CANN ops-transformer 仓库详解:Transformer 算子的底层实现与性能优化
深度学习·性能优化·transformer
嗝o゚5 小时前
昇腾CANN ge 仓的图优化 Pass:哪些 Pass 真正影响推理性能
pytorch·python·深度学习·cann·ge-pass
L、2186 小时前
昇腾NPU性能调优Checklist——从“能跑“到“跑得快“的20步
服务器·人工智能·深度学习
碧海银沙音频科技研究院6 小时前
恒玄bes2600WM+DSP蓝牙耳机项目
深度学习·语音识别
蓦然回首却已人去楼空6 小时前
深度学习进阶:自然语言处理|4.1.2 QA|grads 列表与省略号 [...] 详解
人工智能·深度学习·自然语言处理
手写码匠6 小时前
Android 17 适配实战指南:新特性解读、隐私变更与迁移全攻略
人工智能·深度学习·算法·aigc
端平入洛7 小时前
单个感知机为何无法解决异或问题?
人工智能·深度学习
Narv工程师7 小时前
嵌入式机器人控制器算力评估:从DMIPS到WCET的完整指南
人工智能·算法·机器学习
AI医影跨模态组学7 小时前
J Thorac Oncol(IF=20.8)广东省人民医院钟文昭教授团队:基于影像组学的支持向量机区分驱动肺腺癌进展的分子事件
人工智能·深度学习·机器学习·论文·医学·医学影像·影像组学