Exemple #1
0
    def _extract_photons_from_tracking_action(self, sort=True):
        n = self.tracking_action.GetNumPhotons()
        pos = np.zeros(shape=(n, 3), dtype=np.float32)
        pos[:, 0] = self.tracking_action.GetX()
        pos[:, 1] = self.tracking_action.GetY()
        pos[:, 2] = self.tracking_action.GetZ()

        dir = np.zeros(shape=(n, 3), dtype=np.float32)
        dir[:, 0] = self.tracking_action.GetDirX()
        dir[:, 1] = self.tracking_action.GetDirY()
        dir[:, 2] = self.tracking_action.GetDirZ()

        pol = np.zeros(shape=(n, 3), dtype=np.float32)
        pol[:, 0] = self.tracking_action.GetPolX()
        pol[:, 1] = self.tracking_action.GetPolY()
        pol[:, 2] = self.tracking_action.GetPolZ()

        wavelengths = self.tracking_action.GetWavelength().astype(np.float32)

        t0 = self.tracking_action.GetT0().astype(np.float32)

        if sort:
            reorder = argsort_direction(dir)
            pos = pos[reorder]
            dir = dir[reorder]
            pol = pol[reorder]
            wavelengths = wavelengths[reorder]
            t0 = t0[reorder]

        return Photons(pos, dir, pol, wavelengths, t0)
Exemple #2
0
def intersect(gpu_geometry,
              number=100,
              nphotons=500000,
              nthreads_per_block=64,
              max_blocks=1024):
    "Returns the average number of ray intersections per second."
    distances_gpu = ga.empty(nphotons, dtype=np.float32)

    module = gpu.get_cu_module('mesh.h', options=('--use_fast_math', ))
    gpu_funcs = gpu.GPUFuncs(module)

    run_times = []
    for i in tools.progress(list(range(number))):
        pos = ga.zeros(nphotons, dtype=ga.vec.float3)
        dir = sample.uniform_sphere(nphotons)
        reorder = tools.argsort_direction(dir)
        dir = ga.to_gpu(gpu.to_float3(dir[reorder]))

        t0 = time.time()
        gpu_funcs.distance_to_mesh(np.int32(pos.size),
                                   pos,
                                   dir,
                                   gpu_geometry.gpudata,
                                   distances_gpu,
                                   block=(nthreads_per_block, 1, 1),
                                   grid=(pos.size // nthreads_per_block + 1,
                                         1))
        cuda.Context.get_current().synchronize()
        elapsed = time.time() - t0

        if i > 0:
            # first kernel call incurs some driver overhead
            run_times.append(elapsed)

    return nphotons / ufloat((np.mean(run_times), np.std(run_times)))
Exemple #3
0
def propagate(gpu_detector,
              number=10,
              nphotons=500000,
              nthreads_per_block=64,
              max_blocks=1024):
    "Returns the average number of photons propagated on the GPU per second."
    rng_states = gpu.get_rng_states(nthreads_per_block * max_blocks)

    run_times = []
    for i in tools.progress(list(range(number))):
        pos = np.zeros((nphotons, 3))
        dir = sample.uniform_sphere(nphotons)
        reorder = tools.argsort_direction(dir)
        dir = dir[reorder]
        pol = normalize(np.cross(sample.uniform_sphere(nphotons), dir))
        wavelengths = np.random.uniform(400, 800, size=nphotons)
        photons = event.Photons(pos, dir, pol, wavelengths)
        gpu_photons = gpu.GPUPhotons(photons)

        t0 = time.time()
        gpu_photons.propagate(gpu_detector, rng_states, nthreads_per_block,
                              max_blocks)
        cuda.Context.get_current().synchronize()
        elapsed = time.time() - t0

        if i > 0:
            # first kernel call incurs some driver overhead
            run_times.append(elapsed)

    return nphotons / ufloat((np.mean(run_times), np.std(run_times)))
Exemple #4
0
    def _extract_photons_from_tracking_action(self, sort=True):
        n = self.tracking_action.GetNumPhotons()        
        pos = np.zeros(shape=(n,3), dtype=np.float32)
        pos[:,0] = self.tracking_action.GetX()
        pos[:,1] = self.tracking_action.GetY()
        pos[:,2] = self.tracking_action.GetZ()

        dir = np.zeros(shape=(n,3), dtype=np.float32)
        dir[:,0] = self.tracking_action.GetDirX()
        dir[:,1] = self.tracking_action.GetDirY()
        dir[:,2] = self.tracking_action.GetDirZ()

        pol = np.zeros(shape=(n,3), dtype=np.float32)
        pol[:,0] = self.tracking_action.GetPolX()
        pol[:,1] = self.tracking_action.GetPolY()
        pol[:,2] = self.tracking_action.GetPolZ()
        
        wavelengths = self.tracking_action.GetWavelength().astype(np.float32)

        t0 = self.tracking_action.GetT0().astype(np.float32)

        if sort:
            reorder = argsort_direction(dir)
            pos = pos[reorder]
            dir = dir[reorder]
            pol = pol[reorder]
            wavelengths = wavelengths[reorder]
            t0 = t0[reorder]

        return Photons(pos, dir, pol, wavelengths, t0)