paddle_GPU_test / GPU_test.py
jkushwaha's picture
Update GPU_test.py
1e4b350 verified
raw
history blame contribute delete
534 Bytes
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.")