def _to_dask_cudf(futures, client=None): """ Convert a list of futures containing cudf Dataframes into a Dask.Dataframe :param futures: list[cudf.Dataframe] list of futures containing dataframes :param client: dask.distributed.Client Optional client to use :return: dask.Dataframe a dask.Dataframe """ c = default_client() if client is None else client # Convert a list of futures containing dfs back into a dask_cudf dfs = [d for d in futures if d.type != type(None)] # NOQA if logger.should_log_for(logger.level_debug): logger.debug("to_dask_cudf dfs=%s" % str(dfs)) meta_future = c.submit(_get_meta, dfs[0], pure=False) meta = meta_future.result() return dd.from_delayed(dfs, meta=meta)
def cuda_kernel_factory(nvrtc_kernel_str, dtypes, kernel_name=None): """ A factory wrapper function to perform some of the boiler-plate involved in making cuPy RawKernels type-agnostic. Until a better method is created, either by RAPIDS or cuPy, this function will perform a string search and replace of c-based datatype primitives in ``nvrtc_kernel_str`` using a numerical placeholder (eg. {0}, {1}) for the dtype in the corresponding index of tuple ``dtypes``. Note that the extern, function scope, and function name should not be included in the kernel string. These will be added by this function and the function name will be made unique, based on the given dtypes. Example ------- The following kernel string with dtypes = [float, double, int] ({0} *a, {1} *b, {2} *c) {} Will become (float *a, double *b, int *c) {} Parameters ---------- nvrtc_kernel_str : string valid nvrtc kernel string without extern, scope, or function name. dtypes : tuple of dtypes to search and replace. kernel_name : string prefix and function name to use. Note that when this not set (or is set to None), a UUID will be used, which will stop this function from being memoized. Returns ------- kernel_name : string unique function name created for kernel, raw_kernel : cupy.RawKernel object ready for use """ dtype_strs = get_dtype_strs(dtypes) for idx, dtype in enumerate(dtypes): nvrtc_kernel_str = nvrtc_kernel_str.replace("{%d}" % idx, dtype_strs[idx]) kernel_name = f'''{uuid1() if kernel_name is None else kernel_name}_{ "".join(dtype_strs).replace(" ", "_") }''' nvrtc_kernel_str = "%s\nvoid %s%s" % \ (extern_prefix, kernel_name, nvrtc_kernel_str) if logger.should_log_for(logger.LEVEL_DEBUG): logger.debug(str(nvrtc_kernel_str)) return cp.RawKernel(nvrtc_kernel_str, kernel_name)