From 6254fe21b0c5d5d7a46ec3096aa71fa0af8776c2 Mon Sep 17 00:00:00 2001 From: Braxton Cuneo Date: Mon, 6 May 2024 10:26:49 -0700 Subject: [PATCH] Cleaned up --- mcdc/adapt.py | 3 ++- mcdc/kernel.py | 6 ------ mcdc/type_.py | 35 ++++++++++++++++++++++++++++------- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/mcdc/adapt.py b/mcdc/adapt.py index 55bd0ae7..9a11abb9 100644 --- a/mcdc/adapt.py +++ b/mcdc/adapt.py @@ -12,7 +12,8 @@ HAS_GPU = False except: - print("Warning: GPU capability is not available") + if mcdc.main.target == "gpu": + print("Warning: GPU capability is not available") HAS_GPU = False import math diff --git a/mcdc/kernel.py b/mcdc/kernel.py index 09d8e412..551912e4 100644 --- a/mcdc/kernel.py +++ b/mcdc/kernel.py @@ -997,7 +997,6 @@ def get_particle(P, bank, mcdc): return True -#! Don't touch for now @njit def manage_particle_banks(seed, mcdc): # Record time @@ -1038,7 +1037,6 @@ def manage_particle_banks(seed, mcdc): mcdc["runtime_bank_management"] += time_end - time_start -#! Don't touch for now @njit def manage_IC_bank(mcdc): # Buffer bank @@ -1421,7 +1419,6 @@ def bank_IC(P, prog): precursor["y"] = P["y"] precursor["z"] = P["z"] precursor["w"] = wp_prime / wn_prime - #! Ask Ilham about this # Sample group xi = rng(P) * total @@ -2184,7 +2181,6 @@ def score_eddington(s, g, t, x, y, z, flux, P, score): adapt.global_add(score["bin"], (s, g, t, x, y, z, 5), flux * uz * uz) -#! Don't touch for now @njit def score_reduce_bin(score, mcdc): # Normalize @@ -2207,7 +2203,6 @@ def score_closeout_history(score): score["bin"].fill(0.0) -#! Don't touch for now @njit def score_closeout(score, mcdc): N_history = mcdc["setting"]["N_particle"] @@ -2321,7 +2316,6 @@ def eigenvalue_tally(P, distance, mcdc): mcdc["C_max"] = C_density -#! Don't touch for now @njit def eigenvalue_tally_closeout_history(mcdc): N_particle = mcdc["setting"]["N_particle"] diff --git a/mcdc/type_.py b/mcdc/type_.py index ac9b1a3a..d4cae5b2 100644 --- a/mcdc/type_.py +++ b/mcdc/type_.py @@ -41,6 +41,34 @@ # ============================================================================== +# While CPU execution can robustly handle all sorts of Numba types, GPU +# execution requires structs to follow some of the basic properties expected of +# C-style structs with standard layout: +# +# - Every primitive field is aligned by its size, and padding is inserted +# between fields to ensure alignment in arrays and nested data structures +# +# - Every field has a unique address +# +# If these rules are violated, memory accesses made in GPUs may encounter +# problems. For example, in cases where an access is not at an address aligned +# by their size, a segfault or similar fault will occur, or information will be +# lost. These issues were fixed by providing a function, align, which ensures the +# field lists fed to np.dtype fulfill these requirements. +# +# The align function does the following: +# +# - Tracks the cumulative offset of fields as they appear in the input list. +# +# - Inserts additional padding fields to ensure that primitive fields are +# aligned by their size +# +# - Re-sizes arrays to have at least one element in their array (this ensure +# they have a non-zero size, and hence cannot overlap base addresses with +# other fields. +# + + def fixup_dims(dim_tuple): return tuple([max(d, 1) for d in dim_tuple]) @@ -70,9 +98,6 @@ def align(field_list): else: print_error("Unexpected field item type") - if multiplier == 0: - multiplier = 1 - size *= multiplier if offset % alignment != 0: @@ -1188,10 +1213,6 @@ def make_type_domain_decomp(input_deck): # ============================================================================== -def copy_global(dst, src): - pass - - def make_type_global(input_deck): global global_