File size: 534 Bytes
2aa7125
 
1e4b350
 
2aa7125
1e4b350
 
2aa7125
1e4b350
 
 
2aa7125
1e4b350
 
 
2aa7125
1e4b350
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import paddle

# Define an array on the CPU
array_on_cpu = paddle.to_tensor([1, 2, 3, 4, 5])

# Check if GPU is available
use_gpu = paddle.is_compiled_with_cuda() and paddle.device.is_compiled_with_cuda()

if use_gpu:
    # Transfer the array to GPU
    array_on_gpu = array_on_cpu.cuda()

    # Print the array on GPU
    print("Array on GPU:")
    print(array_on_gpu)

    # Verify the device of the tensor
    print("Device of the tensor:", array_on_gpu.place)
else:
    print("CUDA is not available. Cannot load array onto GPU.")