Skip to content

Commit

Permalink
Merge 36b42a4 into 5cdaa03
Browse files Browse the repository at this point in the history
  • Loading branch information
jaycedowell committed Jul 21, 2020
2 parents 5cdaa03 + 36b42a4 commit 87cec65
Show file tree
Hide file tree
Showing 91 changed files with 869 additions and 481 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ language: python

python:
- 2.7
- 3.6
# PyPy versions
- pypy2.7-6.0
- pypy3

services:
- docker
Expand All @@ -28,6 +30,7 @@ jobs:
python: 2.7
script:
- make docker-cpu
- make docker
- bash ./.travis_deploy_docs.sh

script:
Expand All @@ -39,7 +42,7 @@ script:
simplejson \
pint \
graphviz \
git+https://github.com/davidjamesca/ctypesgen.git@3d2d9803339503d2988382aa861b47a6a4872c32 \
git+https://github.com/olsonse/ctypesgen.git@9bd2d249aa4011c6383a10890ec6f203d7b7990f \
coveralls \
codecov
- sudo make -j NOCUDA=1
Expand Down
7 changes: 7 additions & 0 deletions Dockerfile.cpu
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Update ctypesgen
RUN curl -fSsL -O https://bootstrap.pypa.io/get-pip.py && \
python get-pip.py && \
rm get-pip.py
RUN pip --no-cache-dir install \
git+https://github.com/olsonse/ctypesgen.git@9bd2d249aa4011c6383a10890ec6f203d7b7990f

# Build the library
WORKDIR /bifrost
COPY . .
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile.gpu
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM nvidia/cuda:8.0
FROM nvidia/cuda:10.2-devel-ubuntu18.04

MAINTAINER Ben Barsdell <benbarsdell@gmail.com>

Expand Down Expand Up @@ -32,7 +32,7 @@ RUN pip --no-cache-dir install \
contextlib2 \
simplejson \
pint \
git+https://github.com/davidjamesca/ctypesgen.git@3d2d9803339503d2988382aa861b47a6a4872c32 \
git+https://github.com/olsonse/ctypesgen.git@9bd2d249aa4011c6383a10890ec6f203d7b7990f \
graphviz

ENV TERM xterm
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile_prereq.gpu
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM nvidia/cuda:8.0
FROM nvidia/cuda:10.2-devel-ubuntu18.04

MAINTAINER Ben Barsdell <benbarsdell@gmail.com>

Expand Down Expand Up @@ -31,7 +31,7 @@ RUN pip --no-cache-dir install \
contextlib2 \
simplejson \
pint \
git+https://github.com/davidjamesca/ctypesgen.git@3d2d9803339503d2988382aa861b47a6a4872c32 \
git+https://github.com/olsonse/ctypesgen.git@9bd2d249aa4011c6383a10890ec6f203d7b7990f \
graphviz

ENV TERM xterm
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ print "All done"
* ctypesgen

```
$ sudo pip install numpy contextlib2 pint git+https://github.com/davidjamesca/ctypesgen.git@3d2d9803339503d2988382aa861b47a6a4872c32
$ sudo pip install numpy contextlib2 pint git+https://github.com/olsonse/ctypesgen.git@9bd2d249aa4011c6383a10890ec6f203d7b7990f
```

### Bifrost installation
Expand Down
2 changes: 1 addition & 1 deletion config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ endif
BIFROST_NAME = bifrost
LIBBIFROST_NAME = lib$(BIFROST_NAME)
LIBBIFROST_MAJOR = 0
LIBBIFROST_MINOR = 8
LIBBIFROST_MINOR = 9
LIBBIFROST_PATCH = 0
LIBBIFROST_SO = $(LIBBIFROST_NAME)$(SO_EXT)
LIBBIFROST_SO_MAJ = $(LIBBIFROST_SO).$(LIBBIFROST_MAJOR)
Expand Down
2 changes: 1 addition & 1 deletion docs/source/Getting-started-guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ numpy, matplotlib, contextlib2, simplejson, pint, graphviz, ctypesgen
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

If you have already installed pip, this step should be as simple as
``pip install --user numpy matplotlib contextlib2 simplejson pint graphviz git+https://github.com/davidjamesca/ctypesgen.git@3d2d9803339503d2988382aa861b47a6a4872c32``.
``pip install --user numpy matplotlib contextlib2 simplejson pint graphviz git+https://github.com/olsonse/ctypesgen.git@9bd2d249aa4011c6383a10890ec6f203d7b7990f``.

C++ dependencies
~~~~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion python/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ $(BIFROST_PYTHON_VERSION_FILE): ../config.mk
@echo "__version__ = \"$(LIBBIFROST_MAJOR).$(LIBBIFROST_MINOR).$(LIBBIFROST_PATCH)\"" > $@

