Skip to content

Commit

Permalink
Worked on getting make_plugin.py to work with installed Bifrost as we…
Browse files Browse the repository at this point in the history
…ll as in the Bifrost source directory. The next thing is to clean it up so that it can be run anywhere.
  • Loading branch information
jaycedowell committed Feb 4, 2020
1 parent 3f8c452 commit 22d3074
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 11 deletions.
24 changes: 23 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,36 @@ clean:
$(MAKE) -C $(SRC_DIR) clean
.PHONY: clean
install: $(INSTALL_LIB_DIR)/$(LIBBIFROST_SO_MAJ_MIN) $(INSTALL_INC_DIR)/$(BIFROST_NAME)
install -m 644 -t $(INSTALL_INC_DIR)/$(BIFROST_NAME) config.mk user.mk
install -C -D -m 644 -t $(INSTALL_INC_DIR)/$(BIFROST_NAME)/config config.mk user.mk
install -C -m 644 -t $(INSTALL_INC_DIR) \
src/array_utils.hpp src/assert.hpp src/Complex.hpp src/cuda.hpp src/EnvVars.hpp \
src/fft_kernels.h src/int_fastdiv.h src/Jones.hpp src/linalg_kernels.h src/ObjectCache.hpp \
src/utils.hpp src/utils.hu src/Vector.hpp src/workspace.hpp src/ArrayIndexer.cuh src/IndexArray.cuh \
src/ShapeIndexer.cuh
$(MAKE) -C $(BIFROST_PYTHON_DIR) install
.PHONY: install
uninstall:
rm -f $(INSTALL_LIB_DIR)/$(LIBBIFROST_SO)
rm -f $(INSTALL_LIB_DIR)/$(LIBBIFROST_SO_MAJ)
rm -f $(INSTALL_LIB_DIR)/$(LIBBIFROST_SO_MAJ_MIN)
rm -rf $(INSTALL_INC_DIR)/bifrost/
rm -rf $(INSTALL_INC_DIR)/array_utils.hpp
rm -rf $(INSTALL_INC_DIR)/assert.hpp
rm -rf $(INSTALL_INC_DIR)/Complex.hpp
rm -rf $(INSTALL_INC_DIR)/cuda.hpp
rm -rf $(INSTALL_INC_DIR)/EnvVars.hpp
rm -rf $(INSTALL_INC_DIR)/fft_kernels.h
rm -rf $(INSTALL_INC_DIR)/int_fastdiv.h
rm -rf $(INSTALL_INC_DIR)/Jones.hpp
rm -rf $(INSTALL_INC_DIR)/linalg_kernels.h
rm -rf $(INSTALL_INC_DIR)/ObjectCache.hpp
rm -rf $(INSTALL_INC_DIR)/utils.hpp
rm -rf $(INSTALL_INC_DIR)/utils.hu
rm -rf $(INSTALL_INC_DIR)/Vector.hpp
rm -rf $(INSTALL_INC_DIR)/workspace.hpp
rm -rf $(INSTALL_INC_DIR)/ArrayIndexer.cuh
rm -rf $(INSTALL_INC_DIR)/IndexArray.cuh
rm -rf $(INSTALL_INC_DIR)/ShapeIndexer.cuh
$(MAKE) -C $(BIFROST_PYTHON_DIR) uninstall
.PHONY: uninstall

Expand Down
41 changes: 37 additions & 4 deletions plugins/makefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,37 @@
_MAKEFILE_TEMPLATE = os.path.join(os.path.dirname(__file__), 'makefile.tmpl')


def resolve_bifrost(bifrost_path=None):
"""
Given a base path for a Bifrost installation, find all of the necessary
components for the Makefile. Returns a four-element tuple of the
configuration path, includes path, library path, and plugin scripts path.
"""

