Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
9812176
Save progress. This builds up the initalization needed to interpolate…
cianciosa Jun 1, 2026
29baca7
Add routine and unit test for PIC field interpolation.
cianciosa Jun 2, 2026
48f84f9
Minor formatting changes.
cianciosa Jun 3, 2026
ec3b744
Add framework enhancements necessary to impliment particle reinjectio…
cianciosa Jun 16, 2026
03416e1
Refactor simplify field solve. Among the changes include.
cianciosa Jun 25, 2026
4abd228
Fix CUDA build errors.
cianciosa Jun 25, 2026
2eade32
Update test tolarance for cuda builds
cianciosa Jun 25, 2026
aef0b36
Adjust float test tolarance on CPU.
cianciosa Jun 25, 2026
774071c
jit::use_cuda is a function.
cianciosa Jun 25, 2026
5449ea7
Add the ability to interpolate the filtered electric field. Start bui…
cianciosa Jul 2, 2026
f6a4e2b
Assemble pic code. Currently does not store any results but has all t…
cianciosa Jul 6, 2026
ca13c37
Enable batch loop unrolling for the field solve and test optimal unro…
cianciosa Jul 6, 2026
2123c99
Use the correct cuda call for device to device copy.
cianciosa Jul 6, 2026
8afaa28
Add test coverage for preitems and copy items.
cianciosa Jul 6, 2026
977d342
Refactor workflow manager to define pre run and post items. Add an ab…
cianciosa Jul 14, 2026
85afa52
Inital working pic code. Fix bug where or was accidently using add no…
cianciosa Jul 15, 2026
d6d8e88
Fix error where the recursive pick filtering indexing was running the…
cianciosa Jul 17, 2026
e0e627e
Fix compile error and allow copy and zero buffers to have different s…
cianciosa Jul 17, 2026
86a7df4
Fix compile error on cuda backends.
cianciosa Jul 17, 2026
fddd1c4
Delete duplicate variable delcaration.
cianciosa Jul 17, 2026
60b96ea
Check the correct variable for Kernel Profiling.
cianciosa Jul 20, 2026
edda8af
Fix function signatures in cuda backends so host functions run correc…
cianciosa Jul 20, 2026
6a7d13e
Remove indices cache since indices are now stored in registers. Clean…
cianciosa Jul 29, 2026
a727c2c
Enable threadgroup memory usage in metal kernels. This reduces the pa…
cianciosa Jul 29, 2026
f953bc1
Enable shared memory caching in the Cuda backend.
cianciosa Jul 30, 2026
eb4ed9c
Use the correct index for the start of the loop.
cianciosa Jul 30, 2026
c29698e
Fix more index errors.
cianciosa Jul 30, 2026
90deb87
Add shared memory registers to the compile method calls for the output.
cianciosa Jul 30, 2026
9417c33
Fix typo
cianciosa Jul 30, 2026
0a74da5
Shared memory is currently assuming a given thread size. So over ride…
cianciosa Jul 30, 2026
95503a6
Decouple shared memory from thread size.
cianciosa Jul 31, 2026
72ab0b3
Decouple threadgroup memory from thread width.
cianciosa Jul 31, 2026
f927fc6
Fix issues when input cache was disabled.
cianciosa Jul 31, 2026
16c65d7
Rewrite the sum kernel to use atomic accumulation. The kernel is 10x …
cianciosa Aug 4, 2026
a17d2ad
Enable atomics for the cuda backend.
cianciosa Aug 5, 2026
884f447
Argument nodes allow us to compute cell indicies and position without…
cianciosa Aug 5, 2026
925c3ee
Update C and Fortran bindings for new API changes.
cianciosa Aug 10, 2026
bfeb5a2
Fix some issues where the random state array could be larger than the…
cianciosa Aug 11, 2026
fc10826
Fix JIT compile issues on Linux systems. Needed to include the atomic…
cianciosa Aug 12, 2026
fa37129
Fix issue with Metal random kernels where the offset was being iterat…
cianciosa Aug 26, 2026
e30ee20
Create a custom node for the apply_u collision operator.
cianciosa Aug 31, 2026
37c8c3c
The input for x would be computed as const floating_point type so we …
cianciosa Aug 31, 2026
2b8abaa
Add apply_xi custom node.
cianciosa Aug 31, 2026
2dac57f
Add nodes needed to impliement coordinate conversions and fix reducti…
cianciosa Sep 3, 2026
97d4678
Add collision operators to pic code. To accomplish this, needed to ad…
cianciosa Sep 16, 2026
b6707b4
Refactor random numbers to avoid casting to a floating point type fir…
cianciosa Sep 17, 2026
eafe501
Convert device name and architexture to strings and Displaced maximum…
cianciosa Sep 17, 2026
0927a42
The max working set indicates that we can use more random number states.
cianciosa Sep 18, 2026
c14d957
Relax test tolarance for complex atan float.
cianciosa Sep 18, 2026
72dcf23
Fix cuda issues so unit tests pass.
cianciosa Sep 22, 2026
1c2192a
Fix random output during safe_math on the cuda and cpu backends.
cianciosa Sep 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ project (graph_framework CXX)
#-------------------------------------------------------------------------------
option (USE_PCH "Enable the use of precompiled headers" ON)
option (SAVE_KERNEL_SOURCE "Writes the kernel source code to a file." OFF)
option (USE_INPUT_CACHE "Cache the values kernel input values." OFF)
option (USE_CONSTANT_CACHE "Cache the value of constants in kernel registers." OFF)
option (USE_INPUT_CACHE "Cache the values kernel input values." ON)
option (USE_CONSTANT_CACHE "Cache the value of constants in kernel registers." ON)
option (SHOW_USE_COUNT "Add a comment showing the use count in kernel sources." OFF)
option (USE_INDEX_CACHE "Cache index values instead of computing them every time." OFF)
option (USE_INDEX_CACHE "Cache index values instead of computing them every time." ON)
option (USE_VERBOSE "Verbose jit option." OFF)
option (PROFILE_KERNELS "Display kernel timing information" OFF)
option (BUILD_C_BINDING "Build C interface." OFF)
option (BUILD_Fortran_BINDING "Build Fortran interface." OFF)

