Add GPU Functionality to the dev Branch - #440
Conversation
d88daf3 to
a8f181d
Compare
It appears the builtin implementation is not provided on AMD. This, or something like it, would need to be included until there is a real fix.
Multi-dimensional array returns still need to be added.
f8ea2c6 to
b746564
Compare
|
It should be noted that the After consultation with @ilhamv , this seemed like the best option to get gpu functionality merged in a timely manner. |
|
These latest changes remove dead code, and so should not affect regression/unit tests. |
|
Thanks, @braxtoncuneo! I'll work on the review ASAP. And thanks for highlighting some of the changes in separate conversations. |
|
Dedicated pages in |
|
We would need to keep track of overheads that appear only in pure Python mode, as it would be important in interpreting runtime results when we compare Python VS Numba-CPU modes. We can do this when we work on the docs in the follow-up PR. |
|
|
|
@braxtoncuneo |
|
@braxtoncuneo |
|
@braxtoncuneo I can see that there is potential for generalizing it to be a utility module. However, generalizing it would need to make the functions tangent-safe, like those currently used in the quadratic surfaces, not to mention the sacrificed performance from moving away from the specialized solvers. Nevertheless, due to the potential improved maintainability, we keep the generalization option open in the future! |
You're right. I'll get those switched back to the |
No. In fact, it looks like some of the changes between the CEMeNT
I have verified that it passes for gpu on tuolumne. 👍
The latest batch of commits revises these accesses back to the equivalent |
Summary of changes
This PR adds GPU execution to the dev branch. This was accomplished by re-implementing some functionality in a manner compatible with execution through
numba-hipandnumba-cuda. This includes changes to how gpu state objects are managed, the introduction of helper intrinsics/functions to handle returning arrays, and replacement of builtin functions that are not supported on one or more gpu plaltforms (e.g. powers for complex numbers, numpy polynomial solvers).Types of changes
New feature: Helper functions/intrinsics for returning arrays on GPU
As has been mentioned in previous issues/PRs,
numba-hipandnumba-cudado not permit returning arrays from functions. In brief, this is because memory management on GPU is hard, and the simplest way to create an array as a local variable is to allocate it on the stack. Once the array that created a local array returns, that array no longer "exists" in a way that it can be safely used.This is a problem, since the helper functions provided by
numba_objects_generator.pyreturn references to and slices of arrays in the mcdc global data structure. We'd like to keep those helper functions, considering how much convenience and quality of life they provide to developers. Also, since these global data structures have a lifetime which encompasses the lifetime of all transport logic (i.e. the structures are in memory and safe to use whenever any transport logic is run) it should be safe to ignore this array-returning restriction for these helper functions.For this specific use case, when we know for certain that an array is safe to use after a function returns, this PR introduces the
array_returndecorator and thearray_resultfunction, which enables the return of array references/slices like so:This works by smuggling a pointer to the array's data and the size of the array out as a tuple, then reconstructing the array based off of the returned tuple in the calling function.
In normal python execution, the
array_resultfunction simply returns its input. However, there exists an overload ofarray_resultwhich will handle the conversion to tuple in compiled contexts.The
array_returndecorator registers an intrinsic overload of the decorated function. This intrinsic calls the decorated function and creates a new array based on the returned tuple. Because intrinsics are inlined directly into their calling function, they aren't their own function with a separate stack frame and so are not rejected by the array-returning guards ofnumba-hipornumba-cuda.New feature: GPU-compatible quartic solver and complex power calculation
numpy.rootssolves polynomials and is implemented bynumbain compiled contexts!numba-hipandnumba-cudadon't implementnumpy.roots- likely because the general case does not have analytic solutions and requires the use of arbitrarily large matrixes (determined by the degree of the polynomial).numba-hipdoesn't implement the intrinsic for powers of complex numbers.New feature: GPU execution
New feature: Added logic to
test/regression/conftest.pyto support regression/units tests with GPUBug fix: updated references to reflect the new names and module locations of Harmonize API, as imported by MC/DC
Bug fix: updated logic switched by gpu-related settings to check values in
settingsbased upon the constants inmcdc.constantBug fix: removed redundant call to
clear_flagsincode_factory/gpu/transport/simulation.pyBug fix: ensured that the original value of atomically-modified fields is taken from the return of the atomic operation, rather than from a separate read. This is important, because only the return value of the atomic operation itself can be trusted with providing the original value immediately before the operation.
Bug fix: updated
add_bank_sizeand its uses so that they follow the interface of atomic operations, returning the trusted value. Using a separateget_bank_sizeafter the fact has the same problem as a separate read, and so the original value must be provided by the logic ofadd_bank_sizeitself.Bug fix: modified the reading of particles from banks so that they use the trusted values returned by
add_bank_size, which requires the movement to occur after the addition itself has occurred.Bug fix: added early return to progress-printing code in
mcdc/transport/simulation.pyto avoid divide-by-zero whenmpi_work_size==0Bug fix: updated the cpu-side
atomic_addto match the correct atomic operation interfaceRefactor: Added gpu platform detection to
config.py, providing global flags to indicate whether CUDA/ROCM is availableBug fix: Moved the call to
setup_gpu_programinmainso that it occurs after types have been defined. Without this ordering, the function would attempt to compile functions without proper type information.Bug fix: Updated
test/unit/test_numba_layers_generator.pyto reflect the new array-returning functionality provided formcdc_get/mcdc_set.Developer Checklist
Associated Issues and PRs
Associated Developers