Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • wslda wslda
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 0
    • Issues 0
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Package Registry
    • Container Registry
    • Infrastructure Registry
  • Analytics
    • Analytics
    • CI/CD
    • Repository
    • Value stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • wtools
  • wsldawslda
  • Wiki
  • C and CUDA

C and CUDA · Changes

Page history
Update C and CUDA authored Dec 15, 2020 by Gabriel Wlazłowski's avatar Gabriel Wlazłowski
Hide whitespace changes
Inline Side-by-side
C-and-CUDA.md
View page @ 8214566a
TODO
\ No newline at end of file
Programming language:
* static codes `st-wslda`: [C99](https://en.wikipedia.org/wiki/C99) standard
* time dependent codes `td-wslda`: mixture of [C99](https://en.wikipedia.org/wiki/C99) and [CUDA](https://en.wikipedia.org/wiki/CUDA).
In general CUDA is compatible with C99. Thus, in practice when editing files (*predefines.h*, *problem-definition.h* or *logger.h*) you can use C language irrespectively to code variants (`st` or `td`). There is only one exception related to function `delta_ext` in *problem-definition.h* file. It declaration is
* static codes `st-wslda`:
```c
double complex delta_ext(int ix, int iy, int iz, int it, double complex delta, double *params, size_t extra_data_size, void *extra_data)
```
* time dependent codes `td-wslda`:
```cuda
__device__ Complex delta_ext(int ix, int iy, int iz, int it, Complex delta, double *params, size_t extra_data_size, void *extra_data)
```
The change arises from incompatibility of complex type in C99 and CUDA. Namely:
* `st-wslda`: return type must be C99 [double complex](https://en.cppreference.com/w/c/numeric/complex)
* `td-wslda`: return type must be compatible with [CUDA Complex](https://thrust.github.io/doc/group__complex__numbers.html)
Below we provide example of the same code written in both standards:
* C99
```c
double complex delta_ext(int ix, int iy, int iz, int it, double complex delta, double *params, size_t extra_data_size, void *extra_data)
{
double complex D = 1.0 + I*2.0; // assign value
double complex Dc = conj(D); // complex conjugate
double absolute_value = cabs(D);
double phase = carg(D);
double real_part = creal(D);
double imginary_part = cimag(D);
double complex exponentiation = cexp(D);
double complex power = cpow(D, 2);
// ...
return D;
}
```
* CUDA
```cuda
__device__ Complex delta_ext(int ix, int iy, int iz, int it, Complex delta, double *params, size_t extra_data_size, void *extra_data)
{
Complex D = Complex(1.0,2.0); // assign value
Complex Dc = thrust::conj(D); // complex conjugate
double absolute_value = thrust::abs(D);
double phase = thrust::arg(D);
double real_part = D.real();
double imginary_part = D.imag();
Complex exponentiation = thrust::exp(D);
Complex power = thrust::pow(D, 2);
// ...
return D;
}
```
Clone repository
  • API version
  • Automatic interpolations
  • Auxiliary tools
  • Browsing the code
  • Broyden algorithm
  • C and CUDA
  • Campaign of calculations
  • Checking correctness of settings
  • Chemical potentials control
  • Code & Results quality
  • Common failures of static codes
  • Common failures of time dependent codes
  • Computation domain
  • Configuring GPU machine
  • Constraining densities and potentials
View All Pages