# How to add two integers using the power of the GPU and not the CPU



## Alain De Vos (Oct 9, 2021)

I want to write a program which adds two integers but uses for this the GPU and not the CPU to perform the actual computation (any language is ok)
[ PS: I don't want to do artificial intelligence on the GPU, nor fuzzy logic, nor image recognition, nor quantum computing, just simple add two integers]


----------



## dd_ff_bb (Oct 9, 2021)

This for your question:








						Addition of two numbers in CUDA: A Simple Approach
					

How To Add two numbers in CUDA? How to perform parallel addition in CUDA?




					www.cstechera.com
				




This for details:


			https://www3.nd.edu/~zxu2/acms60212-40212-S16/Lec-11-GPU.pdf
		


This as starting point for your next question:








						How to compile CUDA applications?
					

I'm trying to get CUDA to work on: FreeBSD silvers 9.1-RELEASE-p4 FreeBSD 9.1-RELEASE-p4 #0: Sun Jun 30 01:07:52 MSK 2013     root@silvers:/usr/obj/usr/src/sys/GENERIC  amd64 I installed toolkit 2.3 (32 bit) for Fedora 10 but when I run nvcc cuda.cpp I get: /usr/local/cuda/bin/nvcc cuda.cpp...




					forums.freebsd.org


----------



## wally (Oct 9, 2021)

Two questions please.
May I ask why?


----------



## Alain De Vos (Oct 9, 2021)

Will python work ?





						Numba for AMD ROC GPUs — Numba 0.50.1 documentation
					






					numba.pydata.org


----------



## Jose (Oct 9, 2021)

dd_ff_bb said:


> This for your question:
> 
> 
> 
> ...


No CUDA on Freebsd yet. At least on Nvidia cards:








						CUDA and /(nv_(un|)register|os_(un|)lock)_user_pages/
					

Please, consider implementing nv_register_user_pages/nv_unregister_user_pages/os_lock_user_pages/os_unlock_user_pages in the FreeBSD driver. Those functions are apparently being called on CUDA initialization and that’s the bit that prevents CUDA from working on FreeBSD. Well, at least as far as...




					forums.developer.nvidia.com
				




Edit: CUDA only works on Nvidia cards, so no, not possible.


----------



## Alain De Vos (Oct 9, 2021)

Bummer , even py-numba requires an "old" llvm-10 compiler.


----------



## sidetone (Oct 9, 2021)

OpenGL maybe.

AMD opensourced GPUFort as an alternative to CUDA.

I was reading about Julia. It's possible that https://juliagpu.org/ could be used in the future.


----------



## shkhln (Oct 9, 2021)

Vulkan's compute shaders should work everywhere. There are, however, no libs and no debugging tools.


----------



## eternal_noob (Oct 9, 2021)

How to Use and Teach OpenGL Compute Shaders

Basically you write an OpenGL program and use a GLSL (OpenGL Shading Language) compute shader to do the calculation. I can't elaborate on this since i never tried them because my graphics card is too old and doesn't support such shaders.

You need to know how you create your OpenGL context.
As a context creation framework i recommend GLFW. It comes with a nice license and it's lightweight, simple and well documented. Of course there are many others.

Note that you need to use an OpenGL extension loading library such as GLAD (recommended) or GLEW to work with shaders. A plain (fixed function pipeline) OpenGL program won't do it.


----------

