Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

In order to run Python code with GPU (after installing all libraries for this), one can juste add these line before the code:

device_name= tf.test.gpu_device_name()
if device_name!='/device:GPU:0':
    raise SystemEror('GPU device not found')
else:
    print('GPU found!')

with tf.device("/device:GPU:0"):
    #python code here...

Is there any similar way to run existing C++ code on GPU ? I've searched and I found that one should install other libraries and re-write the C++ code. I would prefer something (if exists) in a similar way of Python.

Any ideas?

question from:https://stackoverflow.com/questions/66056261/run-c-code-easily-on-gpu-lik-python-language

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
176 views
Welcome To Ask or Share your Answers For Others

1 Answer

C++ doesn’t have any facilities built in for GPU programming, you’d need to use something like OpenCL (or CUDA if you have an Nvidia GPU) for compute, or OpenGL/Vulkan or another graphics library for graphics.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...