Learn more  » Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Bower components Debian packages RPM packages NuGet packages

edgify / pycuda   python

Repository URL to install this package:

Version: 2020.1 

/ characterize.py

from __future__ import division
from __future__ import absolute_import

from pycuda.tools import context_dependent_memoize
import numpy as np


def platform_bits():
    import sys
    if sys.maxsize > 2**32:
        return 64
    else:
        return 32


def has_stack():
    from pycuda.driver import Context
    return Context.get_device().compute_capability() >= (2, 0)


def has_double_support():
    from pycuda.driver import Context
    return Context.get_device().compute_capability() >= (1, 3)


@context_dependent_memoize
def sizeof(type_name, preamble=""):
    from pycuda.compiler import SourceModule
    mod = SourceModule("""
    %s
    extern "C"
    __global__ void write_size(size_t *output)
    {
      *output = sizeof(%s);
    }
    """ % (preamble, type_name), no_extern_c=True)

    import pycuda.gpuarray as gpuarray
    output = gpuarray.empty((), dtype=np.uintp)
    mod.get_function("write_size")(output, block=(1, 1, 1), grid=(1, 1))

    return int(output.get())