class GenericFnType(FnType): """The type of cl.oquence GenericFn's.""" def __init__(self, generic_fn): self.generic_fn = self.constant_value = generic_fn def __repr__(self): return self.generic_fn.__name__ @cypy.memoize def _resolve_Call(self, visitor, func, args): #@UnusedVariable explicit_arg_types = tuple( visitor._resolve_type(arg.unresolved_type) for arg in args) return self.generic_fn._get_concrete_fn(explicit_arg_types).return_type cypy.interned(GenericFnType) class ConcreteFnType(FnType): """The type of cl.oquence ConcreteFn's.""" def __init__(self, concrete_fn): self.concrete_fn = self.constant_value = concrete_fn def __repr__(self): return self.concrete_fn.full_name @cypy.memoize def _resolve_Call(self, visitor, func, args): #@UnusedVariable concrete_fn = self.concrete_fn explicit_arg_types = concrete_fn.explicit_arg_types arg_types = tuple(
name = None """The name of the item, if it has a name, or None.""" source = None """The OpenCL source code associated with this item.""" class ExtensionItem(ProgramItem): """Represents an extension.""" def __init__(self, extension): self.extension = extension @cypy.lazy(property) def source(self): return self.extension.pragma_str cypy.interned(ExtensionItem) _cl_khr_fp64_item = ExtensionItem(cl.cl_khr_fp64) _cl_khr_fp16_item = ExtensionItem(cl.cl_khr_fp16) _cl_khr_byte_addressable_store = ExtensionItem(cl.cl_khr_byte_addressable_store) class ProgramItemVisitor(_ast.NodeVisitor): """Visits an annotated ast to produce program items and metadata.""" def __init__(self, generic_fn, explicit_arg_names, explicit_arg_types, constants): self.generic_fn = generic_fn self.explicit_arg_names = explicit_arg_names self.explicit_arg_types = explicit_arg_types self.explicit_arg_map = cypy.frozendict(zip(explicit_arg_names, explicit_arg_types)) self.constants = constants
pass class GenericFnType(FnType): """The type of cl.oquence GenericFn's.""" def __init__(self, generic_fn): self.generic_fn = self.constant_value = generic_fn def __repr__(self): return self.generic_fn.__name__ @cypy.memoize def _resolve_Call(self, visitor, func, args): #@UnusedVariable explicit_arg_types = tuple(visitor._resolve_type(arg.unresolved_type) for arg in args) return self.generic_fn._get_concrete_fn(explicit_arg_types).return_type cypy.interned(GenericFnType) class ConcreteFnType(FnType): """The type of cl.oquence ConcreteFn's.""" def __init__(self, concrete_fn): self.concrete_fn = self.constant_value = concrete_fn def __repr__(self): return self.concrete_fn.full_name @cypy.memoize def _resolve_Call(self, visitor, func, args): #@UnusedVariable concrete_fn = self.concrete_fn explicit_arg_types = concrete_fn.explicit_arg_types arg_types = tuple(visitor._resolve_type(arg.unresolved_type) for arg in args)
constants[arg_name] = constant_value def _filter_args(self, args, concrete_fn): # filter out actual arguments if that argument has become a constant constants = concrete_fn.constants for arg_name, arg in zip(self.explicit_arg_names, args): if not constants.has_key(arg_name): yield arg ########################################################################## # Type ########################################################################## @cypy.lazy(property) def cl_type(self): return _type_inference.GenericFnType(self) cypy.interned(GenericFn) class ConcreteFn(object): """A concrete function consists of a generic function bound to concrete argument types and constant bindings. From a ConcreteFn, an OpenCL program is born. Do not initialize directly, use :meth:`GenericFn.get_concrete_fn` or :meth:`GenericFn.get_concrete_fn_for`. """ def __init__(self, visitor): self._visitor = visitor @cypy.lazy(property) def generic_fn(self):
source = None """The OpenCL source code associated with this item.""" class ExtensionItem(ProgramItem): """Represents an extension.""" def __init__(self, extension): self.extension = extension @cypy.lazy(property) def source(self): return self.extension.pragma_str cypy.interned(ExtensionItem) _cl_khr_fp64_item = ExtensionItem(cl.cl_khr_fp64) _cl_khr_fp16_item = ExtensionItem(cl.cl_khr_fp16) _cl_khr_byte_addressable_store = ExtensionItem( cl.cl_khr_byte_addressable_store) class ProgramItemVisitor(_ast.NodeVisitor): """Visits an annotated ast to produce program items and metadata.""" def __init__(self, generic_fn, explicit_arg_names, explicit_arg_types, constants): self.generic_fn = generic_fn self.explicit_arg_names = explicit_arg_names self.explicit_arg_types = explicit_arg_types self.explicit_arg_map = cypy.frozendict(
def _filter_args(self, args, concrete_fn): # filter out actual arguments if that argument has become a constant constants = concrete_fn.constants for arg_name, arg in zip(self.explicit_arg_names, args): if not constants.has_key(arg_name): yield arg ########################################################################## # Type ########################################################################## @cypy.lazy(property) def cl_type(self): return _type_inference.GenericFnType(self) cypy.interned(GenericFn) class ConcreteFn(object): """A concrete function consists of a generic function bound to concrete argument types and constant bindings. From a ConcreteFn, an OpenCL program is born. Do not initialize directly, use :meth:`GenericFn.get_concrete_fn` or :meth:`GenericFn.get_concrete_fn_for`. """ def __init__(self, visitor): self._visitor = visitor @cypy.lazy(property)