Expand Down Expand Up @@ -207,6 +208,7 @@ FetchContent_GetProperties (
)

# Do not build llvm until pull command is finished.
add_dependencies (CASPluginTest_exports pull_llvm)
add_dependencies (gpu-resource-headers pull_llvm)
add_dependencies (llvm-offload-resource-headers pull_llvm)
add_dependencies (LLVMDemangle pull_llvm)
Expand Down Expand Up @@ -374,8 +376,12 @@ macro (add_tool_target target lang)
graph_framework
)

if (${USE_PCH} AND ${BUILD_C_BINDING})
target_precompile_headers (${target} REUSE_FROM graph_c)
if (${USE_PCH})
if (${BUILD_C_BINDING})
target_precompile_headers (${target} REUSE_FROM graph_c)
elseif (NOT ${target} MATCHES xrays)
target_precompile_headers (${target} REUSE_FROM xrays)
endif ()
endif ()
endmacro ()

Expand Down Expand Up @@ -404,4 +410,18 @@ macro (add_test_target target lang)
endif ()
endmacro ()

macro (add_compile_test target lang)
cmake_path (GET CMAKE_CXX_COMPILER FILENAME compiler_command)
add_test (NAME ${target}_off
COMMAND ${compiler_command} -std=c++23 -DUSE_VERBOSE=false -DCHECK_TEST -c ${CMAKE_CURRENT_SOURCE_DIR}/${target}.${lang}
)
add_test (NAME ${target}_on
COMMAND ${compiler_command} -std=c++23 -DUSE_VERBOSE=false -c ${CMAKE_CURRENT_SOURCE_DIR}/${target}.${lang}
)
set_tests_properties (${target}_on
PROPERTIES
WILL_FAIL true
)
endmacro ()

add_subdirectory (graph_tests)
5,576 changes: 5,007 additions & 569 deletions graph_c_binding/graph_c_binding.cpp

Large diffs are not rendered by default.

