Example #1
0
 def execute(self, idata, odata):
     # TODO: Work out how to integrate CUDA stream
     _check(
         _bf.bfFirExecute(self.obj,
                          asarray(idata).as_BFarray(),
                          asarray(odata).as_BFarray()))
     return odata
Example #2
0
 def matmul(self, alpha, a, b, beta, c):
     """Computes:
       c = alpha*a.b + beta*c
     or if b is None:
       c = alpha*a.a^H + beta*c
     or if a is None:
       c = alpha*b^H.b + beta*c
     where '.' is matrix product and '^H' is Hermitian transpose.
     Multi-dimensional semantics are the same as numpy.matmul:
       The last two dims represent the matrix, and all other dims are
       used as batch dims to be matched or broadcast between a and b.
     """
     if alpha is None:
         alpha = 1.
     if beta is None:
         beta = 0.
     beta  = float(beta)
     alpha = float(alpha)
     a_array = asarray(a).as_BFarray() if a is not None else None
     b_array = asarray(b).as_BFarray() if b is not None else None
     c_array = asarray(c).as_BFarray()
     _check(_bf.bfLinAlgMatMul(self.obj,
                               alpha,
                               a_array,
                               b_array,
                               beta,
                               c_array))
     return c
Example #3
0
 def init(self, coeffs, decim=1, space='cuda'):
     space = _string2space(space)
     psize = None
     _check(
         _bf.bfFirInit(self.obj,
                       asarray(coeffs).as_BFarray(), decim, space, 0,
                       psize))
Example #4
0
def reduce(idata, odata, op='sum'):
    if op not in REDUCE_MAP:
        raise ValueError("Invalid reduce op: " + str(op))
    op = REDUCE_MAP[op]
    _check(_bf.bfReduce(asarray(idata).as_BFarray(),
                        asarray(odata).as_BFarray(),
                        op))
Example #5
0
def set_devices_no_spin_cpu():
    """Sets a flag on all GPU devices that tells them not to spin the CPU when
    synchronizing. This is useful for reducing CPU load in GPU pipelines.

    This function must be called _before_ any GPU devices are
    initialized (i.e., at the start of the process)."""
    _check(_bf.bfDevicesSetNoSpinCPU())
Example #6
0
 def __init__(self,
              ring,
              size,
              nonblocking=False):
     SpanBase.__init__(self, ring, writeable=True)
     self.obj = _bf.BFwspan()
     _check(_bf.bfRingSpanReserve(self.obj, ring.obj, size, nonblocking))
     self.commit_size = size
Example #7
0
 def resize(self, contiguous_span, total_span=None, nringlet=1,
            buffer_factor=4):
     if total_span is None:
         total_span = contiguous_span * buffer_factor
     _check( _bf.bfRingResize(self.obj,
                              contiguous_span,
                              total_span,
                              nringlet) )
Example #8
0
def transpose(dst, src, axes=None):
    if axes is None:
        axes = reversed(range(len(dst.shape)))
    dst_bf = asarray(dst).as_BFarray()
    src_bf = asarray(src).as_BFarray()
    array_type = ctypes.c_int * src.ndim
    axes_array = array_type(*axes)
    _check(_bf.Transpose(src_bf, dst_bf, axes_array))
Example #9
0
    def update(self, contents):
        if isinstance(contents, dict):
            """Updates (replaces) the contents of the log
			contents: string or dict containing data to write to the log
			"""
            contents = '\n'.join(
                ['%s : %s' % item for item in contents.items()])
        _check(_bf.ProcLogUpdate(self.obj, contents))
Example #10
0
def memset2D(dst, val=0):
    assert (len(dst.shape) == 2)
    space = _string2space(_get_space(dst))
    height, width = dst.shape
    width_bytes = width * dst.dtype.itemsize
    _check(
        _bf.bfMemset2D(dst.ctypes.data, dst.strides[0], space, val,
                       width_bytes, height))
Example #11
0
 def __init__(self, ring, sequence, nframe, nonblocking=False):
     SpanBase.__init__(self, ring, sequence, writeable=True)
     nbyte = nframe * self._sequence.tensor['frame_nbyte']
     self.obj = _bf.BFwspan()
     _check(_bf.bfRingSpanReserve(self.obj, ring.obj, nbyte, nonblocking))
     self._set_base_obj(self.obj)
     # Note: We default to 0 instead of nframe so that we don't accidentally
     #         commit bogus data if a block throws an exception.
     self.commit_nframe = 0
