示例#1
0
    def __init__(self,
                 detector,
                 seed=None,
                 cuda_device=None,
                 particle_tracking=False,
                 photon_tracking=False,
                 geant4_processes=4,
                 nthreads_per_block=64,
                 max_blocks=1024):
        self.detector = detector

        self.nthreads_per_block = nthreads_per_block
        self.max_blocks = max_blocks
        self.photon_tracking = photon_tracking

        if seed is None:
            self.seed = pick_seed()
        else:
            self.seed = seed

        # We have three generators to seed: numpy.random, GEANT4, and CURAND.
        # The latter two are done below.
        np.random.seed(self.seed)

        if geant4_processes > 0:
            self.photon_generator = generator.photon.G4ParallelGenerator(
                geant4_processes,
                detector.detector_material,
                base_seed=self.seed,
                tracking=particle_tracking)
        else:
            self.photon_generator = None

        self.context = gpu.create_cuda_context(cuda_device)

        if hasattr(detector, 'num_channels'):
            self.gpu_geometry = gpu.GPUDetector(detector)
            self.gpu_daq = gpu.GPUDaq(self.gpu_geometry)
            self.gpu_pdf = gpu.GPUPDF()
            self.gpu_pdf_kernel = gpu.GPUKernelPDF()
        else:
            self.gpu_geometry = gpu.GPUGeometry(detector)

        self.rng_states = gpu.get_rng_states(self.nthreads_per_block *
                                             self.max_blocks,
                                             seed=self.seed)

        self.pdf_config = None
示例#2
0
    def testGPUPDF(self):
        '''Create a hit count and (q,t) PDF for 10 MeV events in MicroLBNE'''

        g4generator = G4ParallelGenerator(1, water)

        context = gpu.create_cuda_context()

        gpu_geometry = gpu.GPUDetector(self.detector)

        nthreads_per_block, max_blocks = 64, 1024

        rng_states = gpu.get_rng_states(nthreads_per_block * max_blocks)

        gpu_daq = gpu.GPUDaq(gpu_geometry)
        gpu_pdf = gpu.GPUPDF()
        gpu_pdf.setup_pdf(self.detector.num_channels(), 100, (-0.5, 999.5), 10,
                          (-0.5, 9.5))

        gpu_pdf.clear_pdf()

        for ev in g4generator.generate_events(
                itertools.islice(self.vertex_gen, 10)):
            gpu_photons = gpu.GPUPhotons(ev.photons_beg)
            gpu_photons.propagate(gpu_geometry, rng_states, nthreads_per_block,
                                  max_blocks)
            gpu_daq.begin_acquire()
            gpu_daq.acquire(gpu_photons, rng_states, nthreads_per_block,
                            max_blocks)
            gpu_channels = gpu_daq.end_acquire()
            gpu_pdf.add_hits_to_pdf(gpu_channels)

        hitcount, pdf = gpu_pdf.get_pdfs()
        self.assertTrue((hitcount > 0).any())
        self.assertTrue((pdf > 0).any())

        # Consistency checks
        for i, nhits in enumerate(hitcount):
            self.assertEqual(nhits, pdf[i].sum())

        context.pop()
示例#3
0
if __name__ == '__main__':
    from chroma import demo
    import gc

    tools.enable_debug_on_crash()

    # Default to run all tests
    tests = ['ray', 'load', 'propagate', 'pdf', 'pdf_eval']
    if len(sys.argv) > 1:
        tests = sys.argv[1:]  # unless test names given on command line

    detector = create_geometry_from_obj(demo.detector())

    context = gpu.create_cuda_context()
    gpu_detector = gpu.GPUDetector(detector)

    if 'ray' in tests:
        print('%s ray intersections/sec.' % \
            tools.ufloat_to_str(intersect(gpu_detector)))
        # run garbage collection since there is a reference loop
        # in the GPUArray class.
        gc.collect()

    if 'load' in tests:
        print('%s photons loaded/sec.' % tools.ufloat_to_str(load_photons()))
        gc.collect()

    if 'propagate' in tests:
        print('%s photons propagated/sec.' % \
            tools.ufloat_to_str(propagate(gpu_detector)))