404 changes: 404 additions & 0 deletions graph_c_binding/graph_c_binding.h

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions graph_docs/code_performance.dox
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*
* The figure above shows the advantage even a single GPU has over CPU
* execution. In single precision, the M2's GPU is almost @f$100\times@f$ faster
* a single CPU core while the a single A100 has a nearly $800\times$ advantage.
* a single CPU core while the a single A100 has a nearly @f$800\times@f$ advantage.
* An interesting thing to note is the M2 Max CPU show no advantage between
* single and double precision execution.
*
Expand Down Expand Up @@ -112,7 +112,7 @@ for (size_t i = 0, ie = threads.size(); i < ie; i++) {
{v_next->get_x(), graph::variable_cast(vx)},
{v_next->get_y(), graph::variable_cast(vy)},
{v_next->get_z(), graph::variable_cast(vz)}
}, NULL, "Lorentz_kernel", local_size);
}, {}, NULL, "Lorentz_kernel", local_size);
work.compile();

time_steps.start_time(thread_number);
Expand Down
6 changes: 3 additions & 3 deletions graph_docs/discription.dox
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
* expression nodes. The factory method checks a node_cache to avoid building
* duplicate sub-graphs. Identification of duplicate graphs is performed by
* computing a hash of the sub-graph. This hash can be rapidly checked if the
* same hash already exists in a <tt>std::map</tt> container. If the sub-graph
* already exists, the existing graph is returned otherwise a new sub-graph is
* registered in the node_cache.
* same hash already exists in a <tt>std::unordered_map</tt> container. If the
* sub-graph already exists, the existing graph is returned otherwise a new
* sub-graph is registered in the node_cache.
*
* Each time an expression is built, the reduce method is called to simplify the
* graph. For instance, a graph consisting of constant added to a constant will
Expand Down
4 changes: 2 additions & 2 deletions graph_docs/kernel_optimization.dox
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void field_solve_example() {
+ graph::exp(static_cast<T> (-1)*arg*arg/static_cast<T> (10));
}