Example #12
0
def set_openmp_cores(cores):
    # PYCLIBRARY ISSUE
    # TODO: Would be really nice to be able to directly pass
    #         a list here instead of needing to specify _array+type.
    #         Should be able to do it safely for any const* argument
    #         Note that the base type of the pointer type could be
    #           derived via a reverse lookup table.
    #           E.g., Inverse of POINTER(c_int)-->LP_c_int
    _check(_bf.bfAffinitySetOpenMPCores(len(cores), _array(cores, 'int')))
Example #13
0
	def execute(self, idata, odata, negative_delays=False):
		# TODO: Work out how to integrate CUDA stream
		psize = None
		_check( _bf.FdmtExecute(self.obj,
		                        asarray(idata).as_BFarray(),
		                        asarray(odata).as_BFarray(),
		                        negative_delays,
		                        0, psize) )
		return odata
Example #14
0
def memcpy(dst, src):
    assert (dst.flags['C_CONTIGUOUS'])
    assert (src.shape == dst.shape)
    dst_space = _string2space(_get_space(dst))
    src_space = _string2space(_get_space(src))
    count = dst.nbytes
    _check(
        _bf.bfMemcpy(dst.ctypes.data, dst_space, src.ctypes.data, src_space,
                     count))
    return dst
Example #15
0
 def update(self, contents):
     """Updates (replaces) the contents of the log
     contents: string or dict containing data to write to the log
     """
     if contents is None:
         raise ValueError("Contents cannot be None")
     if isinstance(contents, dict):
         contents = '\n'.join(
             ['%s : %s' % item for item in contents.items()])
     _check(_bf.bfProcLogUpdate(self.obj, contents))
Example #16
0
 def __init__(self, sequence, frame_offset, nframe):
     SpanBase.__init__(self, sequence.ring, sequence, writeable=False)
     tensor = sequence.tensor
     self.obj = _bf.BFrspan()
     _check(
         _bf.bfRingSpanAcquire(self.obj, sequence.obj,
                               frame_offset * tensor['frame_nbyte'],
                               nframe * tensor['frame_nbyte']))
     self._set_base_obj(self.obj)
     self.nframe_skipped = min(self.frame_offset - frame_offset, nframe)
     self.requested_frame_offset = frame_offset
Example #17
0
def memcpy2D(dst, src):
    assert (len(dst.shape) == 2)
    assert (src.shape == dst.shape)
    dst_space = _string2space(_get_space(dst))
    src_space = _string2space(_get_space(src))
    height, width = dst.shape
    width_bytes = width * dst.dtype.itemsize
    _check(
        _bf.bfMemcpy2D(dst.ctypes.data, dst.strides[0], dst_space,
                       src.ctypes.data, src.strides[0], src_space, width_bytes,
                       height))
Example #18
0
 def execute_workspace(self,
                       iarray,
                       oarray,
                       workspace_ptr,
                       workspace_size,
                       inverse=False):
     _check(
         _bf.bfFftExecute(self.obj,
                          asarray(iarray).as_BFarray(),
                          asarray(oarray).as_BFarray(), inverse,
                          workspace_ptr, workspace_size))
     return oarray
Example #19
0
 def execute_workspace(self,
                       idata,
                       odata,
                       workspace_ptr,
                       workspace_size,
                       negative_delays=False):
     size = _bf.BFsize(workspace_size)
     _check(
         _bf.bfFdmtExecute(self.obj,
                           asarray(idata).as_BFarray(),
                           asarray(odata).as_BFarray(), negative_delays,
                           workspace_ptr, size))
     return odata
Example #20
0
 def __init__(self,
              ring,
              which='specific',
              name="",
              time_tag=None,
              other_obj=None,
              guarantee=True,
              header_transform=None):
     SequenceBase.__init__(self, ring)
     self._ring = ring
     # A function for transforming the header before it's read
     self.header_transform = header_transform
     self.obj = _bf.BFrsequence()
     if which == 'specific':
         _check(_bf.bfRingSequenceOpen(self.obj, ring.obj, name, guarantee))
     elif which == 'at':
         assert (time_tag is not None)
         _check(
             _bf.bfRingSequenceOpenAt(self.obj, ring.obj, time_tag,
                                      guarantee))
     elif which == 'latest':
         _check(_bf.bfRingSequenceOpenLatest(self.obj, ring.obj, guarantee))
     elif which == 'earliest':
         _check(
             _bf.bfRingSequenceOpenEarliest(self.obj, ring.obj, guarantee))
     else:
         raise ValueError(
             "Invalid 'which' parameter; must be one of: 'specific', 'latest', 'earliest'"
         )