# Get the Bifrost source path, if needed
if bifrost_path is None:
bifrost_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# Setup the dependant paths
## Configuration files
bifrost_config_path = bifrost_path+'/include/bifrost/config'
if not os.path.exists(os.path.join(bifrost_config_path, 'config.mk')):
### Fallback to this being in the directory itself
bifrost_config_path = bifrost_path
## Includes
bifrost_include_path = bifrost_path+'/include'
if not os.path.exists(os.path.join(bifrost_include_path, 'bifrost', 'ring.h')):
### Fallback to this being in the src directory
bifrost_include_path = os.path.join(bifrost_path, 'src')
## Libraries
bifrost_library_path = bifrost_path+'/lib'
## Plugin scripts
bifrost_script_path = os.path.dirname(os.path.abspath(__file__))

# Done
return bifrost_config_path, bifrost_include_path, bifrost_library_path, bifrost_script_path


def get_makefile_name(libname):
"""
Given a library name, return the corresponding Makefile name.
Expand All @@ -56,9 +87,8 @@ def create_makefile(libname, includes, bifrost_path=None):
if isinstance(includes, (list, tuple)):
includes = " ".join(includes)

# Get the Bifrost source path, if needed
if bifrost_path is None:
bifrost_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Get the Bifrost paths
bifrost_config, bifrost_include, bifrost_library, bifrost_script = resolve_bifrost(bifrost_path=bifrost_path)

# Load in the template
with open(_MAKEFILE_TEMPLATE, 'r') as fh:
Expand All @@ -67,7 +97,10 @@ def create_makefile(libname, includes, bifrost_path=None):
# Fill the template, save it, and return the filename
template = template.format(libname=libname,
includes=includes,
bifrost=bifrost_path)
bifrost_config=bifrost_config,
bifrost_include=bifrost_include,
bifrost_library=bifrost_library,
bifrost_script=bifrost_script)
filename = get_makefile_name(libname)
with open(filename, 'w') as fh:
fh.write(template)
Expand Down
12 changes: 6 additions & 6 deletions plugins/makefile.tmpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

include {bifrost}/config.mk {bifrost}/user.mk
include {bifrost_config}/config.mk {bifrost_config}/user.mk

ifndef NOCUDA
# All CUDA archs supported by this version of nvcc
Expand Down Expand Up @@ -69,9 +69,9 @@ ifndef ANY_ARCH
NVCCFLAGS += -Xcompiler "-march=native"
endif

CPPFLAGS += -I{bifrost}/src -I. -I$(CUDA_INCDIR)
CPPFLAGS += -I{bifrost_include} -I. -I$(CUDA_INCDIR)

LDFLAGS += -L{bifrost}/lib -lbifrost
LDFLAGS += -L{bifrost_library} -lbifrost

GCCFLAGS += -fmessage-length=80 #-fdiagnostics-color=auto

Expand All @@ -82,7 +82,7 @@ PYTHON_WRAPPER_FILE={libname}.py
all: lib{libname}.so $(PYTHON_BINDINGS_FILE) $(PYTHON_WRAPPER_FILE)

define run_ctypesgen
python {bifrost}/python/wrap.py -l$1 -I. -I{bifrost}/src $^ -o $@
python -c 'from ctypesgen import main as ctypeswrap; ctypeswrap.main()' -l$1 -I. -I{bifrost_include} $^ -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 All @@ -95,7 +95,7 @@ define run_ctypesgen
endef

define run_wrapper
python {bifrost}/plugins/wrap_plugin.py $1
python {bifrost_script}/wrap_plugin.py $1
endef

lib{libname}.so: {libname}.o
Expand All @@ -114,4 +114,4 @@ $(PYTHON_WRAPPER_FILE): $(PYTHON_BINDINGS_FILE)
$(call run_wrapper,$(PYTHON_BINDINGS_FILE))

clean:
rm -f lib{libname}.so {libname}.o $(PYTHON_BINDINGS_FILE) $(PYTHON_WRAPPER_FILE)
rm -f lib{libname}.so {libname}.o $(PYTHON_BINDINGS_FILE) $(PYTHON_WRAPPER_FILE)

0 comments on commit 22d3074

Please sign in to comment.