define run_ctypesgen
ctypesgen.py -l$1 -I$2 $^ -o $@
python -c 'from ctypesgen import main as ctypeswrap; ctypeswrap.main()' -l$1 -I$2 $^ -o $@
# WAR for 'const char**' being generated as POINTER(POINTER(c_char)) instead of POINTER(c_char_p)
sed -i 's/POINTER(c_char)/c_char_p/g' $@
# WAR for a buggy WAR in ctypesgen that breaks type checking and auto-byref functionality
Expand Down
22 changes: 15 additions & 7 deletions python/bifrost/DataType.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

# Copyright (c) 2016, The Bifrost Authors. All rights reserved.
# Copyright (c) 2016-2020, The Bifrost Authors. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -38,7 +38,15 @@
cf32: 32+32-bit complex floating point
"""

from libbifrost import _bf
# Python2 compatibility
from __future__ import division, absolute_import
import sys
string_types = (str,)
if sys.version_info < (3,):
range = xrange
string_types = (basestring,)

from bifrost.libbifrost import _bf
import numpy as np

# Custom dtypes to represent additional complex types
Expand Down Expand Up @@ -100,15 +108,15 @@ def is_vector_structure(dtype):
if dtype.names is None:
return False
ndim = len(dtype.names)
vector_field_names = tuple('f%i' % i for i in xrange(ndim))
vector_field_names = tuple('f%i' % i for i in range(ndim))
return (dtype.kind == 'V' and
dtype.names == vector_field_names and
all([dtype[i] == dtype[0] for i in xrange(1, ndim)]))
all([dtype[i] == dtype[0] for i in range(1, ndim)]))

class DataType(object):
# Note: Default of None results in default Numpy type (np.float)
def __init__(self, t=None):
if isinstance(t, basestring):
if isinstance(t, string_types):
for i, char in enumerate(t):
if char.isdigit():
break
Expand Down Expand Up @@ -148,10 +156,10 @@ def __init__(self, t=None):
t = t[0]
self._kind = t.kind
if t.kind == 'c':
self._nbit /= 2 # Bifrost convention is nbit per real component
self._nbit //= 2 # Bifrost convention is nbit per real component
self._kind = 'cf' # Numpy only supports floating-point complex types
elif t.kind == 'V': # WAR to support custom integer complex types
self._nbit /= 2
self._nbit //= 2
if t in [ci4, ci8, ci16, ci32, ci64]:
self._kind = 'ci'
elif t in [cf16]:
Expand Down
7 changes: 3 additions & 4 deletions python/bifrost/GPUArray.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@

import ctypes
import numpy as np
from memory import raw_malloc, raw_free, memset, memcpy, memcpy2D
from libbifrost import _check, _string2space
from bifrost.libbifrost import _bf
from array import _array2bifrost
from bifrost.memory import raw_malloc, raw_free, memset, memcpy, memcpy2D
from bifrost.libbifrost import _bf, _check, _string2space
from bifrost.array import _array2bifrost # This doesn't exist!

class GPUArray(object):
def __init__(self, shape, dtype, buffer=None, offset=0, strides=None):
Expand Down
4 changes: 2 additions & 2 deletions python/bifrost/Space.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

# Copyright (c) 2016, The Bifrost Authors. All rights reserved.
# Copyright (c) 2016-2020, The Bifrost Authors. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -41,7 +41,7 @@

class Space(object):
def __init__(self, s):
if isinstance(s, basestring):
if isinstance(s, str):
if s not in set(['auto', 'system',
'cuda', 'cuda_host', 'cuda_managed']):
raise ValueError('Invalid space: %s' % s)
Expand Down
39 changes: 21 additions & 18 deletions python/bifrost/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,33 @@
"""

# TODO: Decide how to organise the namespace
import core, memory, affinity, ring, block, address, udp_socket
import pipeline
import device
from ndarray import ndarray, asarray, empty_like, empty, zeros_like, zeros
import views
from map import map
from pipeline import Pipeline, get_default_pipeline, block_scope
import blocks
from block_chainer import BlockChainer
from reduce import reduce

from __future__ import print_function, absolute_import

from bifrost import core, memory, affinity, ring, block, address, udp_socket
from bifrost import pipeline
from bifrost import device
from bifrost.ndarray import ndarray, asarray, empty_like, empty, zeros_like, zeros
from bifrost import views
from bifrost.map import map
from bifrost.pipeline import Pipeline, get_default_pipeline, block_scope
from bifrost import blocks
from bifrost.block_chainer import BlockChainer
from bifrost.reduce import reduce
# import copy_block, transpose_block, scrunch_block, sigproc_block, fdmt_block
# from transpose import transpose
# from unpack import unpack
# from quantize import quantize
# from bifrost.transpose import transpose
# from bifrost.unpack import unpack
# from bifrost.quantize import quantize

