Nobisuke
Dekisugi
RAG
Privacy policy
2024/08/11 03:42
你好,
在工作的时候,我仿佛听到一个声音在说,
“用AMD的GPU吧!”
于是,我决定试一试。
Shoya Yasuda 正在管理一个名为TYTAN的求解器。
由于最近pyqubo没有得到维护,我们决定与志愿者一起创建一个QUBO求解器并进行维护。此外,QUBO求解器的价格通常相当高昂,因此我们将其开源并支持GPU,以便能够进行大规模计算。
这次,我将之前兼容NVIDIA GPU的求解器适配为兼容AMD GPU。我们使用ROCm代替CUDA。
在这次实验中,我使用了一台Ryzen 9 5950X CPU和一块消费级的RX 7900 XTX GPU。
# 检查ROCm是否可用
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
# 创建一个10000x10000的上三角矩阵
matrix = torch.triu(torch.rand((10000, 10000), dtype=torch.float32)).to(device)
# 创建一个长度为10000的二进制向量
binary_vector = torch.randint(0, 2, (10000,), dtype=torch.float32).to(device)
...
# 显示结果
print(result)
tensor(6344590.5000, device='cuda:0')
速度非常快。
print(qubo)
print(x)
tensor([[0.6717, 0.2371, 0.3101, ..., 0.5782, 0.7420, 0.1201],
[0.0000, 0.1776, 0.7430, ..., 0.5994, 0.1445, 0.1131],
[0.0000, 0.0000, 0.4777, ..., 0.9339, 0.5034, 0.7254],
...,
[0.0000, 0.0000, 0.0000, ..., 0.1156, 0.8715, 0.9204],
[0.0000, 0.0000, 0.0000, ..., 0.0000, 0.5723, 0.5254],
[0.0000, 0.0000, 0.0000, ..., 0.0000, 0.0000, 0.6098]],
device='cuda:0')
tensor([0., 0., 0., ..., 0., 0., 1.], device='cuda:0')
看起来它运行成功了。
print(len(qubo))
print(len(x))
10000
10000
我们成功解决了一个包含10,000个量子比特的问题。
同样地,我尝试解决一个HOBO问题,虽然由于其复杂性需要更多时间,但它也成功运行了:
tensor([[[3.4074e-01, 2.3801e-01, 7.2555e-01, ..., 5.7089e-01,
9.3300e-01, 9.4946e-01],
[4.5312e-01, 6.0727e-02, 6.4917e-01, ..., 9.2022e-01,
4.8904e-01, 7.7863e-01],
[4.8968e-01, 1.3415e-01, 1.3029e-01, ..., 1.3355e-01,
3.1534e-01, 1.4187e-01],
...,
[8.1578e-01, 4.4324e-01, 6.7385e-01, ..., 4.7309e-01,
8.9954e-01, 1.3278e-01],
[3.1411e-01, 6.2912e-01, 3.0486e-01, ..., 7.0183e-01,
2.1883e-01, 4.6304e-01],
[2.8279e-01, 2.7991e-01, 3.7780e-01, ..., 8.6366e-01,
1.0008e-01, 4.9714e-01]],
[[3.6964e-02, 4.8730e-01, 3.2427e-01, ..., 7.9467e-01,
7.8272e-01, 7.5983e-01],
[7.0970e-01, 2.3678e-01, 2.4753e-02, ..., 7.0028e-01,
2.4440e-01, 1.1518e-02],
[6.3244e-01, 8.4304e-01, 9.5919e-01, ..., 6.2282e-01,
4.0956e-01, 4.5244e-01],
...,
[4.4514e-01, 4.7023e-01, 5.3170e-02, ..., 5.9058e-02,
6.1356e-01, 9.7442e-01],
[1.7204e-02, 6.4554e-01, 4.0960e-01, ..., 4.3088e-01,
6.7305e-01, 7.0740e-01],
[5.8251e-01, 4.6846e-01, 7.5960e-01, ..., 7.6140e-01,
8.1435e-01, 1.9587e-01]],
[[1.1972e-01, 1.0914e-01, 4.9694e-01, ..., 9.5165e-01,
4.4203e-01, 3.6698e-01],
[3.1464e-01, 6.1380e-01, 1.2407e-01, ..., 3.7007e-01,
7.6723e-02, 3.5921e-01],
[1.1962e-01, 5.5726e-01, 1.7458e-01, ..., 4.3072e-01,
7.2724e-01, 3.4609e-01],
...,
[7.7374e-01, 7.4722e-02, 3.7408e-01, ..., 2.1651e-01,
4.6314e-01, 7.4453e-02],
[7.3573e-01, 6.9235e-01, 4.4228e-01, ..., 5.4889e-01,
6.1121e-01, 9.5530e-01],
[3.2142e-01, 5.7895e-02, 3.3993e-01, ..., 4.1517e-02,
8.8431e-01, 9.4296e-01]],
...,
[[4.0457e-01, 2.8757e-01, 5.4801e-01, ..., 1.0961e-01,
7.2955e-01, 1.9745e-01],
[8.9825e-01, 1.0816e-01, 6.0176e-01, ..., 3.0971e-01,
7.8467e-01, 4.8715e-01],
[9.9333e-01, 1.5634e-01, 9.9381e-01, ..., 8.3018e-01,
6.3215e-01, 1.2996e-01],
...,
[6.1138e-01, 7.5022e-01, 5.3412e-01, ..., 7.2379e-01,
1.9942e-01, 7.2978e-02],
[6.0287e-01, 7.0418e-01, 2.6854e-01, ..., 7.5977e-02,
1.3940e-01, 2.4227e-01],
[3.3239e-01, 4.3019e-01, 6.400
8e-01, ..., 5.2265e-01,
1.2314e-01, 9.3854e-01]],
[[9.4510e-01, 5.6508e-01, 3.4954e-01, ..., 8.2149e-01,
9.1106e-01, 2.4986e-04],
[9.9170e-01, 2.9942e-01, 5.7906e-01, ..., 4.9604e-01,
2.4864e-01, 2.2348e-01],
[3.3026e-01, 4.4755e-01, 2.5998e-01, ..., 4.6217e-01,
5.0340e-01, 4.0357e-01],
...,
[1.9716e-01, 2.9640e-02, 5.8540e-01, ..., 4.8116e-01,
2.9869e-01, 6.4445e-01],
[3.0518e-01, 2.6747e-01, 6.4220e-02, ..., 9.0268e-01,
7.4376e-02, 8.2438e-01],
[1.4391e-01, 2.9811e-01, 8.7411e-01, ..., 9.6410e-01,
5.4904e-01, 3.1477e-01]],
[[4.7378e-01, 5.8130e-01, 5.5962e-01, ..., 7.8212e-02,
2.1484e-01, 1.6522e-01],
[9.0710e-01, 2.7738e-01, 9.7132e-01, ..., 3.2095e-01,
2.7935e-01, 3.4490e-01],
[6.5868e-02, 3.0124e-01, 3.8631e-01, ..., 8.2379e-01,
8.5930e-01, 9.4988e-01],
...,
[9.0615e-01, 6.0957e-02, 8.0838e-02, ..., 1.1742e-01,
9.3179e-02, 3.6622e-01],
[7.0447e-01, 1.2479e-01, 6.1637e-01, ..., 8.9149e-01,
2.5499e-01, 4.4584e-01],
[7.3772e-01, 3.1814e-01, 6.3537e-01, ..., 1.2058e-01,
1.6863e-01, 1.1854e-01]]], device='cuda:0')
使用AMD没有遇到任何问题。以上就是全部内容。
© 2024, blueqat Inc. All rights reserved