Пример #1
0
                        '--out_dir',
                        type=str,
                        required=False,
                        default=None,
                        help='Path of directory for generated library')
    parser.add_argument('-st',
                        '--static',
                        required=False,
                        default=False,
                        action='store_true',
                        help='If specified, the generated library will be'
                        'a static library (required for CUDA).')
    parser.add_argument('-bt',
                        '--build_type',
                        required=False,
                        type=utils.EnumType(build_type),
                        default='jacobian',
                        help='The type of library to build: {type}'.format(
                            type=str(utils.EnumType(build_type))))
    parser.add_argument(
        '-e',
        '--executable',
        required=False,
        default=False,
        action='store_true',
        help='If supplied, convert the generated library to an '
        'executable shared library (cannot be supplied w/ '
        '--static switch)')

    args = parser.parse_args()
    generate_library(args.lang, args.source_dir, args.obj_dir, args.out_dir,
Пример #2
0
        description='Generates a python wrapper for pyJac via Cython')
    parser.add_argument('-l',
                        '--lang',
                        type=str,
                        choices=utils.langs,
                        required=True,
                        help='Programming language for output '
                        'source files')
    parser.add_argument('-so',
                        '--source_dir',
                        type=str,
                        required=True,
                        help='The folder that contains the generated pyJac '
                        'files.')
    parser.add_argument('-out',
                        '--out_dir',
                        type=str,
                        required=False,
                        default=None,
                        help='The folder to place the generated library in')
    parser.add_argument('-kt',
                        '--kernel_type',
                        required=False,
                        type=utils.EnumType(KernelType),
                        default='jacobian',
                        help='The type of library to build: {type}'.format(
                            type=str(utils.EnumType(KernelType))))

    args = parser.parse_args()
    pywrap(args.lang, args.source_dir, args.out_dir, ktype=args.kernel_type)
Пример #3
0
    def get_limits(loopy_opts,
                   arrays,
                   input_file='',
                   string_strides=[p_size.name],
                   dtype=np.int32,
                   limit_int_overflow=False):
        """
        Utility method to load shared / constant memory limits from a file or
        :mod:`pyopencl` as needed

        Parameters
        ----------
        loopy_opts: :class:`loopy_options`
            If loopy_opts.lang == 'opencl', pyopencl will be used to fill in any
            missing limits
        arrays: dict
            A mapping of :class:`memory_type` to :class:`loopy.TemporaryVariable` or
            :class:`loopy.GlobalArg`, representing the types of all arrays to be
            included
        input_file: str
            The path to a yaml file with specified limits (keys should include
            'local' and 'constant', and 'global')
        string_strides: str
            The strides of host & device buffers dependent on user input
            Need special handling in size determination
        dtype: np.dtype [np.int32]
            The index type of the kernel to be generated. Default is a 32-bit int
        limit_int_overflow: bool [False]
            If true, turn on limiting array sizes to avoid integer overflow.
            Currently only needed for Intel OpenCL

        Returns
        -------
        limits: :class:`memory_limits`
            An initialized :class:`memory_limits` that can determine the total
            'global', 'constant' and 'local' memory available on the device
        """

        limits = {}  # {memory_type.m_pagesize: align_size}
        if loopy_opts.lang == 'opencl':
            try:
                limits.update({
                    memory_type.m_global:
                    loopy_opts.device.global_mem_size,
                    memory_type.m_constant:
                    loopy_opts.device.max_constant_buffer_size,
                    memory_type.m_local:
                    loopy_opts.device.local_mem_size,
                    memory_type.m_alloc:
                    loopy_opts.device.max_mem_alloc_size
                })
            except AttributeError:
                pass
        user = load_memory_limits(input_file)
        # find limit(s) that applies to us
        user = [
            u for u in user if 'platforms' not in u
            or loopy_opts.platform_name.lower() in u['platforms']
        ]
        if len(user) > 1:
            # check that we don't have multiple limits with this platforms specified
            if len([u for u in user if 'platforms' in u]) > 1 or len(
                [u for u in user if 'platforms' not in u]) > 1:
                logger = logging.getLogger(__name__)
                logger.error(
                    'Multiple memory-limits supplied by name in file ({}) '
                    'for platform {}.  Valid configurations are either one '
                    'default memory-limits specification for all platforms '
                    'with specific overrides for a platform, or a '
                    'platform-specific memory-limits only.'.format(
                        input_file, loopy_opts.platform_name))
                raise InvalidInputSpecificationException('memory-limits')
            assert len(user) <= 2

        if user:
            logger = logging.getLogger(__name__)
            for lim in sorted(user, key=lambda x: 'platforms' in x):
                # load from file
                mtype = utils.EnumType(memory_type)
                user_limits = {}
                for key, value in six.iteritems(lim):
                    if key == 'platforms':
                        continue
                    # check in memory type
                    key = 'm_' + key
                    # update with enum
                    logger.debug(
                        'Overriding memory-limit for type {} from value '
                        '({}) to value ({}) from {} limits.'.format(
                            key, limits[mtype(key)] if mtype(key) in limits
                            else None, value, 'per-platform'
                            if 'platforms' in lim else 'default'))
                    user_limits[mtype(key)] = value
                # and overwrite default limits w/ user
                limits.update(user_limits)

        return memory_limits(loopy_opts.lang, loopy_opts.order, arrays, limits,
                             string_strides, dtype, limit_int_overflow)