try:
from .version import __version__
from bifrost.version import __version__
except ImportError:
print "*************************************************************************"
print "Please run `make` from the root of the source tree to generate version.py"
print "*************************************************************************"
print("*************************************************************************")
print("Please run `make` from the root of the source tree to generate version.py")
print("*************************************************************************")
raise
__author__ = "The Bifrost Authors"
__copyright__ = "Copyright (c) 2016, The Bifrost Authors. All rights reserved.\nCopyright (c) 2016, NVIDIA CORPORATION. All rights reserved."
__copyright__ = "Copyright (c) 2016-2020, The Bifrost Authors. All rights reserved.\nCopyright (c) 2016, NVIDIA CORPORATION. All rights reserved."
__credits__ = ["Ben Barsdell"]
__license__ = "BSD 3-Clause"
__maintainer__ = "Ben Barsdell"
Expand Down
12 changes: 7 additions & 5 deletions python/bifrost/addon/leda/bandfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from __future__ import print_function

import os, sys

sys.path.append('..')
Expand Down Expand Up @@ -83,12 +85,12 @@ def __init__(self, fname):
obs1 = extract_obs_offset_from_name(fname)
obs2 = extract_obs_offset_in_file(fname)
if obs1 != obs2 and obs1 != "UNKNOWN" and obs2 !="UNKNOWN":
print "Consistency Error", fname, ": OBS_OFFSET in file doesn't match the offset in the name"
print("Consistency Error", fname, ": OBS_OFFSET in file doesn't match the offset in the name")
"""

if hedr["SOURCE"] == "LEDA_TEST":
if not is_integer(n_scans): print "CONSISTENCY ERROR, ", fname, "scan:",n_scans, "is not integer"
if not is_integer((self.end_time-self.start_time)/9.0): print "CONSISTENCY ERROR", fname, ": not 9 sec dump in file"
if not is_integer(n_scans): print("CONSISTENCY ERROR, ", fname, "scan:",n_scans, "is not integer")
if not is_integer((self.end_time-self.start_time)/9.0): print("CONSISTENCY ERROR", fname, ": not 9 sec dump in file")

# Gather the file info for all files that have different frequency but the same observation time.
class BandFiles(object):
Expand All @@ -106,7 +108,7 @@ def __init__(self, basename):
if basename[-5:] == ".dada": # Just a single file
if os.access(basename,os.R_OK): self.files.append(FileInfo(basename))
else: "Error:", basename, "does not exist or is not readable"
print basename, FileInfo(basename), self.files
print(basename, FileInfo(basename), self.files)
else:

# Look for files in all the standard locations
Expand Down Expand Up @@ -138,7 +140,7 @@ def __init__(self, basename):
if f.start_time not in self.start_time_present: self.start_time_present.append(f.start_time)

if len(self.start_time_present) > 1:
print "Error: Files with same timestamp in their name have different internal time. Basename:",basename
print("Error: Files with same timestamp in their name have different internal time. Basename:",basename)
#sys.exit(1)

self.start_time = self.start_time_present[0]
Expand Down
23 changes: 15 additions & 8 deletions python/bifrost/addon/leda/blocks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright (c) 2016, The Bifrost Authors. All rights reserved.

# Copyright (c) 2016-2020, The Bifrost Authors. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -28,6 +29,12 @@
This file contains blocks specific to LEDA-OVRO.
"""

# Python2 compatibility
from __future__ import print_function
import sys
if sys.version_info < (3,):
range = xrange

import os
import bandfiles
import bifrost
Expand Down Expand Up @@ -75,10 +82,10 @@ def __init__(self, time_stamp, core=-1, gulp_nframe=4096):
i += 1

# Report what we've got
print "Num files in time:", len(beamformer_scans)
print "File and number:"
print("Num files in time:", len(beamformer_scans))
print("File and number:")
for scan in beamformer_scans:
print os.path.basename(scan.files[0].name)+":", len(scan.files)
print(os.path.basename(scan.files[0].name)+":", len(scan.files))

self.beamformer_scans = beamformer_scans # List of full-band time steps

Expand All @@ -100,7 +107,7 @@ def main(self, input_rings, output_rings):
ohdr["tsamp"] = self.SAMPLING_RATE
ohdr['foff'] = self.CHANNEL_WIDTH

#print length_one_second, ring_span_size, file_chunk_size, number_of_chunks
#print(length_one_second, ring_span_size, file_chunk_size, number_of_chunks)

with self.oring.begin_writing() as oring:

Expand All @@ -109,7 +116,7 @@ def main(self, input_rings, output_rings):
# Go through the frequencies
for f in scan.files:

print "Opening", f.name
print("Opening", f.name)

with open(f.name,'rb') as ifile:
ifile.read(self.HEADER_SIZE)
Expand All @@ -126,10 +133,10 @@ def main(self, input_rings, output_rings):
try:
data = np.fromfile(ifile, count=file_chunk_size, dtype=np.int8).astype(np.float32)
except:
print "Bad read. Stopping read."
print("Bad read. Stopping read.")
return
if data.size != length_one_second*self.N_BEAM*self.N_CHAN*2:
print "Bad data shape. Stopping read."
print("Bad data shape. Stopping read.")
return
data = data.reshape(length_one_second, self.N_BEAM, self.N_CHAN, 2)
power = (data[...,0]**2 + data[...,1]**2).mean(axis=1) # Now have time by frequency.
Expand Down
Loading

0 comments on commit 87cec65

Please sign in to comment.