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

Allocation of arrays for hamiltonian #21

Open
ksunden opened this issue Dec 31, 2017 · 1 comment
Open

Allocation of arrays for hamiltonian #21

ksunden opened this issue Dec 31, 2017 · 1 comment

Comments

@ksunden
Copy link
Member

ksunden commented Dec 31, 2017

// Allocate arrays and pointers for the Hamiltonians for the current and next step.
//pycuda::complex<double> *H_cur = (pycuda::complex<double>*)malloc(ham.nStates * ham.nStates * sizeof(pycuda::complex<double>));
//pycuda::complex<double> *H_next = (pycuda::complex<double>*)malloc(ham.nStates * ham.nStates * sizeof(pycuda::complex<double>));
//TODO: either figure out why dynamically allocated arrays weren't working, or use a #define to statically allocate
pycuda::complex<double> buf1[81];
pycuda::complex<double> buf2[81];
pycuda::complex<double>* H_cur = buf1;
pycuda::complex<double>* H_next = buf2;

I originally tried using dynamically allocated arrays (commented out lines), but ran into some trouble getting the code to work which was solved by using statically allocated buffers and simple pointers to those buffers.
This solved the problem getting the code to work, but assumes a specific matrix size.

Either, we need to solve the dynamically allocated arrays, or we can use some slight metaprogramming to solve this problem. SInce we compile just before using, we know the size of this array at compile time (in fact, we know the size of all of our arrays at compile time. This allows us to use the stack rather than the heap for some of our arrays. Stack allocated memory can be easier to use, as it is allocated and freed implicitly.

Ways we could go about this: python format strings using format to replace certain fields with the numbers we want. This could actually help (probably not noticeably) the transfer costs, as many of the things we need could be transferred in the instructions themselves rather than as parameters.

Otherwise we could use a C preprocessor macro to #define VEC_SIZE 9 and then use VEC_SIZE * VEC_SIZE where the square is needed. This is, in my opinion slightly more elegant, though may take the compiler (a probably trival amount of ) time. This way, a single line can be added to the source code handed to the compiler, and not have to worry about the rest

@kameyer226
Copy link
Contributor

Have you tried single precision complex arrays? Also, did you build your own numpy library from source? Things may have changed greatly since this was last commented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants