def setUp(self): self.abort = False if scipy and ocl is None: return try: self.testdata = scipy.misc.ascent() except Exception: # for very old versions of scipy self.testdata = scipy.misc.lena() kernel_base = get_opencl_code(os.path.join("sift", "sift")) if self.orientation_script is None: self.skipTest("Uninitialized parametric class") if "cpu" in self.orientation_script: self.USE_CPU = True else: self.USE_CPU = False if self.USE_CPU: assert("cpu" in self.keypoint_script) else: assert("gpu" in self.keypoint_script) self.wg_orient = self.orientation_param prod_wg = 1 for i in self.wg_orient: prod_wg *= i kernel_src = kernel_base + get_opencl_code(os.path.join("sift", self.orientation_script)) try: self.program_orient = pyopencl.Program(self.ctx, kernel_src).build() except Exception: logger.warning("Failed to compile kernel '%s': aborting" % self.orientation_script) self.abort = True return if prod_wg > self.maxwg: logger.warning("max_work_group_size: %s %s needed", self.maxwg, prod_wg) self.abort = True self.wg_keypoint = self.keypoint_param kernel_src = kernel_base + get_opencl_code(os.path.join("sift", self.keypoint_script)) prod_wg = 1 for i in self.wg_keypoint: prod_wg *= i try: self.program_keypoint = pyopencl.Program(self.ctx, kernel_src).build() except Exception: logger.warning("Failed to compile kernel '%s': aborting" % self.keypoint_script) self.abort = True return if prod_wg > self.maxwg: logger.warning("max_work_group_size: %s %s needed", self.maxwg, prod_wg) self.abort = True
def _compile_kernels(self): """Call the OpenCL compiler """ device = self.ctx.devices[0] query_wg = pyopencl.kernel_work_group_info.WORK_GROUP_SIZE for kernel in list(self.kernels.keys()): if "." in kernel: continue kernel_src = get_opencl_code(kernel) wg_size = self.kernels[kernel] try: program = pyopencl.Program(self.ctx, kernel_src).build( '-D WORKGROUP_SIZE=%s' % wg_size) except pyopencl.MemoryError as error: raise MemoryError(error) except pyopencl.RuntimeError as error: if kernel == "keypoints": logger.warning( "Failed compiling kernel '%s' with workgroup size %s: %s: use low_end alternative", kernel, wg_size, error) self.LOW_END = True else: logger.error( "Failed compiling kernel '%s' with workgroup size %s: %s", kernel, wg_size, error) raise error self.programs[kernel] = program for one_function in program.all_kernels(): workgroup_size = one_function.get_work_group_info( query_wg, device) self.kernels[kernel + "." + one_function.function_name] = workgroup_size
def _compile_kernels(self): """Call the OpenCL compiler """ for kernel, wg_size in list(self.kernels.items()): kernel_src = get_opencl_code(os.path.join("sift", kernel)) if isinstance(wg_size, tuple): wg_size = self.max_workgroup_size try: program = pyopencl.Program(self.ctx, kernel_src).build( '-D WORKGROUP_SIZE=%s' % wg_size) except pyopencl.MemoryError as error: raise MemoryError(error) except pyopencl.RuntimeError as error: if kernel == "keypoints_gpu2": logger.warning( "Failed compiling kernel '%s' with workgroup size %s: %s: use low_end alternative", kernel, wg_size, error) self.LOW_END += 1 elif kernel == "keypoints_gpu1": logger.warning( "Failed compiling kernel '%s' with workgroup size %s: %s: use CPU alternative", kernel, wg_size, error) self.LOW_END += 1 else: logger.error( "Failed compiling kernel '%s' with workgroup size %s: %s", kernel, wg_size, error) raise error self.programs[kernel] = program for one_function in program.all_kernels(): workgroup_size = kernel_workgroup_size(program, one_function) self.kernels[kernel + "." + one_function.function_name] = workgroup_size
def _compile_kernels(self): """ Call the OpenCL compiler """ for kernel in list(self.kernels.keys()): kernel_src = get_opencl_code(os.path.join("sift", kernel)) try: program = pyopencl.Program(self.ctx, kernel_src).build() except pyopencl.MemoryError as error: raise MemoryError(error) self.program = program for one_function in program.all_kernels(): workgroup_size = kernel_workgroup_size(program, one_function) self.kernels[kernel + "." + one_function.function_name] = workgroup_size