Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CUDA Syntax overview. #25

Open
Robadob opened this issue May 19, 2021 · 1 comment
Open

CUDA Syntax overview. #25

Robadob opened this issue May 19, 2021 · 1 comment
Labels
documentation Improvements or additions to documentation

Comments

@Robadob
Copy link
Member

Robadob commented May 19, 2021

Simple page/section aimed at Python users explaining the CUDA C equivalent of common syntax vs python which they may need for defining agent functions.

E.g, defining variable, if-else, for, function define/call.

Could link to an external guide/s at the end for greater detail.

@Robadob Robadob added the documentation Improvements or additions to documentation label May 19, 2021
@Robadob
Copy link
Member Author

Robadob commented May 19, 2021

Agent Function/CUDA Syntax

FLAMGPU agent functions are written using CUDA, which itself is a form of C++ (albeit lacking support for most of the standard library). The syntax required to write agent functions is likely to be cover a small subset of available C++ feature, common to other C style languages such as Java and C# like control flow operations, rather than needing to learn about technical features such as manual memory management and pointers.

If you're using the Python API and are unfamiliar with these languages, the difference between common statements is outlined below:

Variables

Python

foo = 5
foo += 2
bar = foo

CUDA

int foo = 5;
foo += 2;
int bar = foo;

Unlike python, CUDA requires variables types to be specified. The types supported by FLAMEGPU are:

Signed Integer Unsigned Integer Floating Point
int / int32_t unsigned int / uint32_t float
long long / int64_t unsigned long long / int64_t double
signed char / int8_t unsigned char / int8_t
short / int16_t unsigned short / int16_t

if-else statements

Python

if foo == 1:
    bar = 5
elif foo == 2:
    bar = 6
else:
    foo = 1
    bar = 7

CUDA

int bar;
if (foo == 1) {
    bar = 5;
} else if (foo == 2) {
    bar = 6;
} else {
    foo = 1;
    bar = 7;
}

CUDA uses curly brackets instead of indentation for scoping blocks. (The brackets aren't strictly required if there's only a single statement (;) in the block.

for loops

Python

for i in range(10):
  # do something

CUDA

for (int i = 0; i < 10; ++i) {
  // do something
}

For loops have 3 parts, separated by semi colons; for(<variable definition>;<condition>;<post-iteration action>).

etc..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant