def __init__(self, size=None, interpolation='linear'): """ e.g. size = (300,300)""" try: # simulate GPU fail... # raise Exception() # self.dev = OCLDevice(useGPU = True, # useDevice = spimagine.__OPENCLDEVICE__) # FIXME # device should not be reinitialized as then # every other queue becomes invalid # init_device(useGPU = True, # useDevice = spimagine.config.__OPENCLDEVICE__) self.isGPU = True except Exception as e: print(e) print("could not find GPU OpenCL device - trying CPU...") try: init_device(useGPU=False) self.isGPU = False self.dtypes = [np.float32] except Exception as e: print(e) print("could not find any OpenCL device ... sorry") self.memMax = .7 * get_device().get_info("MAX_MEM_ALLOC_SIZE") # self.memMax = 2.*get_device().get_info("MAX_MEM_ALLOC_SIZE") build_options_basic = [ "-I", "%s" % absPath("kernels/"), "-D", "maxSteps=%s" % spimagine.config.__DEFAULTMAXSTEPS__, ] if spimagine.config.__QUALIFIER_CONSTANT_TO_GLOBAL__: build_options_basic += ["-D", "QUALIFIER_CONSTANT_TO_GLOBAL"] interpolation_defines = { "linear": ["-D", "SAMPLER_FILTER=CLK_FILTER_LINEAR"], "nearest": ["-D", "SAMPLER_FILTER=CLK_FILTER_NEAREST"] } if interpolation in interpolation_defines: self.interp = interpolation build_options_basic += interpolation_defines[interpolation] else: raise KeyError("interpolation = '%s' not defined ,valid: %s" % (interpolation, list(interpolation_defines.keys()))) try: self.proc = OCLProgram( absPath("kernels/all_render_kernels.cl"), build_options=build_options_basic + [ "-cl-finite-math-only", "-cl-fast-relaxed-math", "-cl-unsafe-math-optimizations", "-cl-mad-enable" ]) except Exception as e: logger.debug(str(e)) self.proc = OCLProgram(absPath("kernels/all_render_kernels.cl"), build_options=build_options_basic) self.invMBuf = OCLArray.empty(16, dtype=np.float32) self.invPBuf = OCLArray.empty(16, dtype=np.float32) self.projection = np.zeros((4, 4)) self.modelView = np.zeros((4, 4)) if size: self.resize(size) else: self.resize((200, 200)) self.set_dtype() self.set_gamma() self.set_max_val() self.set_min_val() self.set_occ_strength(.1) self.set_occ_radius(21) self.set_occ_n_points(30) self.set_alpha_pow() self.set_box_boundaries() self.set_units() self.set_modelView() self.set_projection()
def __init__(self, size=None, interpolation='linear'): """ e.g. size = (300,300)""" try: # simulate GPU fail... # raise Exception() # self.dev = OCLDevice(useGPU = True, # useDevice = spimagine.__OPENCLDEVICE__) # FIXME # device should not be reinitialized as then # every other queue becomes invalid # init_device(useGPU = True, # useDevice = spimagine.config.__OPENCLDEVICE__) self.isGPU = True except Exception as e: print(e) print("could not find GPU OpenCL device - trying CPU...") try: init_device(useGPU=False) self.isGPU = False self.dtypes = [np.float32] except Exception as e: print(e) print("could not find any OpenCL device ... sorry") self.memMax = .7 * get_device().get_info("MAX_MEM_ALLOC_SIZE") # self.memMax = 2.*get_device().get_info("MAX_MEM_ALLOC_SIZE") self.rebuild_program(interpolation=interpolation) self.invMBuf = OCLArray.empty(16, dtype=np.float32) self.invPBuf = OCLArray.empty(16, dtype=np.float32) self.projection = np.zeros((4, 4)) self.modelView = np.zeros((4, 4)) if size: self.resize(size) else: self.resize((200, 200)) self.set_dtype() self.set_gamma() self.set_max_val() self.set_min_val() self.set_occ_strength(.1) self.set_occ_radius(21) self.set_occ_n_points(30) self.set_alpha_pow() self.set_box_boundaries() self.set_units() self.set_modelView() self.set_projection()
__DEFAULT_WIDTH__ = _get_param("window_width", int) __DEFAULT_SPIN_AXIS__ = _get_param("spin_axis", int) __DEFAULT_BOX_LINEWIDTH__= _get_param("box_linewidth", float) __DEFAULT_HEIGHT__ = _get_param("window_height", int) __DEFAULTMAXSTEPS__ = _get_param("max_steps", int) __DEFAULT_INTERP__ = _get_param("interpolation", str) __QUALIFIER_CONSTANT_TO_GLOBAL__ = _get_param("_qualifier_constant_to_global", bool) __COLORMAPDICT__ = loadcolormaps() init_device(id_platform=__ID_PLATFORM__, id_device=__ID_DEVICE__, use_gpu=__USE_GPU__) # this should fix an annoying file url drag drop bug in mac yosemite import platform __SYSTEM_DARWIN__ = False if platform.system() == "Darwin": __SYSTEM_DARWIN__ = True def _parseFileNameFix(fpath): from subprocess import check_output path = check_output(["osascript", "-e", "get posix path of posix file \"file://%s\" -- kthxbai" % fpath]) path = path[:-1].decode("unicode_escape")