Example #21
0
 def __init__(self, space='system', name=None, core=None):
     if name is None:
         name = str(uuid4())
     name = _slugify(name)
     space = _string2space(space)
     #self.obj = None
     #self.obj = _get(_bf.bfRingCreate(name=name, space=space), retarg=0)
     BifrostObject.__init__(
         self, _bf.bfRingCreate, _bf.bfRingDestroy, name, space)
     if core is not None:
         try:
             _check( _bf.bfRingSetAffinity(self.obj, 
                                           core) )
         except RuntimeError:
             pass
Example #22
0
 def __init__(self, space='system', name=None, owner=None, core=None):
     # If this is non-None, then the object is wrapping a base Ring instance
     self.base = None
     self.space = space
     if name is None:
         name = 'ring_%i' % Ring.instance_count
         Ring.instance_count += 1
     name = _slugify(name)
     BifrostObject.__init__(self, _bf.bfRingCreate, _bf.bfRingDestroy, name,
                            _string2space(self.space))
     if core is not None:
         try:
             _check(_bf.bfRingSetAffinity(self.obj, core))
         except RuntimeError:
             pass
     self.owner = owner
     self.header_transform = None
Example #23
0
 def __init__(self, ring, name="", time_tag=-1, header="", nringlet=1):
     SequenceBase.__init__(self, ring)
     # TODO: Allow header to be a string, buffer, or numpy array
     header_size = len(header)
     if isinstance(header, np.ndarray):
         header = header.ctypes.data
     #print "hdr:", header_size, type(header)
     name = str(name)
     offset_from_head = 0
     self.obj = _bf.BFwsequence()
     _check(_bf.bfRingSequenceBegin(
         self.obj,
         ring.obj,
         name,
         time_tag,
         header_size,
         header,
         nringlet,
         offset_from_head))
Example #24
0
 def __init__(self, ring, header, gulp_nframe, buf_nframe):
     SequenceBase.__init__(self, ring)
     self._header = header
     # This allows passing DataType instances instead of string types
     header['_tensor']['dtype'] = str(header['_tensor']['dtype'])
     header_str = json.dumps(header)
     header_size = len(header_str)
     tensor = self.tensor
     # **TODO: Consider moving this into bfRingSequenceBegin
     self.ring.resize(gulp_nframe * tensor['frame_nbyte'],
                      buf_nframe * tensor['frame_nbyte'],
                      tensor['nringlet'])
     offset_from_head = 0
     # TODO: How to allow time_tag to be optional? Probably need to plumb support through to backend.
     self.obj = _bf.BFwsequence()
     _check(
         _bf.bfRingSequenceBegin(self.obj, ring.obj, header['name'],
                                 header['time_tag'], header_size,
                                 header_str, tensor['nringlet'],
                                 offset_from_head))
Example #25
0
 def __init__(self, ring, which='specific', name="", time_tag=None,
              other_obj=None, guarantee=True):
     SequenceBase.__init__(self, ring)
     self._ring = ring
     self.obj = _bf.BFrsequence()
     if which == 'specific':
         _check(_bf.bfRingSequenceOpen(self.obj, ring.obj, name, guarantee))
     elif which == 'latest':
         _check(_bf.bfRingSequenceOpenLatest(self.obj, ring.obj, guarantee))
     elif which == 'earliest':
         _check(_bf.bfRingSequenceOpenEarliest(self.obj, ring.obj, guarantee))
     elif which == 'at':
         _check(_bf.bfRingSequenceOpenAt(self.obj, ring.obj, time_tag, guarantee))
     #elif which == 'next':
     #    self._check( self.lib.bfRingSequenceOpenNext(pointer(self.obj), other_obj) )
     else:
         raise ValueError("Invalid 'which' parameter; must be one of: 'specific', 'latest', 'earliest'")
Example #26
0
	def init(self, nchan, max_delay, f0, df, exponent=-2.0, space='cuda'):
		space = _string2space(space)
		psize = None
		_check( _bf.FdmtInit(self.obj, nchan, max_delay, f0, df, exponent, space, 0, psize) )
Example #27
0
def set_core(core):
    _check(_bf.bfAffinitySetCore(core))
Example #28
0
 def address(self):
     buflen = 128
     buf = ctypes.create_string_buffer(buflen)
     _check(_bf.bfAddressGetString(self.obj, buflen, buf))
     return buf.value
Example #29
0
 def end_writing(self):
     _check( _bf.bfRingEndWriting(self.obj) )
Example #30
0
 def _begin_writing(self):
     _check( _bf.bfRingBeginWriting(self.obj) )