Skip to content

Commit

Permalink
Merge pull request #84 from bacpop/blas-fix
Browse files Browse the repository at this point in the history
BLAS linking; CI fix; better message for deprecated function
  • Loading branch information
johnlees authored Nov 22, 2022
2 parents c61ee1a + f691884 commit bdb9f8d
Show file tree
Hide file tree
Showing 18 changed files with 801 additions and 341 deletions.
15 changes: 11 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,13 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)
find_package(ZLIB)
execute_process(COMMAND pybind11-config --cmakedir OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE pybind11_DIR)
find_package(pybind11 2.6 CONFIG REQUIRED)

# Linear algebra packages
find_package(Eigen3 3.3 REQUIRED NO_MODULE)
find_package(Armadillo REQUIRED)
include_directories(${ARMADILLO_INCLUDE_DIRS})
find_package(BLAS)
if(BLAS_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DEIGEN_USE_BLAS")
endif()

# Define python library target
add_library("${TARGET_NAME}" MODULE)
Expand All @@ -76,7 +80,7 @@ if(CMAKE_CUDA_COMPILER)
# -Xptxas -dlcm=ca turns cache on, but not needed in recent nvcc versions
# --cudart static: static linking of the CUDA libraries
# -gencode arch=compute_35 etc compiles for each (minimum) device version listed (v3.5, v5.0, v7.5)
set(CUDA_OPTS "-Xcompiler -fPIC -Xptxas -dlcm=ca --relocatable-device-code=true --expt-relaxed-constexpr")
set(CUDA_OPTS "-Xcompiler -fPIC -Xptxas -dlcm=ca --relocatable-device-code=true --expt-relaxed-constexpr --diag-suppress 20236")
# Turn on link time optimisation if available
if(CMAKE_BUILD_TYPE MATCHES Release)
string(APPEND CUDA_OPTS " -dlto -arch=sm_86")
Expand Down Expand Up @@ -123,6 +127,8 @@ target_sources("${TARGET_NAME}" PRIVATE src/sketchlib_bindings.cpp
src/database/database.cpp
src/api.cpp
src/dist/linear_regression.cpp
src/random/kmeans/KMeansRexCore.cpp
src/random/kmeans/mersenneTwister2002.c
src/random/rng.cpp
src/random/random_match.cpp)
set_target_properties("${TARGET_NAME}" PROPERTIES
Expand All @@ -141,7 +147,8 @@ if(CMAKE_CUDA_COMPILER)
set_property(TARGET "${TARGET_NAME}" PROPERTY CUDA_RESOLVE_DEVICE_SYMBOLS ON)
#set_property(TARGET "${TARGET_NAME}" PROPERTY CUDA_ARCHITECTURES OFF)
endif()
target_link_libraries("${TARGET_NAME}" PRIVATE pybind11::module Eigen3::Eigen ${HDF5_LIBRARIES} openblas lapack gfortran m dl)
target_link_libraries("${TARGET_NAME}" PRIVATE pybind11::module Eigen3::Eigen
${HDF5_LIBRARIES} ${BLAS_LIBRARIES} gfortran m dl)
if(DEFINED ENV{CONDA_PREFIX} AND (NOT APPLE OR CMAKE_COMPILER_IS_GNUCC OR ENV{SKETCHLIB_INSTALL} EQUAL "conda"))
target_link_libraries("${TARGET_NAME}" PRIVATE gomp z)
else()
Expand Down
14 changes: 14 additions & 0 deletions LICENSE_KMeansRex
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
BSD 3-clause license for open-source software.

Copyright (c) 2013-2015, Michael C. Hughes
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ steps:
export PATH=${CUDA_HOME}/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=${CUDA_HOME}/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
export SKETCHLIB_INSTALL=azure
python -m pip install --no-deps --ignore-installed .
python -m pip install --no-deps --ignore-installed . -vvv
displayName: 'Build & install (setup.py)'

- script: |
Expand Down
2 changes: 1 addition & 1 deletion pp_sketch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

'''PopPUNK sketching functions'''

__version__ = '2.0.1'
__version__ = '2.1.0'
2 changes: 1 addition & 1 deletion pp_sketch/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def main():
sequences = []

if args['-l']:
with open(args['-l'], 'rU') as refFile:
with open(args['-l'], 'r') as refFile:
for refLine in refFile:
refFields = refLine.rstrip().split("\t")
names.append(refFields[0])
Expand Down
8 changes: 4 additions & 4 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ endif

UNAME_S := $(shell uname -s)
LIBLOC = ${CONDA_PREFIX}
LDLIBS = -lz -lhdf5_cpp -lhdf5 -lopenblas -llapack -lgomp
LDLIBS = -lz -lhdf5_cpp -lhdf5 -lopenblas -lgomp
ifeq ($(UNAME_S),Linux)
CXXFLAGS+= -m64
ifdef PROFILE
Expand All @@ -29,11 +29,11 @@ LDFLAGS+= -L$(LIBLOC)/lib
CUDA_LDLIBS=-lcudadevrt -lcudart_static $(LDLIBS)

CUDA_LDFLAGS =-L$(LIBLOC)/lib -L${CUDA_HOME}/targets/x86_64-linux/lib/stubs -L${CUDA_HOME}/targets/x86_64-linux/lib
CUDAFLAGS +=-Xcompiler -fPIC -Xptxas -dlcm=ca --cudart static --relocatable-device-code=true -gencode arch=compute_70,code=sm_70 -gencode arch=compute_75,code=sm_75
CUDAFLAGS +=-Xcompiler -fPIC -Xptxas -dlcm=ca --cudart static --relocatable-device-code=true --expt-relaxed-constexpr -gencode arch=compute_70,code=sm_70 -gencode arch=compute_75,code=sm_75
ifdef GPU
CXXFLAGS += -DGPU_AVAILABLE
CUDAFLAGS += -gencode arch=compute_86,code=sm_86
CUDA_LDFLAGS += -L/usr/local/cuda-11.1/lib64
CUDA_LDFLAGS += -L/usr/local/cuda-11.2/lib64
endif

PYTHON_LIB = pp_sketchlib$(shell python3-config --extension-suffix)
Expand All @@ -43,7 +43,7 @@ python: CPPFLAGS += -DGPU_AVAILABLE -DPYTHON_EXT -DNDEBUG -Dpp_sketchlib_EXPORTS

PROGRAMS=sketch_test matrix_test read_test gpu_dist_test

SKETCH_OBJS=dist/dist.o dist/matrix_ops.o reference.o sketch/seqio.o sketch/sketch.o database/database.o sketch/countmin.o api.o dist/linear_regression.o random/rng.o random/random_match.o
SKETCH_OBJS=dist/dist.o dist/matrix_ops.o reference.o sketch/seqio.o sketch/sketch.o database/database.o sketch/countmin.o api.o dist/linear_regression.o random/rng.o random/random_match.o random/kmeans/KMeansRexCore.o random/kmeans/mersenneTwister2002.o
GPU_SKETCH_OBJS=gpu/gpu_api.o
CUDA_OBJS=gpu/dist.cu.o gpu/sketch.cu.o gpu/device_reads.cu.o gpu/gpu_countmin.cu.o gpu/device_memory.cu.o

Expand Down
6 changes: 3 additions & 3 deletions src/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ NumpyMatrix query_db(std::vector<Reference> &ref_sketches,
if (ref_sketches == query_sketches) {
// calculate dists
distMat.resize(dist_rows, dist_cols);
arma::mat kmer_mat = kmer2mat<std::vector<size_t>>(kmer_lengths);
Eigen::MatrixXf kmer_mat = kmer2mat(kmer_lengths);

// Iterate upper triangle
#pragma omp parallel for schedule(dynamic, 5) num_threads(num_threads) shared(progress)
Expand Down Expand Up @@ -230,7 +230,7 @@ NumpyMatrix query_db(std::vector<Reference> &ref_sketches,
distMat.resize(dist_rows, dist_cols);

// Prepare objects used in distance calculations
arma::mat kmer_mat = kmer2mat<std::vector<size_t>>(kmer_lengths);
Eigen::MatrixXf kmer_mat = kmer2mat(kmer_lengths);
std::vector<size_t> query_lengths(query_sketches.size());
std::vector<uint16_t> query_random_idxs(query_sketches.size());

Expand Down Expand Up @@ -338,7 +338,7 @@ sparse_coo query_db_sparse(std::vector<Reference> &ref_sketches,
ProgressMeter dist_progress(n_progress_ticks, true);
volatile int progress = 0;

arma::mat kmer_mat = kmer2mat<std::vector<size_t>>(kmer_lengths);
Eigen::MatrixXf kmer_mat = kmer2mat(kmer_lengths);
#pragma omp parallel for schedule(static) num_threads(num_threads) shared(progress)
for (size_t i = 0; i < ref_sketches.size(); i++) {
std::vector<float> row_dists(ref_sketches.size());
Expand Down
Loading

0 comments on commit bdb9f8d

Please sign in to comment.