You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
First of all, thank you for the nice MMGNLSE code.
I am new to CUDA and therefore, find it difficult to understand the calculation of the overlap integrals in the CUDA file.
I would appreciate if anyone can help me to explain the below lines from the Calculate Tensors_single.cu file:
if (full_thread_idx >= nmp4) {
return;
}
// Turn linear index into components
unsigned int midx1 = full_thread_idx % num_modes;
unsigned int midx2 = (full_thread_idx/num_modes) % num_modes;
unsigned int midx3 = (full_thread_idx/num_modes/num_modes) % num_modes;
unsigned int midx4 = (full_thread_idx/num_modes/num_modes/num_modes);
// Compute the sum
for (int i = 0; i < Nx; i++) {
for (int j = 0; j < Nx; j++) {
SR[full_thread_idx] += fields[midx1+i*num_modes+j*Nxnm]*fields[midx2+i*num_modes+j*Nxnm]*fields[midx3+i*num_modes+j*Nxnm]*fields[midx4+i*num_modes+j*Nxnm];
}
}
// Normalize
SR[full_thread_idx] /= norms[midx1]*norms[midx2]*norms[midx3]*norms[midx4];
Thanks in advance!
The text was updated successfully, but these errors were encountered:
The key things to understand here are the use of kernel functions and vectorized element indexing in CUDA, so that as much happens in parallel as possible (of course the calculation of the overlap integrals is very parallelizable). You probably noticed that the SR tensor is already flattened, but the funny indexing on the fields comes from the vectorized format. https://devblogs.nvidia.com/even-easier-introduction-cuda/
Note that there should also be the option to calculate the tensors by brute force in Matlab if you prefer (see the Matlab script for calculating the tensors). If in doubt (or you want to check), this can also be used. If I were to write this today, I'd probably just use parfor in Matlab on that.
Hello,
First of all, thank you for the nice MMGNLSE code.
I am new to CUDA and therefore, find it difficult to understand the calculation of the overlap integrals in the CUDA file.
I would appreciate if anyone can help me to explain the below lines from the Calculate Tensors_single.cu file:
if (full_thread_idx >= nmp4) {
return;
}
Thanks in advance!
The text was updated successfully, but these errors were encountered: