GPU上运行,并输出识别显卡信息和电脑配置信息

它可以在GPU上运行,并输出识别显卡信息和电脑配置信息这个代码将使用蒙特卡罗方法来计算π的值。该方法基于随机数生成器来生成点,然后计算这些点落在单位圆内还是外部的概率。该算法在每个线程中计算一次,最终将所有线程的结果加起来得到π的估计值。

请注意,这个算法只是一种近似方法,它不能保证得到精确的π的值。它只是一种计算π的方法,可以用来验证其他计算π的方法的正确性

import torch
import cupy as cp
import numpy as np

# 检查是否使用GPU
if torch.cuda.is_available():
    print("Using GPU")
else:
    print("Using CPU")

# 获取GPU信息
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
print("Device:", device)
print("CUDA Version:", torch.version.cuda)
print("CuPy Version:", cp.__version__)

# 获取显卡信息
print("\nGPU Info:")
if torch.cuda.is_available():
    print("Number of GPUs:", torch.cuda.device_count())
    for i in range(torch.cuda.device_count()):
        print("GPU {}:".format(i))
        print("  Name:", torch.cuda.get_device_name(i))
        print("  Total Memory:", torch.cuda.get_device_properties(i).total_memory / 1024 / 1024, "MB")
        print("  Free Memory:", torch.cuda.memory_allocated(i) / 1024 / 1024, "MB")
        print("  Used Memory:", torch.cuda.memory_reserved(i) / 1024 / 1024, "MB")
        print("  CUDA Version:", torch.version.cuda)
        print("  CuPy Version:", cp.__version__)
        print("  Python Version:", torch.version.pytorch)
        print("  CPU Info:")
        print("    Vendor:", torch.cuda.get_device_properties(i).name)
        print("    Cores:", torch.cuda.get_device_properties(i).multi_processor_count)
        print("    Clock Rate:", torch.cuda.get_device_properties(i).clock_rate / 1000, "MHz")
        print("    Memory Bus Width:", torch.cuda.get_device_properties(i).memory_bandwidth / 1024 / 1024 / 1024, "GB/s")
        print("    L2 Cache Size:", torch.cuda.get_device_properties(i).l2_cache_size / 1024 / 1024, "KB")
        print("    Shared Memory per Block:", torch.cuda.get_device_properties(i).max_threads_per_block / 1024, "KB")
        print("    Shared Memory per Multiprocessor:", torch.cuda.get_device_properties(i).shared_memory_per_block / 1024, "KB")
        print("    Max Threads per Multiprocessor:", torch.cuda.get_device_properties(i).max_threads_per_multi_processor)
        print("    Max Grid Size:", torch.cuda.get_device_properties(i).max_grid_dimension_x, "x", torch.cuda.get_device_properties(i).max_grid_dimension_y, "x", torch.cuda.get_device_properties(i).max_grid_dimension_z)
        print("    Max Block Size:", torch.cuda.get_device_properties(i).max_threads_per_block_x, "x", torch.cuda.get_device_properties(i).max_threads_per_block_y, "x", torch.cuda.get_device_properties(i).max_threads_per_block_z)
        print("    Max Memory Pitch:", torch.cuda.get_device_properties(i).max_memory_accessed_per_block / 1024 / 1024, "KB")
        print("    Compute Capability:", torch.cuda.get_device_properties(i).compute_capability)
        print("    Total Constant Memory:", torch.cuda.get_device_properties(i).total_global_mem / 1024 / 1024, "MB")
        print("    Max Texture Size:", torch.cuda.get_device_properties(i).max_texture1d_linear_width / 1024, "KB")
        print("    Max Texture Size Layered:", torch.cuda.get_device_properties(i).max_texture2d_linear_width / 1024, "KB")
        print("    Max Texture Size 3D:", torch.cuda.get_device_properties(i).max_texture3d_width / 1024, "KB")
        print("    Max Texture Pitch:", torch.cuda.get_device_properties(i).max_texture1d_linear_width / 1024, "KB")
        print("    Texture Alignment:", torch.cuda.get_device_properties(i).texture_alignment)
        print("    Concurrent Kernels:", torch.cuda.get_device_properties(i).concurrent_kernels)
        print("    Cooperative Launch:", torch.cuda.get_device_properties(i).cooperative_launch)
        print("    Cooperative Multi Device Launch:", torch.cuda.get_device_properties(i).cooperative_multi_device_launch)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yehaiwz

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值