From df2166036cf387e8b265b5c22d07af1d3811d7b6 Mon Sep 17 00:00:00 2001 From: Braxton Cuneo Date: Sun, 25 Feb 2024 17:03:17 -0800 Subject: [PATCH] Commit for transfer --- mcdc/adapt.py | 24 ++++++++------- mcdc/loop.py | 39 +++++++++-------------- mcdc/type_.py | 85 +++++++++++++++++++++++++++++++++++++++++---------- 3 files changed, 96 insertions(+), 52 deletions(-) diff --git a/mcdc/adapt.py b/mcdc/adapt.py index 7a2a2a77..3c123d49 100644 --- a/mcdc/adapt.py +++ b/mcdc/adapt.py @@ -101,18 +101,18 @@ def blankout_fn(func): mod_name = func.__module__ fn_name = func.__name__ id = (mod_name,fn_name) - + if id not in blankout_roster: global do_nothing_id name = func.__name__ #print(f"do_nothing_{do_nothing_id} for {name}") arg_count = len(inspect.signature(func).parameters) blankout_roster[id] = generate_do_nothing(arg_count,crash_on_call=f"blankout fn for {name} should never be called") - + blank = blankout_roster[id] return blank - + @@ -176,7 +176,7 @@ def nopython_mode(is_on): return if not isinstance(target_rosters['cpu'],dict): return - + for impl in target_rosters['cpu'].values(): overwrite_func(impl,impl) @@ -212,6 +212,7 @@ def universal_arrays_inner (func): none_type = None mcdc_type = None +mcdc_array_type = None state_spec = None device_gpu = None group_gpu = None @@ -225,13 +226,14 @@ def universal_arrays_inner (func): def gpu_forward_declare(): - global none_type, mcdc_type, state_spec + global none_type, mcdc_type, mcdc_array_type, state_spec global device_gpu, group_gpu, thread_gpu global particle_gpu, particle_record_gpu global step_async, find_cell_async none_type = numba.from_dtype(np.dtype([ ])) mcdc_type = numba.from_dtype(type_.global_) + mcdc_array_type = numba.from_dtype(np.dtype((type_.global_,(1,)))) state_spec = (mcdc_type,none_type,none_type) device_gpu, group_gpu, thread_gpu = harm.RuntimeSpec.access_fns(state_spec) particle_gpu = numba.from_dtype(type_.particle) @@ -331,7 +333,7 @@ def add_IC(particle, prog): @for_cpu() def local_translate(): return np.zeros(1, dtype=type_.translate)[0] - + @for_gpu() def local_translate(): trans = cuda.local.array(1, type_.translate)[0] @@ -343,7 +345,7 @@ def local_translate(): @for_cpu() def local_group_array(): return np.zeros(1, dtype=type_.group_array)[0] - + @for_gpu() def local_group_array(): return cuda.local.array(1, type_.group_array)[0] @@ -352,7 +354,7 @@ def local_group_array(): @for_cpu() def local_j_array(): return np.zeros(1, dtype=type_.j_array)[0] - + @for_gpu() def local_j_array(): return cuda.local.array(1, type_.j_array)[0] @@ -406,7 +408,7 @@ def global_max(ary,idx,val): # Program Specifications # ========================================================================= -state_spec = None +state_spec = None one_event_fns = None multi_event_fns = None @@ -420,7 +422,7 @@ def make_spec(target): global device_gpu, group_gpu, thread_gpu global iterate_async if target == 'gpu': - state_spec = (dev_state_type,grp_state_type,thd_state_type) + state_spec = (dev_state_type,grp_state_type,thd_state_type) one_event_fns = [iterate] #multi_event_fns = [source,move,scattering,fission,leakage,bcollision] device_gpu, group_gpu, thread_gpu = harm.RuntimeSpec.access_fns(state_spec) @@ -443,7 +445,7 @@ def initialize(prog: numba.uintp): def finalize(prog: numba.uintp): final_fn(prog) def step(prog: numba.uintp, arg: arg_type): - + step_async() step_async, = harm.RuntimeSpec.async_dispatch(step) diff --git a/mcdc/loop.py b/mcdc/loop.py index cdd9f385..3d75069b 100644 --- a/mcdc/loop.py +++ b/mcdc/loop.py @@ -1055,7 +1055,7 @@ def run_source_gpu_rt(mcdc): while True: source_gpu_rt.init(4096) source_gpu_rt.exec(65536,288) - #print(f"({count})") + print(f"(source {count})") count += 1 if source_gpu_rt.halted(): break @@ -1067,7 +1067,7 @@ def run_precursor_gpu_rt(mcdc): while True: precursor_gpu_rt.init(4096) precursor_gpu_rt.exec(65536,288) - #print(f"({count})") + print(f"(precursor {count})") count += 1 if source_gpu_rt.halted(): break @@ -1283,7 +1283,7 @@ def process_source_precursors(seed,mcdc): mcdc["source_precursor_seed"] = seed with objmode(mcdc_new = adapt.mcdc_type): - mcdc_new = run_precursor_gpu_rt(mcdc) + mcdc_new = run_precursor_gpu_rt(mcdc)[0] mcdc["tally"] = mcdc_new["tally"] mcdc["setting"] = mcdc_new["setting"] @@ -1315,32 +1315,21 @@ def process_sources(seed,mcdc): mcdc["mpi_work_iter"][0] = 0 mcdc["source_seed"] = seed - with objmode(mcdc_new = adapt.mcdc_type): + mcdc_new = np.zeros(1, dtype=type_.global_) + with objmode(mcdc_new = adapt.mcdc_array_type): mcdc_new = run_source_gpu_rt(mcdc) - mcdc["tally"] = mcdc_new["tally"] - mcdc["setting"] = mcdc_new["setting"] - mcdc["technique"] = mcdc_new["technique"] - mcdc["bank_active"] = mcdc_new["bank_active"] - mcdc["bank_census"] = mcdc_new["bank_census"] - mcdc["bank_source"] = mcdc_new["bank_source"] - mcdc["bank_precursor"] = mcdc_new["bank_precursor"] - #mcdc["i_cycle"] = mcdc_new["i_cycle"] - mcdc["cycle_active"] = mcdc_new["cycle_active"] - mcdc["eigenvalue_tally_nuSigmaF"] = mcdc_new["eigenvalue_tally_nuSigmaF"] - mcdc["eigenvalue_tally_n"] = mcdc_new["eigenvalue_tally_n"] - mcdc["eigenvalue_tally_C"] = mcdc_new["eigenvalue_tally_C"] - mcdc["runtime_total"] = mcdc_new["runtime_total"] - mcdc["runtime_preparation"] = mcdc_new["runtime_preparation"] - mcdc["runtime_simulation"] = mcdc_new["runtime_simulation"] - mcdc["runtime_output"] = mcdc_new["runtime_output"] - mcdc["runtime_bank_management"] = mcdc_new["runtime_bank_management"] - mcdc["particle_track"] = mcdc_new["particle_track"] - mcdc["particle_track_N"] = mcdc_new["particle_track_N"] - mcdc["particle_track_history_ID"] = mcdc_new["particle_track_history_ID"] - mcdc["particle_track_particle_ID"] = mcdc_new["particle_track_particle_ID"] + print("A") + #mcdc["mpi_work_iter"] = mcdc_new[0]["mpi_work_iter"] + type_.copy_global(mcdc,mcdc_new[0]) + with objmode(): + print(mcdc_new[0]["mpi_work_iter"]) + print(mcdc["mpi_work_iter"]) + + print("Setting bank size") kernel.set_bank_size(mcdc["bank_active"],0) + print("Finished processing sources") return process_sources diff --git a/mcdc/type_.py b/mcdc/type_.py index 1e27f083..c55229b9 100644 --- a/mcdc/type_.py +++ b/mcdc/type_.py @@ -56,8 +56,6 @@ def align(field_list): if len(field) == 3: field = ( field[0], field[1], fixup_dims(field[2]) ) for d in field[2]: - if d == 0: - print("AAAAAAAAAAAAAAAAAA") multiplier *= d kind = np.dtype(field[1]) size = kind.itemsize @@ -89,7 +87,7 @@ def align(field_list): result.append((f"padding_{pad_id}", uint8, (pad_size,))) pad_id += 1 - print(result) + #print(result) return result @@ -199,8 +197,8 @@ def make_type_particle_record(input_deck): ("E", float64), ("w", float64), ("sensitivity_ID", int64), + ("alive", bool_), # Should not be last until padding before nested structs is figured out ("rng_seed", uint64), - ("alive", bool_), ] # Get modes @@ -219,10 +217,12 @@ def make_type_particle_record(input_deck): iqmc_struct = [("w", float64, (G,))] if input_deck.setting["track_particle"]: struct += [("track_pid",int64),("track_hid",int64)] - struct += [("iqmc", iqmc_struct)] + struct += [("iqmc", into_dtype(iqmc_struct))] + print(np.dtype(struct)) # Save type particle_record = into_dtype(struct) + print(particle_record) precursor = into_dtype( @@ -244,13 +244,13 @@ def make_type_particle_record(input_deck): def particle_bank(max_size): return into_dtype( - [("particles", particle_record, (max_size,)), ("size", int64, (1,)), ("tag", "U16")] + [("particles", particle_record, (max_size,)), ("size", int64, (1,)), ("tag", "U32")] ) def precursor_bank(max_size): return into_dtype( - [("precursors", precursor, (max_size,)), ("size", int64, (1,)), ("tag", "U16")] + [("precursors", precursor, (max_size,)), ("size", int64, (1,)), ("tag", "U32")] ) @@ -727,7 +727,7 @@ def make_type_setting(deck): ("mode_CE", bool_), # Misc. ("progress_bar", bool_), - ("output_name", "U30"), + ("output_name", str_), ("save_input_deck", bool_), ("track_particle", bool_), # Eigenvalue mode @@ -744,10 +744,10 @@ def make_type_setting(deck): ("census_time", float64, (card["N_census"],)), # Particle source file ("source_file", bool_), - ("source_file_name", "U30"), + ("source_file_name", str_), # Initial condition source file ("IC_file", bool_), - ("IC_file_name", "U30"), + ("IC_file_name", str_), ("N_precursor", uint64), # TODO: Move to technique ("N_sensitivity", uint64), @@ -1249,8 +1249,9 @@ def make_type_parameter(G, J, decay=False): # Global # ============================================================================== -def copy_global(dst,src): - pass + + + def make_type_global(input_deck): global global_ @@ -1324,6 +1325,7 @@ def make_type_global(input_deck): # GLobal type global_ = into_dtype( [ + ("mpi_work_iter", int64, (1,)), ("nuclides", nuclide, (N_nuclide,)), ("materials", material, (N_material,)), ("surfaces", surface, (N_surface,)), @@ -1352,7 +1354,6 @@ def make_type_global(input_deck): ("k_sdv_running", float64), ("gyration_radius", float64, (N_cycle,)), ("idx_cycle", int64), - ("cycle_active", bool_), ("eigenvalue_tally_nuSigmaF", float64, (1,)), ("eigenvalue_tally_n", float64, (1,)), ("eigenvalue_tally_C", float64, (1,)), @@ -1360,7 +1361,6 @@ def make_type_global(input_deck): ("idx_batch", int64), ("mpi_size", int64), ("mpi_rank", int64), - ("mpi_master", bool_), ("mpi_work_start", int64), ("mpi_work_size", int64), ("mpi_work_size_total", int64), @@ -1377,9 +1377,10 @@ def make_type_global(input_deck): ("particle_track_history_ID", int64, (1,)), ("particle_track_particle_ID", int64, (1,)), ("precursor_strength", float64), - ("mpi_work_iter", int64, (1,)), ("source_seed", uint64), - ("source_precursor_seed", uint64) + ("source_precursor_seed", uint64), + ("mpi_master", bool_), + ("cycle_active", bool_), ] ) @@ -1465,3 +1466,55 @@ def make_type_mesh_(card): mesh_names = ["x", "y", "z", "t", "mu", "azi", "g"] + + + + + + +@njit +def copy_global(dst,src): + dst["mpi_work_iter"] = src["mpi_work_iter"] + #dst["tally"] = src["tally"] + #dst["bank_active"] = src["bank_active"].deep_copy() + #dst["bank_census"] = src["bank_census"] + #dst["bank_source"] = src["bank_source"] + print("B") + #dst["setting"] = src["setting"] + print("C") + #dst["technique"] = src["technique"] + print("D") + #dst["bank_precursor"] = src["bank_precursor"] + print("E") + ##dst["i_cycle"] = src["i_cycle"] + #dst["cycle_active"] = src["cycle_active"] + print("F") + #dst["eigenvalue_tally_nuSigmaF"] = src["eigenvalue_tally_nuSigmaF"] + print("G") + #dst["eigenvalue_tally_n"] = src["eigenvalue_tally_n"] + print("H") + #dst["eigenvalue_tally_C"] = src["eigenvalue_tally_C"] + print("I") + #dst["runtime_total"] = src["runtime_total"] + print("J") + #dst["runtime_preparation"] = src["runtime_preparation"] + print("K") + #dst["runtime_simulation"] = src["runtime_simulation"] + print("L") + #dst["runtime_output"] = src["runtime_output"] + print("M") + #dst["runtime_bank_management"] = src["runtime_bank_management"] + print("N") + #dst["particle_track"] = src["particle_track"] + print("O") + #dst["particle_track_N"] = src["particle_track_N"] + print("P") + #dst["particle_track_history_ID"] = src["particle_track_history_ID"] + print("Q") + #dst["particle_track_particle_ID"] = src["particle_track_particle_ID"] + print("R") + print("S") + print("T") + pass + +