Skip to content

Commit 235bdce

Browse files
committed
add gpu_meta
1 parent 156596e commit 235bdce

8 files changed

Lines changed: 51 additions & 30 deletions

File tree

mcdc/code_factory/code_factory.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -315,18 +315,6 @@ def generate_numba_objects(simulation):
315315

316316
structures["simulation"] = new_structure + structures["simulation"]
317317

318-
# GPU interop.
319-
structures["simulation"] += [
320-
("gpu_state_pointer", "u8"),
321-
("source_program_pointer", "u8"),
322-
("precursor_program_pointer", "u8"),
323-
("source_seed", "u8"),
324-
]
325-
records["simulation"]["gpu_state_pointer"] = 0
326-
records["simulation"]["source_program_pointer"] = 0
327-
records["simulation"]["precursor_program_pointer"] = 0
328-
records["simulation"]["source_seed"] = 0
329-
330318
# Print the fields
331319
if MPI.COMM_WORLD.Get_rank() == 0:
332320
with open(f"{Path(mcdc.__file__).parent}/object_/numba_types.py", "w") as f:
@@ -365,7 +353,7 @@ def generate_numba_objects(simulation):
365353
if len(item) == 3:
366354
size = item[2][0]
367355

368-
# Skip particle banks
356+
# Skip particular attributes
369357
if field in bank_names:
370358
continue
371359

@@ -388,6 +376,11 @@ def generate_numba_objects(simulation):
388376
singular_field
389377
][i][sub_item[0]]
390378

379+
380+
# Manually set particle bank attributes
381+
for name in bank_names:
382+
mcdc_simulation[name]['tag'] = getattr(simulation, name).tag
383+
391384
return mcdc_simulation_arr, data["array"]
392385

393386

mcdc/main.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -215,16 +215,6 @@ def preparation():
215215
importlib.reload(mcdc_get)
216216
importlib.reload(mcdc_set)
217217

218-
# ==================================================================================
219-
# Set some Numba object fields
220-
# ==================================================================================
221-
222-
# Particle bank tags
223-
mcdc["bank_active"]["tag"] = "active"
224-
mcdc["bank_census"]["tag"] = "census"
225-
mcdc["bank_source"]["tag"] = "source"
226-
mcdc["bank_future"]["tag"] = "future"
227-
228218
# ==================================================================================
229219
# Platform Targeting, Adapters, Toggles, etc
230220
# ==================================================================================
@@ -263,6 +253,8 @@ def preparation():
263253
# TODO: Use parallel h5py
264254
# ==================================================================================
265255

256+
import h5py
257+
266258
# All ranks, take turn
267259
for i in range(mcdc["mpi_size"]):
268260
if mcdc["mpi_rank"] == i:
@@ -285,13 +277,9 @@ def preparation():
285277
MPI.COMM_WORLD.Barrier()
286278

287279
# ==================================================================================
288-
# Finalize data: wrapping into a tuple
280+
# Adapt functions
289281
# ==================================================================================
290282

291-
from mcdc.transport.simulation import setup_gpu
292-
293-
setup_gpu(mcdc)
294-
295283
# Pick physics model
296284
import mcdc.transport.physics as physics
297285

@@ -310,7 +298,13 @@ def preparation():
310298
rng.wrapping_add = rng.wrapping_add_python
311299
rng.wrapping_mul = rng.wrapping_mul_python
312300

313-
# TODO: Delete Python objects if running in Numba mode
301+
# ==================================================================================
302+
# Finalize data: wrapping into a tuple
303+
# ==================================================================================
304+
305+
from mcdc.transport.simulation import setup_gpu
306+
307+
setup_gpu(mcdc)
314308

315309
return mcdc_arr, data
316310

mcdc/mcdc_get/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444

4545
import mcdc.mcdc_get.tabulated_energy_angle_distribution as tabulated_energy_angle_distribution
4646

47+
import mcdc.mcdc_get.gpu_meta as gpu_meta
48+
4749
import mcdc.mcdc_get.native_material as native_material
4850

4951
import mcdc.mcdc_get.multigroup_material as multigroup_material

mcdc/mcdc_get/gpu_meta.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# The following is automatically generated by code_factory.py
2+
3+
from numba import njit

mcdc/mcdc_set/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444

4545
import mcdc.mcdc_set.tabulated_energy_angle_distribution as tabulated_energy_angle_distribution
4646

47+
import mcdc.mcdc_set.gpu_meta as gpu_meta
48+
4749
import mcdc.mcdc_set.native_material as native_material
4850

4951
import mcdc.mcdc_set.multigroup_material as multigroup_material

mcdc/mcdc_set/gpu_meta.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# The following is automatically generated by code_factory.py
2+
3+
from numba import njit

mcdc/object_/gpu_tools.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from dataclasses import dataclass
2+
from numpy import uint64
3+
4+
####
5+
6+
from mcdc.object_.base import ObjectSingleton
7+
8+
@dataclass
9+
class GPUMeta(ObjectSingleton):
10+
# Annotations for Numba mode
11+
label: str = "gpu_meta"
12+
#
13+
state_pointer: uint64 = uint64(0)
14+
source_program_pointer: uint64 = uint64(0)
15+
precursor_program_pointer: uint64 = uint64(0)
16+
structure_pointer: uint64 = uint64(0)
17+
data_pointer: uint64 = uint64(0)

mcdc/object_/simulation.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@
2222
import numpy as np
2323

2424
from mpi4py import MPI
25-
from numpy import float64, int64, uint64, uintp
25+
from numpy import float64, int64
2626
from numpy.typing import NDArray
2727

2828
####
2929

3030
from mcdc.object_.base import ObjectSingleton
3131
from mcdc.object_.data import DataBase, DataNone
3232
from mcdc.object_.distribution import DistributionBase, DistributionNone
33+
from mcdc.object_.gpu_tools import GPUMeta
3334
from mcdc.object_.mesh import MeshBase
3435
from mcdc.object_.particle import ParticleBank
3536
from mcdc.object_.settings import Settings
@@ -124,6 +125,9 @@ class Simulation(ObjectSingleton):
124125
runtime_output: float
125126
runtime_bank_management: float
126127

128+
# GPU metadata
129+
gpu_meta: GPUMeta
130+
127131
def __init__(self):
128132
super().__init__()
129133

@@ -218,6 +222,9 @@ def __init__(self):
218222
self.runtime_output = 0.0
219223
self.runtime_bank_management = 0.0
220224

225+
# GPU metadata
226+
self.gpu_meta = GPUMeta()
227+
221228
def set_root_universe(self, cells=[]):
222229
self.universes[0].cells = cells
223230

0 commit comments

Comments
 (0)