auto state = graph::random_state<T> (jit::context<T>::random_state_size, 0);
auto state = graph::random_state<T> (jit::context<T>::max_random_state_size(num_particles), 0);
auto random = graph::random<T> (graph::random_state_cast(state));
const T max = 1.0;
const T min = -1.0;
Expand All @@ -68,7 +68,7 @@ void field_solve_example() {
timing::measure_diagnostic compile("compile");

workflow::manager<T> work(0);
work.add_preitem({
work.add_item<workflow::order::pre_item> ({
graph::variable_cast(particle_positions)
}, {}, {
{random_real, variable_cast(particle_positions)}
Expand Down
2 changes: 1 addition & 1 deletion graph_docs/use_cases.dox
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
* branch is absorbed in the upper hybrid resonance, @f$\omega_{h}@f$, while the
* O-Mode branch can pass through it.
*
* @subsubsection use_cases_rf_correctness Comparison to GENRAY
* @subsubsection use_cases_rf_correctness_genray Comparison to GENRAY
* <a href="https://compxco.com/genray.html">Genray</a> is an RF-Ray tracing
* code written in Fortran which operates in a cylindrical geometry. Toroidal
* equilibria can be imported using the
Expand Down
2 changes: 1 addition & 1 deletion graph_driver/xrays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ void bin_power(const commandline::parser &cl,
{z, graph::variable_cast(z_last)},
{p_next, graph::variable_cast(power)},
{k_next, graph::variable_cast(k_sum)}
}, graph::shared_random_state<T, SAFE_MATH> (), "power", local_num_rays);
}, {}, NULL, "power", local_num_rays);
work.compile();

output::result_file file(stream.str());
Expand Down
46 changes: 40 additions & 6 deletions graph_fortran_binding/graph_fortran_binding.f90
Original file line number Diff line number Diff line change
Expand Up @@ -568,14 +568,16 @@ TYPE(C_PTR) FUNCTION graph_atan(c, left, right) &
!> @brief Construct a random state node.
!>
!> @param[in] c The graph C context.
!> @param[in] size Number of randoms needed.
!> @param[in] seed Initial random seed.
!> @returns A random state node.
!-------------------------------------------------------------------------------
TYPE(C_PTR) FUNCTION graph_random_state(c, seed) &
TYPE(C_PTR) FUNCTION graph_random_state(c, size, seed) &
BIND(C, NAME='graph_random_state')
USE, INTRINSIC :: ISO_C_BINDING
IMPLICIT NONE
TYPE(C_PTR), VALUE :: c
INTEGER(C_LONG), value :: size
INTEGER(C_INT32_T), VALUE :: seed
END FUNCTION

Expand Down Expand Up @@ -742,13 +744,16 @@ SUBROUTINE graph_set_device_number(c, num) &
!> @param[in] map_inputs Array of map input nodes.
!> @param[in] map_outputs Array of map output nodes.
!> @param[in] num_maps Number of maps.
!> @param[in] atomics Array of atomics nodes.
!> @param[in] num_atomics Number of atomics.
!> @param[in] random_state Optional random state, can be NULL if not used.
!> @param[in] name Name for the kernel.
!> @param[in] num_particles Number of elements to operate on.
!-------------------------------------------------------------------------------
SUBROUTINE graph_add_pre_item(c, inputs, num_inputs, &
outputs, num_outputs, &
map_inputs, map_outputs, num_maps, &
atomics, num_atomics, &
random_state, name, num_particles) &
BIND(C, NAME='graph_add_pre_item')
USE, INTRINSIC :: ISO_C_BINDING
Expand All @@ -761,6 +766,8 @@ SUBROUTINE graph_add_pre_item(c, inputs, num_inputs, &
INTEGER(C_INTPTR_T), VALUE :: map_inputs
INTEGER(C_INTPTR_T), VALUE :: map_outputs
INTEGER(C_LONG), VALUE :: num_maps
INTEGER(C_INTPTR_T), VALUE :: atomics
INTEGER(C_LONG), VALUE :: num_atomics
TYPE(C_PTR), VALUE :: random_state
CHARACTER(kind=C_CHAR), DIMENSION(*) :: name
INTEGER(C_LONG), VALUE :: num_particles
Expand All @@ -777,13 +784,16 @@ SUBROUTINE graph_add_pre_item(c, inputs, num_inputs, &
!> @param[in] map_inputs Array of map input nodes.
!> @param[in] map_outputs Array of map output nodes.
!> @param[in] num_maps Number of maps.
!> @param[in] atomics Array of atomics nodes.
!> @param[in] num_atomics Number of atomics.
!> @param[in] random_state Optional random state, can be NULL if not used.
!> @param[in] name Name for the kernel.
!> @param[in] num_particles Number of elements to operate on.
!-------------------------------------------------------------------------------
SUBROUTINE graph_add_item(c, inputs, num_inputs, &
outputs, num_outputs, &
map_inputs, map_outputs, num_maps, &
atomics, num_atomics, &
random_state, name, num_particles) &
BIND(C, NAME='graph_add_item')
USE, INTRINSIC :: ISO_C_BINDING
Expand All @@ -796,6 +806,8 @@ SUBROUTINE graph_add_item(c, inputs, num_inputs, &
INTEGER(C_INTPTR_T), VALUE :: map_inputs
INTEGER(C_INTPTR_T), VALUE :: map_outputs
INTEGER(C_LONG), VALUE :: num_maps
INTEGER(C_INTPTR_T), VALUE :: atomics
INTEGER(C_LONG), VALUE :: num_atomics
TYPE(C_PTR), VALUE :: random_state
CHARACTER(kind=C_CHAR), DIMENSION(*) :: name
INTEGER(C_LONG), VALUE :: num_particles
Expand All @@ -812,6 +824,8 @@ SUBROUTINE graph_add_item(c, inputs, num_inputs, &
!> @param[in] map_inputs Array of map input nodes.
!> @param[in] map_outputs Array of map output nodes.
!> @param[in] num_maps Number of maps.
!> @param[in] atomics Array of atomics nodes.
!> @param[in] num_atomics Number of atomics.
!> @param[in] random_state Optional random state, can be NULL if not used.
!> @param[in] name Name for the kernel.
!> @param[in] num_particles Number of elements to operate on.
Expand All @@ -821,6 +835,7 @@ SUBROUTINE graph_add_item(c, inputs, num_inputs, &
SUBROUTINE graph_add_converge_item(c, inputs, num_inputs, &
outputs, num_outputs, &
map_inputs, map_outputs, num_maps, &
atomics, num_atomics, &
random_state, name, num_particles, &
tol, max_iter) &
BIND(C, NAME='graph_add_converge_item')
Expand All @@ -834,6 +849,8 @@ SUBROUTINE graph_add_converge_item(c, inputs, num_inputs, &
INTEGER(C_INTPTR_T), VALUE :: map_inputs
INTEGER(C_INTPTR_T), VALUE :: map_outputs
INTEGER(C_LONG), VALUE :: num_maps
INTEGER(C_INTPTR_T), VALUE :: atomics
INTEGER(C_LONG), VALUE :: num_atomics
TYPE(C_PTR), VALUE :: random_state
CHARACTER(kind=C_CHAR), DIMENSION(*) :: name
INTEGER(C_LONG), VALUE :: num_particles
Expand Down Expand Up @@ -1588,20 +1605,23 @@ FUNCTION graph_context_atan(this, left, right)
!> @brief Get random size.
!>
!> @param[in,out] this @ref graph_context instance.
!> @param[in] size Number of random numbers needed.
!> @param[in] seed Initial random seed.
!> @returns The random size.
!-------------------------------------------------------------------------------
FUNCTION graph_context_random_state(this, seed)
FUNCTION graph_context_random_state(this, size, seed)

IMPLICIT NONE

! Declare Arguments
TYPE(C_PTR) :: graph_context_random_state
CLASS(graph_context), INTENT(INOUT) :: this
INTEGER(C_LONG), INTENT(IN) :: size
INTEGER(C_INT32_T), INTENT(IN) :: seed

! Start of executable.
graph_context_random_state = graph_random_state(this%c_context, seed)
graph_context_random_state = graph_random_state(this%c_context, &
size, seed)

END FUNCTION

Expand Down Expand Up @@ -2030,13 +2050,15 @@ SUBROUTINE graph_context_set_device_number(this, num)
!> @param[in] outputs Array of output nodes.
!> @param[in] map_inputs Array of map input nodes.
!> @param[in] map_outputs Array of map output nodes.
!> @param[in] atomics Array of atomic nodes.
!> @param[in] random_state Optional random state, can be NULL if not used.
!> @param[in] name Name for the kernel.
!> @param[in] num_particles Number of elements to operate on.
!-------------------------------------------------------------------------------
SUBROUTINE graph_context_add_pre_item(this, inputs, outputs, &
map_inputs, map_outputs, &
random_state, name, num_particles)
atomics, random_state, name, &
num_particles)

IMPLICIT NONE

Expand All @@ -2046,6 +2068,7 @@ SUBROUTINE graph_context_add_pre_item(this, inputs, outputs, &
INTEGER(C_INTPTR_T), DIMENSION(:), INTENT(IN) :: outputs
INTEGER(C_INTPTR_T), DIMENSION(:), INTENT(IN) :: map_inputs
INTEGER(C_INTPTR_T), DIMENSION(:), INTENT(IN) :: map_outputs
INTEGER(C_INTPTR_T), DIMENSION(:), INTENT(IN) :: atomics
TYPE(C_PTR), INTENT(IN) :: random_state
CHARACTER(kind=C_CHAR,len=*), INTENT(IN) :: name
INTEGER(C_LONG), INTENT(IN) :: num_particles
Expand All @@ -2056,6 +2079,8 @@ SUBROUTINE graph_context_add_pre_item(this, inputs, outputs, &
LOC(outputs), INT(SIZE(outputs), KIND=C_LONG), &
LOC(map_inputs), LOC(map_outputs), &
INT(SIZE(map_inputs), KIND=C_LONG), &
LOC(atomics), &
INT(SIZE(atomics), KIND=C_LONG), &
random_state, name, num_particles)

END SUBROUTINE
Expand All @@ -2068,13 +2093,15 @@ SUBROUTINE graph_context_add_pre_item(this, inputs, outputs, &
!> @param[in] outputs Array of output nodes.
!> @param[in] map_inputs Array of map input nodes.
!> @param[in] map_outputs Array of map output nodes.
!> @param[in] atomics Array of atomic nodes.
!> @param[in] random_state Optional random state, can be NULL if not used.
!> @param[in] name Name for the kernel.
!> @param[in] num_particles Number of elements to operate on.
!-------------------------------------------------------------------------------
SUBROUTINE graph_context_add_item(this, inputs, outputs, &
map_inputs, map_outputs, &
random_state, name, num_particles)
atomics, random_state, name, &
num_particles)

IMPLICIT NONE

Expand All @@ -2084,6 +2111,7 @@ SUBROUTINE graph_context_add_item(this, inputs, outputs, &
INTEGER(C_INTPTR_T), DIMENSION(:), INTENT(IN) :: outputs
INTEGER(C_INTPTR_T), DIMENSION(:), INTENT(IN) :: map_inputs
INTEGER(C_INTPTR_T), DIMENSION(:), INTENT(IN) :: map_outputs
INTEGER(C_INTPTR_T), DIMENSION(:), INTENT(IN) :: atomics
TYPE(C_PTR), INTENT(IN) :: random_state
CHARACTER(kind=C_CHAR,len=*), INTENT(IN) :: name
INTEGER(C_LONG), INTENT(IN) :: num_particles
Expand All @@ -2094,6 +2122,8 @@ SUBROUTINE graph_context_add_item(this, inputs, outputs, &
LOC(outputs), INT(SIZE(outputs), KIND=C_LONG), &
LOC(map_inputs), LOC(map_outputs), &
INT(SIZE(map_inputs), KIND=C_LONG), &
LOC(atomics), &
INT(SIZE(atomics), KIND=C_LONG), &
random_state, name, num_particles)

END SUBROUTINE
Expand All @@ -2106,6 +2136,7 @@ SUBROUTINE graph_context_add_item(this, inputs, outputs, &
!> @param[in] outputs Array of output nodes.
!> @param[in] map_inputs Array of map input nodes.
!> @param[in] map_outputs Array of map output nodes.
!> @param[in] atomics Array of atomic nodes.
!> @param[in] random_state Optional random state, can be NULL if not used.
!> @param[in] name Name for the kernel.
!> @param[in] num_particles Number of elements to operate on.
Expand All @@ -2114,7 +2145,7 @@ SUBROUTINE graph_context_add_item(this, inputs, outputs, &
!-------------------------------------------------------------------------------
SUBROUTINE graph_context_add_converge_item(this, inputs, outputs, &
map_inputs, map_outputs, &
random_state, name, &
atomics, random_state, name, &
num_particles, tol, max_iter)

IMPLICIT NONE
Expand All @@ -2125,6 +2156,7 @@ SUBROUTINE graph_context_add_converge_item(this, inputs, outputs, &
INTEGER(C_INTPTR_T), DIMENSION(:), INTENT(IN) :: outputs
INTEGER(C_INTPTR_T), DIMENSION(:), INTENT(IN) :: map_inputs
INTEGER(C_INTPTR_T), DIMENSION(:), INTENT(IN) :: map_outputs
INTEGER(C_INTPTR_T), DIMENSION(:), INTENT(IN) :: atomics
TYPE(C_PTR), INTENT(IN) :: random_state
CHARACTER(kind=C_CHAR,len=*), INTENT(IN) :: name
INTEGER(C_LONG), INTENT(IN) :: num_particles
Expand All @@ -2138,6 +2170,8 @@ SUBROUTINE graph_context_add_converge_item(this, inputs, outputs, &
INT(SIZE(outputs), KIND=C_LONG), &
LOC(map_inputs), LOC(map_outputs), &
INT(SIZE(map_inputs), KIND=C_LONG), &
LOC(atomics), &
INT(SIZE(atomics), KIND=C_LONG), &
random_state, name, num_particles, &
tol, max_iter)

Expand Down
Loading
Loading