From 4bf95f452e3275c12026b16b51dc646846598f19 Mon Sep 17 00:00:00 2001 From: Anthony LaTorre Date: Wed, 3 Aug 2011 14:32:49 -0400 Subject: add a GPU class to handle both the gpu context and module; since the geometry requires global device pointers, there should be a one to one correspondence between modules and contexts. the current plan is to perform all gpu operations within this class. also add a simple color map to display hit pmt charge and timing information. --- camera.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) mode change 100644 => 100755 camera.py (limited to 'camera.py') diff --git a/camera.py b/camera.py old mode 100644 new mode 100755 index 37dc072..12f3e6b --- a/camera.py +++ b/camera.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python import numpy as np from itertools import product, count from threading import Thread, Lock @@ -71,12 +72,16 @@ def get_rays(position, size = (800, 600), film_size = (0.035, 0.024), focal_leng return grid, focal_point-grid class Camera(Thread): - def __init__(self, geometry, module, context, lock, size=(800,600)): + def __init__(self, geometry, module, context, lock=None, size=(800,600)): Thread.__init__(self) self.geometry = geometry self.module = module self.context = context - self.lock = lock + + if lock is None: + self.lock = Lock() + else: + self.lock = lock self.size = size self.width, self.height = size @@ -247,7 +252,7 @@ class Camera(Thread): def update(self): if self.render: - while self.nlookup_calls < 10: + while self.nlookup_calls < 100: self.update_xyz_lookup(self.source_position) self.update_image() self.process_image() @@ -355,7 +360,7 @@ class Camera(Thread): self.source_position = self.point if event.key == K_p: - for i in range(10): + for i in range(100): self.update_xyz_lookup(self.point) self.source_position = self.point @@ -479,18 +484,14 @@ if __name__ == '__main__': raise Exception("can't find object %s" % args[0]) from pycuda.tools import make_default_context + from gpu import * - cuda.init() - context = make_default_context() - print 'device %s' % context.get_device().name() - - module = SourceModule(src.kernel, options=['-I' + src.dir], no_extern_c=True, cache_dir=False) geometry = build(obj, options.bits) - geometry.load(module) lock = Lock() - camera = Camera(geometry, module, context, lock, size) - - context.pop() + gpu = GPU() + gpu.load_geometry(geometry) + gpu.context.pop() + camera = Camera(geometry, gpu.module, gpu.context, lock, size=size) camera.start() -- cgit