From 3c1b044491c211716add3cf4e6e0f273bcfe01d2 Mon Sep 17 00:00:00 2001 From: Igor Sfiligoi Date: Thu, 23 Jan 2025 14:16:44 -0800 Subject: [PATCH 1/7] Add su::biom::load_n_samples and use in su.cpp --- src/biom.cpp | 27 ++++++++------------------- src/biom.hpp | 24 ++++++++++++++++++++++++ src/su.cpp | 7 ++++--- src/test_su.cpp | 3 +++ 4 files changed, 39 insertions(+), 22 deletions(-) diff --git a/src/biom.cpp b/src/biom.cpp index 6b01c57..57be3ff 100644 --- a/src/biom.cpp +++ b/src/biom.cpp @@ -15,33 +15,22 @@ using namespace H5; using namespace su; -/* datasets defined by the BIOM 2.x spec */ -const std::string OBS_INDPTR = std::string("/observation/matrix/indptr"); -const std::string OBS_INDICES = std::string("/observation/matrix/indices"); -const std::string OBS_DATA = std::string("/observation/matrix/data"); -const std::string OBS_IDS = std::string("/observation/ids"); - -const std::string SAMPLE_INDPTR = std::string("/sample/matrix/indptr"); -const std::string SAMPLE_INDICES = std::string("/sample/matrix/indices"); -const std::string SAMPLE_DATA = std::string("/sample/matrix/data"); -const std::string SAMPLE_IDS = std::string("/sample/ids"); - biom::biom(std::string filename) : biom_inmem(true) , has_hdf5_backing(true) { file = H5File(filename.c_str(), H5F_ACC_RDONLY); /* establish the datasets */ - obs_indices = file.openDataSet(OBS_INDICES.c_str()); - obs_data = file.openDataSet(OBS_DATA.c_str()); - sample_indices = file.openDataSet(SAMPLE_INDICES.c_str()); - sample_data = file.openDataSet(SAMPLE_DATA.c_str()); + obs_indices = file.openDataSet(OBS_INDICES); + obs_data = file.openDataSet(OBS_DATA); + sample_indices = file.openDataSet(SAMPLE_INDICES); + sample_data = file.openDataSet(SAMPLE_DATA); /* cache IDs and indptr */ - load_ids(OBS_IDS.c_str(), obs_ids); - load_ids(SAMPLE_IDS.c_str(), sample_ids); - load_indptr(OBS_INDPTR.c_str(), obs_indptr); - load_indptr(SAMPLE_INDPTR.c_str(), sample_indptr); + load_ids(OBS_IDS, obs_ids); + load_ids(SAMPLE_IDS, sample_ids); + load_indptr(OBS_INDPTR, obs_indptr); + load_indptr(SAMPLE_INDPTR, sample_indptr); /* cache shape and nnz info */ n_samples = sample_ids.size(); diff --git a/src/biom.hpp b/src/biom.hpp index 66c4959..101acd1 100644 --- a/src/biom.hpp +++ b/src/biom.hpp @@ -60,6 +60,17 @@ namespace su { biom& operator= (const biom&) = delete; private: + /* datasets defined by the BIOM 2.x spec */ + static constexpr const char * OBS_INDPTR = "/observation/matrix/indptr"; + static constexpr const char * OBS_INDICES = "/observation/matrix/indices"; + static constexpr const char * OBS_DATA = "/observation/matrix/data"; + static constexpr const char * OBS_IDS = "/observation/ids"; + + static constexpr const char * SAMPLE_INDPTR = "/sample/matrix/indptr"; + static constexpr const char * SAMPLE_INDICES = "/sample/matrix/indices"; + static constexpr const char * SAMPLE_DATA = "/sample/matrix/data"; + static constexpr const char * SAMPLE_IDS = "/sample/ids"; + bool has_hdf5_backing = false; // cache both index pointers into both CSC and CSR representations @@ -95,6 +106,19 @@ namespace su { public: uint32_t nnz; // the total number of nonzero entries + // used by ssu for helper messages + static inline size_t load_n_samples(const char* filename) { + const char* path = SAMPLE_IDS; + H5::H5File file(filename, H5F_ACC_RDONLY); + H5::DataSet ds_ids = file.openDataSet(path); + H5::DataSpace dataspace = ds_ids.getSpace(); + + hsize_t dims[1]; + dataspace.getSimpleExtentDims(dims, NULL); + + return dims[0]; + } + // for unit testing bool is_sample_indptr(const std::vector& other) const { return sample_indptr==other; } bool is_obs_indptr(const std::vector& other) const { return obs_indptr==other; } diff --git a/src/su.cpp b/src/su.cpp index edb914b..b46d4cb 100644 --- a/src/su.cpp +++ b/src/su.cpp @@ -7,6 +7,7 @@ #include "api.hpp" #include "cmd.hpp" #include "tree.hpp" +// Using inlined-header-only funtions #include "biom.hpp" #include "unifrac.hpp" @@ -128,11 +129,11 @@ int mode_partial_report(const std::string table_filename, unsigned int npartials exit(EXIT_FAILURE); } - su::biom table(table_filename.c_str()); - int total_stripes = (table.n_samples + 1) / 2; + int n_samples = su::biom::load_n_samples(table_filename.c_str()); + int total_stripes = (n_samples + 1) / 2; if(!bare) { - std::cout << "Total samples: " << table.n_samples << std::endl; + std::cout << "Total samples: " << n_samples << std::endl; std::cout << "Total stripes: " << total_stripes << std::endl; } diff --git a/src/test_su.cpp b/src/test_su.cpp index 6fb2c48..a04de73 100644 --- a/src/test_su.cpp +++ b/src/test_su.cpp @@ -383,6 +383,9 @@ void test_biom_constructor() { ASSERT(table_copy.get_sample_ids() == exp_sids); ASSERT(table_copy.get_obs_ids() == exp_oids); + uint32_t t_n_samples = su::biom::load_n_samples("test.biom"); + ASSERT(t_n_samples == exp_n_samples); + SUITE_END(); } From 68380905f09615e8e1c84021a4193b73bdb2ec85 Mon Sep 17 00:00:00 2001 From: Igor Sfiligoi Date: Thu, 23 Jan 2025 14:41:12 -0800 Subject: [PATCH 2/7] Remove unnecessary header includes --- src/faithpd.cpp | 3 --- src/su.cpp | 2 -- 2 files changed, 5 deletions(-) diff --git a/src/faithpd.cpp b/src/faithpd.cpp index 2067496..97ca167 100644 --- a/src/faithpd.cpp +++ b/src/faithpd.cpp @@ -4,9 +4,6 @@ #include #include "api.hpp" #include "cmd.hpp" -#include "tree.hpp" -#include "biom.hpp" -#include "unifrac.hpp" void usage() { diff --git a/src/su.cpp b/src/su.cpp index b46d4cb..66e69ad 100644 --- a/src/su.cpp +++ b/src/su.cpp @@ -6,10 +6,8 @@ #include #include "api.hpp" #include "cmd.hpp" -#include "tree.hpp" // Using inlined-header-only funtions #include "biom.hpp" -#include "unifrac.hpp" enum Format {format_invalid,format_ascii, format_hdf5_fp32, format_hdf5_fp64, format_hdf5_nodist}; From 1efade6fbb7978271fce61077a2870cb275b266d Mon Sep 17 00:00:00 2001 From: Igor Sfiligoi Date: Thu, 23 Jan 2025 15:52:30 -0800 Subject: [PATCH 3/7] Expose the partial functions in libssu --- combined/libssu.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++ src/api.hpp | 14 ++++++------ 2 files changed, 64 insertions(+), 7 deletions(-) diff --git a/combined/libssu.c b/combined/libssu.c index f9d49fd..a6905fa 100644 --- a/combined/libssu.c +++ b/combined/libssu.c @@ -508,4 +508,61 @@ ComputeStatus one_dense_pair_v2(unsigned int n_obs, const char ** obs_ids, const return (*dl_one_dense_pair_v2)(n_obs,obs_ids,sample1,sample2,tree_data,unifrac_method,variance_adjust,alpha,bypass_tips,result); } +/*********************************************************************/ + +static ComputeStatus (*dl_partial)(const char*, const char*, const char*, bool, double, bool, unsigned int, unsigned int, unsigned int, partial_mat_t**) = NULL; +static MergeStatus (*dl_merge_partial_to_mmap_matrix)(partial_dyn_mat_t**, int, const char *, mat_full_fp64_t**) = NULL; +static MergeStatus (*dl_merge_partial_to_mmap_matrix_fp32)(partial_dyn_mat_t**, int, const char *, mat_full_fp32_t**) = NULL; +static MergeStatus (*dl_validate_partial)(const partial_dyn_mat_t* const *, int); +static IOStatus (*dl_read_partial_header)(const char*, partial_dyn_mat_t**); +static IOStatus (*dl_read_partial_one_stripe)(partial_dyn_mat_t*, uint32_t); +static IOStatus (*dl_write_partial)(const char*, const partial_mat_t*); + + +ComputeStatus partial(const char* biom_filename, const char* tree_filename, + const char* unifrac_method, bool variance_adjust, double alpha, + bool bypass_tips, unsigned int n_substeps, unsigned int stripe_start, + unsigned int stripe_stop, partial_mat_t** result) { + if (dl_partial==NULL) ssu_load("partial", (void **) &dl_partial); + + return (*dl_partial)(biom_filename,tree_filename,unifrac_method,variance_adjust,alpha, + bypass_tips,n_substeps,stripe_start,stripe_stop,result); +} + +MergeStatus merge_partial_to_mmap_matrix(partial_dyn_mat_t* * partial_mats, int n_partials, const char *mmap_dir, mat_full_fp64_t** result) { + if (dl_merge_partial_to_mmap_matrix==NULL) ssu_load("merge_partial_to_mmap_matrix", (void **) &dl_merge_partial_to_mmap_matrix); + + return (*dl_merge_partial_to_mmap_matrix)(partial_mats,n_partials,mmap_dir,result); +} + +MergeStatus merge_partial_to_mmap_matrix_fp32(partial_dyn_mat_t* * partial_mats, int n_partials, const char *mmap_dir, mat_full_fp32_t** result) { + if (dl_merge_partial_to_mmap_matrix_fp32==NULL) ssu_load("merge_partial_to_mmap_matrix_fp32", (void **) &dl_merge_partial_to_mmap_matrix_fp32); + + return (*dl_merge_partial_to_mmap_matrix_fp32)(partial_mats,n_partials,mmap_dir,result); +} + +MergeStatus validate_partial(const partial_dyn_mat_t* const * partial_mats, int n_partials) { + if (dl_validate_partial==NULL) ssu_load("validate_partial", (void **) &dl_validate_partial); + + return (*dl_validate_partial)(partial_mats,n_partials); +} + +IOStatus read_partial_header(const char* input_filename, partial_dyn_mat_t** result_out) { + if (dl_read_partial_header==NULL) ssu_load("read_partial_header", (void **) &dl_read_partial_header); + + return (*dl_read_partial_header)(input_filename,result_out); +} + +IOStatus read_partial_one_stripe(partial_dyn_mat_t* result, uint32_t stripe_idx) { + if (dl_read_partial_one_stripe==NULL) ssu_load("read_partial_one_stripe", (void **) &dl_read_partial_one_stripe); + + return (*dl_read_partial_one_stripe)(result,stripe_idx); +} + +IOStatus write_partial(const char* filename, const partial_mat_t* result) { + if (dl_write_partial==NULL) ssu_load("write_partial", (void **) &dl_write_partial); + + return (*dl_write_partial)(filename,result); +} + diff --git a/src/api.hpp b/src/api.hpp index d25d11c..0417c98 100644 --- a/src/api.hpp +++ b/src/api.hpp @@ -704,7 +704,7 @@ EXTERN IOStatus write_vec(const char* filename, r_vec* result); * unknown_method : the requested method is unknown. */ -ComputeStatus partial(const char* biom_filename, const char* tree_filename, +EXTERN ComputeStatus partial(const char* biom_filename, const char* tree_filename, const char* unifrac_method, bool variance_adjust, double alpha, bool bypass_tips, unsigned int n_substeps, unsigned int stripe_start, unsigned int stripe_stop, partial_mat_t** result); @@ -750,7 +750,7 @@ ComputeStatus partial(const char* biom_filename, const char* tree_filename, * ### FOOTER ### * : char, e.g., SSU-PARTIAL-01, same as starting magic */ -IOStatus write_partial(const char* filename, const partial_mat_t* result); +EXTERN IOStatus write_partial(const char* filename, const partial_mat_t* result); /* Read a partial matrix object * @@ -780,7 +780,7 @@ IOStatus read_partial(const char* filename, partial_mat_t** result); * bad_header : header seems malformed * unexpected_end : format end not found in expected location */ -IOStatus read_partial_header(const char* input_filename, partial_dyn_mat_t** result_out); +EXTERN IOStatus read_partial_header(const char* input_filename, partial_dyn_mat_t** result_out); /* Read a stripe of a partial matrix * @@ -796,12 +796,12 @@ IOStatus read_partial_header(const char* input_filename, partial_dyn_mat_t** res * bad_header : header seems malformed * unexpected_end : format end not found in expected location */ -IOStatus read_partial_one_stripe(partial_dyn_mat_t* result, uint32_t stripe_idx); +EXTERN IOStatus read_partial_one_stripe(partial_dyn_mat_t* result, uint32_t stripe_idx); /* * Description TBD */ -MergeStatus validate_partial(const partial_dyn_mat_t* const * partial_mats, int n_partials); +EXTERN MergeStatus validate_partial(const partial_dyn_mat_t* const * partial_mats, int n_partials); /* Merge partial results * @@ -863,7 +863,7 @@ MergeStatus merge_partial_to_matrix_fp32(partial_dyn_mat_t* * partial_mats, int * sample_id_consistency : samples described by stripes are inconsistent * square_mismatch : inconsistency on denotation of square matrix */ -MergeStatus merge_partial_to_mmap_matrix(partial_dyn_mat_t* * partial_mats, int n_partials, const char *mmap_dir, mat_full_fp64_t** result); +EXTERN MergeStatus merge_partial_to_mmap_matrix(partial_dyn_mat_t* * partial_mats, int n_partials, const char *mmap_dir, mat_full_fp64_t** result); /* Merge partial results * @@ -879,7 +879,7 @@ MergeStatus merge_partial_to_mmap_matrix(partial_dyn_mat_t* * partial_mats, int * sample_id_consistency : samples described by stripes are inconsistent * square_mismatch : inconsistency on denotation of square matrix */ -MergeStatus merge_partial_to_mmap_matrix_fp32(partial_dyn_mat_t* * partial_mats, int n_partials, const char *mmap_dir, mat_full_fp32_t** result); +EXTERN MergeStatus merge_partial_to_mmap_matrix_fp32(partial_dyn_mat_t* * partial_mats, int n_partials, const char *mmap_dir, mat_full_fp32_t** result); // Find eigen values and vectors From 897ce3eeaeaec90d2d1ccf648be0a8b37fbde436 Mon Sep 17 00:00:00 2001 From: Igor Sfiligoi Date: Thu, 23 Jan 2025 16:56:23 -0800 Subject: [PATCH 4/7] Make libssu trully thread-safe --- combined/libssu.c | 103 ++++++++++++++++++++++----------------- src/unifrac_internal.cpp | 2 +- 2 files changed, 58 insertions(+), 47 deletions(-) diff --git a/combined/libssu.c b/combined/libssu.c index a6905fa..b410e2c 100644 --- a/combined/libssu.c +++ b/combined/libssu.c @@ -11,6 +11,7 @@ #include #include #include +#include #include "../src/api.hpp" @@ -20,6 +21,8 @@ * */ +static pthread_mutex_t dl_mutex = PTHREAD_MUTEX_INITIALIZER; + /*********************************************************************/ /* Pick the right libssu implementation */ @@ -85,6 +88,14 @@ static void ssu_load(const char *fncname, } } +static void cond_ssu_load(const char *fncname, + void **dl_ptr) { + + pthread_mutex_lock(&dl_mutex); + if ((*dl_ptr)==NULL) ssu_load(fncname,dl_ptr); + pthread_mutex_unlock(&dl_mutex); +} + /*********************************************************************/ /* All the functons below are wrappers * and each has its own function pointer @@ -93,7 +104,7 @@ static void ssu_load(const char *fncname, static void (*dl_ssu_set_random_seed)(unsigned int) = NULL; void ssu_set_random_seed(unsigned int new_seed) { - if (dl_ssu_set_random_seed==NULL) ssu_load("ssu_set_random_seed", (void **) &dl_ssu_set_random_seed); + cond_ssu_load("ssu_set_random_seed", (void **) &dl_ssu_set_random_seed); (*dl_ssu_set_random_seed)(new_seed); } @@ -114,67 +125,67 @@ static void (*dl_convert_bptree_opaque)(const support_bptree_t*, opaque_bptree_t static int (*dl_get_bptree_opaque_els)(opaque_bptree_t*) = NULL; void destroy_mat(mat_t** result) { - if (dl_destroy_mat==NULL) ssu_load("destroy_mat", (void **) &dl_destroy_mat); + cond_ssu_load("destroy_mat", (void **) &dl_destroy_mat); (*dl_destroy_mat)(result); } void destroy_mat_full_fp64(mat_full_fp64_t** result) { - if (dl_destroy_mat_full_fp64==NULL) ssu_load("destroy_mat_full_fp64", (void **) &dl_destroy_mat_full_fp64); + cond_ssu_load("destroy_mat_full_fp64", (void **) &dl_destroy_mat_full_fp64); (*dl_destroy_mat_full_fp64)(result); } void destroy_mat_full_fp32(mat_full_fp32_t** result) { - if (dl_destroy_mat_full_fp32==NULL) ssu_load("destroy_mat_full_fp32", (void **) &dl_destroy_mat_full_fp32); + cond_ssu_load("destroy_mat_full_fp32", (void **) &dl_destroy_mat_full_fp32); (*dl_destroy_mat_full_fp32)(result); } void destroy_partial_mat(partial_mat_t** result) { - if (dl_destroy_partial_mat==NULL) ssu_load("destroy_partial_mat", (void **) &dl_destroy_partial_mat); + cond_ssu_load("destroy_partial_mat", (void **) &dl_destroy_partial_mat); (*dl_destroy_partial_mat)(result); } void destroy_partial_dyn_mat(partial_dyn_mat_t** result) { - if (dl_destroy_partial_dyn_mat==NULL) ssu_load("destroy_partial_dyn_mat", (void **) &dl_destroy_partial_dyn_mat); + cond_ssu_load("destroy_partial_dyn_mat", (void **) &dl_destroy_partial_dyn_mat); (*dl_destroy_partial_dyn_mat)(result); } void destroy_results_vec(r_vec** result) { - if (dl_destroy_results_vec==NULL) ssu_load("destroy_results_vec", (void **) &dl_destroy_results_vec); + cond_ssu_load("destroy_results_vec", (void **) &dl_destroy_results_vec); (*dl_destroy_results_vec)(result); } void destroy_bptree_opaque(opaque_bptree_t** tree_data) { - if (dl_destroy_bptree_opaque==NULL) ssu_load("destroy_bptree_opaque", (void **) &dl_destroy_bptree_opaque); + cond_ssu_load("destroy_bptree_opaque", (void **) &dl_destroy_bptree_opaque); (*dl_destroy_bptree_opaque)(tree_data); } IOStatus read_bptree_opaque(const char* tree_filename, opaque_bptree_t** tree_data) { - if (dl_read_bptree_opaque==NULL) ssu_load("read_bptree_opaque", (void **) &dl_read_bptree_opaque); + cond_ssu_load("read_bptree_opaque", (void **) &dl_read_bptree_opaque); return (*dl_read_bptree_opaque)(tree_filename,tree_data); } void load_bptree_opaque(const char* newick, opaque_bptree_t** tree_data) { - if (dl_load_bptree_opaque==NULL) ssu_load("load_bptree_opaque", (void **) &dl_load_bptree_opaque); + cond_ssu_load("load_bptree_opaque", (void **) &dl_load_bptree_opaque); (*dl_load_bptree_opaque)(newick,tree_data); } void convert_bptree_opaque(const support_bptree_t* in_tree, opaque_bptree_t** tree_data) { - if (dl_convert_bptree_opaque==NULL) ssu_load("convert_bptree_opaque", (void **) &dl_convert_bptree_opaque); + cond_ssu_load("convert_bptree_opaque", (void **) &dl_convert_bptree_opaque); (*dl_convert_bptree_opaque)(in_tree,tree_data); } int get_bptree_opaque_els(opaque_bptree_t* tree_data) { - if (dl_get_bptree_opaque_els==NULL) ssu_load("get_bptree_opaque_els", (void **) &dl_get_bptree_opaque_els); + cond_ssu_load("get_bptree_opaque_els", (void **) &dl_get_bptree_opaque_els); return (*dl_get_bptree_opaque_els)(tree_data); } @@ -187,7 +198,7 @@ static ComputeStatus (*dl_one_off_wtree)(const char*, const opaque_bptree_t*, co ComputeStatus one_off(const char* biom_filename, const char* tree_filename, const char* unifrac_method, bool variance_adjust, double alpha, bool bypass_tips, unsigned int n_substeps, mat_t** result) { - if (dl_one_off==NULL) ssu_load("one_off", (void **) &dl_one_off); + cond_ssu_load("one_off", (void **) &dl_one_off); return (*dl_one_off)(biom_filename, tree_filename, unifrac_method, variance_adjust, alpha, bypass_tips, n_substeps, result); } @@ -195,7 +206,7 @@ ComputeStatus one_off(const char* biom_filename, const char* tree_filename, ComputeStatus one_off_wtree(const char* biom_filename, const opaque_bptree_t* tree_data, const char* unifrac_method, bool variance_adjust, double alpha, bool bypass_tips, unsigned int n_substeps, mat_t** result) { - if (dl_one_off_wtree==NULL) ssu_load("one_off_wtree", (void **) &dl_one_off_wtree); + cond_ssu_load("one_off_wtree", (void **) &dl_one_off_wtree); return (*dl_one_off_wtree)(biom_filename, tree_data, unifrac_method, variance_adjust, alpha, bypass_tips, n_substeps, result); } @@ -216,7 +227,7 @@ ComputeStatus one_off_matrix_inmem_v2(const support_biom_t *table_data, const su bool bypass_tips, unsigned int n_substeps, unsigned int subsample_depth, bool subsample_with_replacement, const char *mmap_dir, mat_full_fp64_t** result) { - if (dl_one_off_matrix_inmem_v2==NULL) ssu_load("one_off_matrix_inmem_v2", (void **) &dl_one_off_matrix_inmem_v2); + cond_ssu_load("one_off_matrix_inmem_v2", (void **) &dl_one_off_matrix_inmem_v2); return (*dl_one_off_matrix_inmem_v2)(table_data, tree_data, unifrac_method, variance_adjust, alpha, bypass_tips, n_substeps, subsample_depth, subsample_with_replacement, mmap_dir, result); @@ -225,7 +236,7 @@ ComputeStatus one_off_matrix_inmem_v2(const support_biom_t *table_data, const su ComputeStatus one_off_inmem(const support_biom_t *table_data, const support_bptree_t *tree_data, const char* unifrac_method, bool variance_adjust, double alpha, bool bypass_tips, unsigned int n_substeps, mat_full_fp64_t** result) { - if (dl_one_off_inmem==NULL) ssu_load("one_off_inmem", (void **) &dl_one_off_inmem); + cond_ssu_load("one_off_inmem", (void **) &dl_one_off_inmem); return (*dl_one_off_inmem)(table_data, tree_data, unifrac_method, variance_adjust, alpha, bypass_tips, n_substeps, result); } @@ -235,7 +246,7 @@ ComputeStatus one_off_matrix_inmem_fp32_v2(const support_biom_t *table_data, con bool bypass_tips, unsigned int n_substeps, unsigned int subsample_depth, bool subsample_with_replacement, const char *mmap_dir, mat_full_fp32_t** result) { - if (dl_one_off_matrix_inmem_fp32_v2==NULL) ssu_load("one_off_matrix_inmem_fp32_v2", (void **) &dl_one_off_matrix_inmem_fp32_v2); + cond_ssu_load("one_off_matrix_inmem_fp32_v2", (void **) &dl_one_off_matrix_inmem_fp32_v2); return (*dl_one_off_matrix_inmem_fp32_v2)(table_data, tree_data, unifrac_method, variance_adjust, alpha, bypass_tips, n_substeps, subsample_depth, subsample_with_replacement, mmap_dir, result); @@ -244,7 +255,7 @@ ComputeStatus one_off_matrix_inmem_fp32_v2(const support_biom_t *table_data, con ComputeStatus one_off_inmem_fp32(const support_biom_t *table_data, const support_bptree_t *tree_data, const char* unifrac_method, bool variance_adjust, double alpha, bool bypass_tips, unsigned int n_substeps, mat_full_fp32_t** result) { - if (dl_one_off_inmem_fp32==NULL) ssu_load("one_off_inmem_fp32", (void **) &dl_one_off_inmem_fp32); + cond_ssu_load("one_off_inmem_fp32", (void **) &dl_one_off_inmem_fp32); return (*dl_one_off_inmem_fp32)(table_data, tree_data, unifrac_method, variance_adjust, alpha, bypass_tips, n_substeps, result); } @@ -269,7 +280,7 @@ ComputeStatus one_off_matrix_v2(const char* biom_filename, const char* tree_file bool bypass_tips, unsigned int n_substeps, unsigned int subsample_depth, bool subsample_with_replacement, const char *mmap_dir, mat_full_fp64_t** result) { - if (dl_one_off_matrix_v2==NULL) ssu_load("one_off_matrix_v2", (void **) &dl_one_off_matrix_v2); + cond_ssu_load("one_off_matrix_v2", (void **) &dl_one_off_matrix_v2); return (*dl_one_off_matrix_v2)(biom_filename, tree_filename, unifrac_method, variance_adjust, alpha, bypass_tips, n_substeps, subsample_depth, subsample_with_replacement, mmap_dir, result); @@ -280,7 +291,7 @@ ComputeStatus one_off_matrix_v2t(const char* biom_filename, const opaque_bptree_ bool bypass_tips, unsigned int n_substeps, unsigned int subsample_depth, bool subsample_with_replacement, const char *mmap_dir, mat_full_fp64_t** result) { - if (dl_one_off_matrix_v2t==NULL) ssu_load("one_off_matrix_v2t", (void **) &dl_one_off_matrix_v2t); + cond_ssu_load("one_off_matrix_v2t", (void **) &dl_one_off_matrix_v2t); return (*dl_one_off_matrix_v2t)(biom_filename, tree_data, unifrac_method, variance_adjust, alpha, bypass_tips, n_substeps, subsample_depth, subsample_with_replacement, mmap_dir, result); @@ -291,7 +302,7 @@ ComputeStatus one_off_matrix(const char* biom_filename, const char* tree_filenam bool bypass_tips, unsigned int n_substeps, const char *mmap_dir, mat_full_fp64_t** result) { - if (dl_one_off_matrix==NULL) ssu_load("one_off_matrix", (void **) &dl_one_off_matrix); + cond_ssu_load("one_off_matrix", (void **) &dl_one_off_matrix); return (*dl_one_off_matrix)(biom_filename, tree_filename, unifrac_method, variance_adjust, alpha, bypass_tips, n_substeps, mmap_dir, result); @@ -302,7 +313,7 @@ ComputeStatus one_off_matrix_fp32_v2(const char* biom_filename, const char* tree bool bypass_tips, unsigned int n_substeps, unsigned int subsample_depth, bool subsample_with_replacement, const char *mmap_dir, mat_full_fp32_t** result) { - if (dl_one_off_matrix_fp32_v2==NULL) ssu_load("one_off_matrix_fp32_v2", (void **) &dl_one_off_matrix_fp32_v2); + cond_ssu_load("one_off_matrix_fp32_v2", (void **) &dl_one_off_matrix_fp32_v2); return (*dl_one_off_matrix_fp32_v2)(biom_filename, tree_filename, unifrac_method, variance_adjust, alpha, bypass_tips, n_substeps, subsample_depth, subsample_with_replacement, mmap_dir, result); @@ -313,7 +324,7 @@ ComputeStatus one_off_matrix_fp32_v2t(const char* biom_filename, const opaque_bp bool bypass_tips, unsigned int n_substeps, unsigned int subsample_depth, bool subsample_with_replacement, const char *mmap_dir, mat_full_fp32_t** result) { - if (dl_one_off_matrix_fp32_v2t==NULL) ssu_load("one_off_matrix_fp32_v2t", (void **) &dl_one_off_matrix_fp32_v2t); + cond_ssu_load("one_off_matrix_fp32_v2t", (void **) &dl_one_off_matrix_fp32_v2t); return (*dl_one_off_matrix_fp32_v2t)(biom_filename, tree_data, unifrac_method, variance_adjust, alpha, bypass_tips, n_substeps, subsample_depth, subsample_with_replacement, mmap_dir, result); @@ -324,7 +335,7 @@ ComputeStatus one_off_matrix_fp32(const char* biom_filename, const char* tree_fi bool bypass_tips, unsigned int n_substeps, const char *mmap_dir, mat_full_fp32_t** result) { - if (dl_one_off_matrix_fp32==NULL) ssu_load("one_off_matrix_fp32", (void **) &dl_one_off_matrix_fp32); + cond_ssu_load("one_off_matrix_fp32", (void **) &dl_one_off_matrix_fp32); return (*dl_one_off_matrix_fp32)(biom_filename, tree_filename, unifrac_method, variance_adjust, alpha, bypass_tips, n_substeps, mmap_dir, result); @@ -335,7 +346,7 @@ ComputeStatus one_off_matrix_fp32(const char* biom_filename, const char* tree_fi static ComputeStatus (*dl_faith_pd_one_off)(const char*, const char*, r_vec**) = NULL; ComputeStatus faith_pd_one_off(const char* biom_filename, const char* tree_filename, r_vec** result) { - if (dl_faith_pd_one_off==NULL) ssu_load("faith_pd_one_off", (void **) &dl_faith_pd_one_off); + cond_ssu_load("faith_pd_one_off", (void **) &dl_faith_pd_one_off); return (*dl_faith_pd_one_off)(biom_filename, tree_filename, result); } @@ -358,7 +369,7 @@ ComputeStatus unifrac_to_file_v2(const char* biom_filename, const char* tree_fil unsigned int pcoa_dims, unsigned int permanova_perms, const char *grouping_filename, const char *grouping_columns, const char *mmap_dir){ - if (dl_unifrac_to_file_v2==NULL) ssu_load("unifrac_to_file_v2", (void **) &dl_unifrac_to_file_v2); + cond_ssu_load("unifrac_to_file_v2", (void **) &dl_unifrac_to_file_v2); return (*dl_unifrac_to_file_v2)(biom_filename, tree_filename, out_filename, unifrac_method, variance_adjust, alpha, bypass_tips, n_substeps, format, subsample_depth, subsample_with_replacement, @@ -369,7 +380,7 @@ ComputeStatus unifrac_to_file(const char* biom_filename, const char* tree_filena const char* unifrac_method, bool variance_adjust, double alpha, bool bypass_tips, unsigned int n_substeps, const char* format, unsigned int pcoa_dims, const char *mmap_dir) { - if (dl_unifrac_to_file==NULL) ssu_load("unifrac_to_file", (void **) &dl_unifrac_to_file); + cond_ssu_load("unifrac_to_file", (void **) &dl_unifrac_to_file); return (*dl_unifrac_to_file)(biom_filename, tree_filename, out_filename, unifrac_method, variance_adjust, alpha, bypass_tips, n_substeps, format, pcoa_dims, mmap_dir); @@ -382,7 +393,7 @@ ComputeStatus unifrac_multi_to_file_v2(const char* biom_filename, const char* tr unsigned int pcoa_dims, unsigned int permanova_perms, const char *grouping_filename, const char *grouping_columns, const char *mmap_dir) { - if (dl_unifrac_multi_to_file_v2==NULL) ssu_load("unifrac_multi_to_file_v2", (void **) &dl_unifrac_multi_to_file_v2); + cond_ssu_load("unifrac_multi_to_file_v2", (void **) &dl_unifrac_multi_to_file_v2); return (*dl_unifrac_multi_to_file_v2)(biom_filename, tree_filename, out_filename, unifrac_method, variance_adjust, alpha, bypass_tips, n_substeps, format, n_subsamples, subsample_depth, subsample_with_replacement, @@ -398,7 +409,7 @@ static ComputeStatus (*dl_compute_permanova_fp32)(const char *, unsigned int, co ComputeStatus compute_permanova_fp64(const char *grouping_filename, unsigned int n_columns, const char* *columns, mat_full_fp64_t * result, unsigned int permanova_perms, double *fstats, double *pvalues) { - if (dl_compute_permanova_fp64==NULL) ssu_load("compute_permanova_fp64", (void **) &dl_compute_permanova_fp64); + cond_ssu_load("compute_permanova_fp64", (void **) &dl_compute_permanova_fp64); return (*dl_compute_permanova_fp64)(grouping_filename, n_columns, columns, result, permanova_perms, fstats, pvalues); } @@ -406,7 +417,7 @@ ComputeStatus compute_permanova_fp64(const char *grouping_filename, unsigned int ComputeStatus compute_permanova_fp32(const char *grouping_filename, unsigned int n_columns, const char* * columns, mat_full_fp32_t * result, unsigned int permanova_perms, float *fstats, float *pvalues) { - if (dl_compute_permanova_fp32==NULL) ssu_load("compute_permanova_fp32", (void **) &dl_compute_permanova_fp32); + cond_ssu_load("compute_permanova_fp32", (void **) &dl_compute_permanova_fp32); return (*dl_compute_permanova_fp32)(grouping_filename, n_columns, columns, result, permanova_perms, fstats, pvalues); } @@ -418,19 +429,19 @@ static IOStatus (*dl_write_mat_from_matrix)(const char*, mat_full_fp64_t*) = NUL static IOStatus (*dl_write_vec)(const char*, r_vec*) = NULL; IOStatus write_mat(const char* filename, mat_t* result) { - if (dl_write_mat==NULL) ssu_load("write_mat", (void **) &dl_write_mat); + cond_ssu_load("write_mat", (void **) &dl_write_mat); return (*dl_write_mat)(filename, result); } IOStatus write_mat_from_matrix(const char* filename, mat_full_fp64_t* result) { - if (dl_write_mat_from_matrix==NULL) ssu_load("write_mat_from_matrix", (void **) &dl_write_mat_from_matrix); + cond_ssu_load("write_mat_from_matrix", (void **) &dl_write_mat_from_matrix); return (*dl_write_mat_from_matrix)(filename, result); } IOStatus write_vec(const char* filename, r_vec* result) { - if (dl_write_vec==NULL) ssu_load("write_vec", (void **) &dl_write_vec); + cond_ssu_load("write_vec", (void **) &dl_write_vec); return (*dl_write_vec)(filename, result); } @@ -452,7 +463,7 @@ IOStatus write_mat_from_matrix_hdf5_fp64_v2(const char* output_filename, mat_ful const char* *stat_method_arr, const char* *stat_name_arr, const double *stat_val_arr, const double *stat_pval_arr, const unsigned int *stat_perm_count_arr, const char* *stat_group_name_arr, const unsigned int *stat_group_count_arr) { - if (dl_write_mat_from_matrix_hdf5_fp64_v2==NULL) ssu_load("write_mat_from_matrix_hdf5_fp64_v2", (void **) &dl_write_mat_from_matrix_hdf5_fp64_v2); + cond_ssu_load("write_mat_from_matrix_hdf5_fp64_v2", (void **) &dl_write_mat_from_matrix_hdf5_fp64_v2); return (*dl_write_mat_from_matrix_hdf5_fp64_v2)(output_filename, result, pcoa_dims, save_dist, stat_n_vals, stat_method_arr, stat_name_arr, stat_val_arr, stat_pval_arr, stat_perm_count_arr, @@ -460,7 +471,7 @@ IOStatus write_mat_from_matrix_hdf5_fp64_v2(const char* output_filename, mat_ful } IOStatus write_mat_from_matrix_hdf5_fp64(const char* filename, mat_full_fp64_t* result, unsigned int pcoa_dims, int save_dist) { - if (dl_write_mat_from_matrix_hdf5_fp64==NULL) ssu_load("write_mat_from_matrix_hdf5_fp64", (void **) &dl_write_mat_from_matrix_hdf5_fp64); + cond_ssu_load("write_mat_from_matrix_hdf5_fp64", (void **) &dl_write_mat_from_matrix_hdf5_fp64); return (*dl_write_mat_from_matrix_hdf5_fp64)(filename, result, pcoa_dims, save_dist); } @@ -471,7 +482,7 @@ IOStatus write_mat_from_matrix_hdf5_fp32_v2(const char* output_filename, mat_ful const char* *stat_method_arr, const char* *stat_name_arr, const float *stat_val_arr, const float *stat_pval_arr, const unsigned int *stat_perm_count_arr, const char* *stat_group_name_arr, const unsigned int *stat_group_count_arr) { - if (dl_write_mat_from_matrix_hdf5_fp32_v2==NULL) ssu_load("write_mat_from_matrix_hdf5_fp32_v2", (void **) &dl_write_mat_from_matrix_hdf5_fp32_v2); + cond_ssu_load("write_mat_from_matrix_hdf5_fp32_v2", (void **) &dl_write_mat_from_matrix_hdf5_fp32_v2); return (*dl_write_mat_from_matrix_hdf5_fp32_v2)(output_filename, result, pcoa_dims, save_dist, stat_n_vals, stat_method_arr, stat_name_arr, stat_val_arr, stat_pval_arr, stat_perm_count_arr, @@ -479,7 +490,7 @@ IOStatus write_mat_from_matrix_hdf5_fp32_v2(const char* output_filename, mat_ful } IOStatus write_mat_from_matrix_hdf5_fp32(const char* filename, mat_full_fp32_t* result, unsigned int pcoa_dims, int save_dist) { - if (dl_write_mat_from_matrix_hdf5_fp32==NULL) ssu_load("write_mat_from_matrix_hdf5_fp32", (void **) &dl_write_mat_from_matrix_hdf5_fp32); + cond_ssu_load("write_mat_from_matrix_hdf5_fp32", (void **) &dl_write_mat_from_matrix_hdf5_fp32); return (*dl_write_mat_from_matrix_hdf5_fp32)(filename, result, pcoa_dims, save_dist); } @@ -494,7 +505,7 @@ ComputeStatus one_dense_pair_v2t(unsigned int n_obs, const char ** obs_ids, cons const opaque_bptree_t* tree_data, const char* unifrac_method, bool variance_adjust, double alpha, bool bypass_tips, double* result) { - if (dl_one_dense_pair_v2t==NULL) ssu_load("one_dense_pair_v2t", (void **) &dl_one_dense_pair_v2t); + cond_ssu_load("one_dense_pair_v2t", (void **) &dl_one_dense_pair_v2t); return (*dl_one_dense_pair_v2t)(n_obs,obs_ids,sample1,sample2,tree_data,unifrac_method,variance_adjust,alpha,bypass_tips,result); } @@ -503,7 +514,7 @@ ComputeStatus one_dense_pair_v2(unsigned int n_obs, const char ** obs_ids, const const support_bptree_t* tree_data, const char* unifrac_method, bool variance_adjust, double alpha, bool bypass_tips, double* result) { - if (dl_one_dense_pair_v2==NULL) ssu_load("one_dense_pair_v2", (void **) &dl_one_dense_pair_v2); + cond_ssu_load("one_dense_pair_v2", (void **) &dl_one_dense_pair_v2); return (*dl_one_dense_pair_v2)(n_obs,obs_ids,sample1,sample2,tree_data,unifrac_method,variance_adjust,alpha,bypass_tips,result); } @@ -523,44 +534,44 @@ ComputeStatus partial(const char* biom_filename, const char* tree_filename, const char* unifrac_method, bool variance_adjust, double alpha, bool bypass_tips, unsigned int n_substeps, unsigned int stripe_start, unsigned int stripe_stop, partial_mat_t** result) { - if (dl_partial==NULL) ssu_load("partial", (void **) &dl_partial); + cond_ssu_load("partial", (void **) &dl_partial); return (*dl_partial)(biom_filename,tree_filename,unifrac_method,variance_adjust,alpha, bypass_tips,n_substeps,stripe_start,stripe_stop,result); } MergeStatus merge_partial_to_mmap_matrix(partial_dyn_mat_t* * partial_mats, int n_partials, const char *mmap_dir, mat_full_fp64_t** result) { - if (dl_merge_partial_to_mmap_matrix==NULL) ssu_load("merge_partial_to_mmap_matrix", (void **) &dl_merge_partial_to_mmap_matrix); + cond_ssu_load("merge_partial_to_mmap_matrix", (void **) &dl_merge_partial_to_mmap_matrix); return (*dl_merge_partial_to_mmap_matrix)(partial_mats,n_partials,mmap_dir,result); } MergeStatus merge_partial_to_mmap_matrix_fp32(partial_dyn_mat_t* * partial_mats, int n_partials, const char *mmap_dir, mat_full_fp32_t** result) { - if (dl_merge_partial_to_mmap_matrix_fp32==NULL) ssu_load("merge_partial_to_mmap_matrix_fp32", (void **) &dl_merge_partial_to_mmap_matrix_fp32); + cond_ssu_load("merge_partial_to_mmap_matrix_fp32", (void **) &dl_merge_partial_to_mmap_matrix_fp32); return (*dl_merge_partial_to_mmap_matrix_fp32)(partial_mats,n_partials,mmap_dir,result); } MergeStatus validate_partial(const partial_dyn_mat_t* const * partial_mats, int n_partials) { - if (dl_validate_partial==NULL) ssu_load("validate_partial", (void **) &dl_validate_partial); + cond_ssu_load("validate_partial", (void **) &dl_validate_partial); return (*dl_validate_partial)(partial_mats,n_partials); } IOStatus read_partial_header(const char* input_filename, partial_dyn_mat_t** result_out) { - if (dl_read_partial_header==NULL) ssu_load("read_partial_header", (void **) &dl_read_partial_header); + cond_ssu_load("read_partial_header", (void **) &dl_read_partial_header); return (*dl_read_partial_header)(input_filename,result_out); } IOStatus read_partial_one_stripe(partial_dyn_mat_t* result, uint32_t stripe_idx) { - if (dl_read_partial_one_stripe==NULL) ssu_load("read_partial_one_stripe", (void **) &dl_read_partial_one_stripe); + cond_ssu_load("read_partial_one_stripe", (void **) &dl_read_partial_one_stripe); return (*dl_read_partial_one_stripe)(result,stripe_idx); } IOStatus write_partial(const char* filename, const partial_mat_t* result) { - if (dl_write_partial==NULL) ssu_load("write_partial", (void **) &dl_write_partial); + cond_ssu_load("write_partial", (void **) &dl_write_partial); return (*dl_write_partial)(filename,result); } diff --git a/src/unifrac_internal.cpp b/src/unifrac_internal.cpp index f068ca9..e77924c 100644 --- a/src/unifrac_internal.cpp +++ b/src/unifrac_internal.cpp @@ -20,7 +20,7 @@ #include "unifrac_internal.hpp" -static pthread_mutex_t printf_mutex; +static pthread_mutex_t printf_mutex = PTHREAD_MUTEX_INITIALIZER; static bool* report_status; static int sync_printf(const char *format, ...) { From 817b7d732e514ca362328f40592b44d8cc68f3e1 Mon Sep 17 00:00:00 2001 From: Igor Sfiligoi Date: Thu, 23 Jan 2025 17:12:17 -0800 Subject: [PATCH 5/7] Make ssu and faithpd use the shared library --- Makefile | 28 +++++++++++----------------- combined/Makefile | 4 +--- combined/faithpd | 44 -------------------------------------------- combined/ssu | 47 ----------------------------------------------- src/Makefile | 19 +++++++++++-------- 5 files changed, 23 insertions(+), 119 deletions(-) delete mode 100755 combined/faithpd delete mode 100755 combined/ssu diff --git a/Makefile b/Makefile index 13d068b..8b04e98 100644 --- a/Makefile +++ b/Makefile @@ -6,20 +6,20 @@ PLATFORM := $(shell uname -s) COMPILER := $(shell ($(CXX) -v 2>&1) | tr A-Z a-z ) ifeq ($(PLATFORM),Darwin) -all: api main install test_binaries +all: api install main install_main test_binaries else # Note: important that all_nv is after all_cpu_basic and all_nv_avx2 for tests to work all: all_cpu_basic all_nv_avx2 all_nv all_combined test_binaries_nv -all_cpu_basic: api_cpu_basic main_cpu_basic install_cpu_basic +all_cpu_basic: api_cpu_basic install_cpu_basic -all_nv: api_nv main_nv install_nv +all_nv: api_nv install_nv -all_nv_avx2: api_nv_avx2 main_nv_avx2 install_nv_avx2 +all_nv_avx2: api_nv_avx2 install_nv_avx2 -all_combined: api_combined install_combined +all_combined: api_combined install_combined main install_main endif @@ -50,28 +50,22 @@ api_combined: main: cd src && make main -main_cpu_basic: - export BUILD_VARIANT=cpu_basic ; export BUILD_FULL_OPTIMIZATION=False ; cd src && make main - -main_nv: - . ./setup_nv_h5.sh; export BUILD_VARIANT=nv ; export BUILD_FULL_OPTIMIZATION=False ; cd src && make main - -main_nv_avx2: - . ./setup_nv_h5.sh; export BUILD_VARIANT=nv_avx2 ; export BUILD_FULL_OPTIMIZATION=True ; cd src && make main +install_main: + cd src && make install ########### install install: - cd src && make install + cd src && make install_lib install_cpu_basic: - export BUILD_VARIANT=cpu_basic ; export BUILD_FULL_OPTIMIZATION=False ; cd src && make install + export BUILD_VARIANT=cpu_basic ; export BUILD_FULL_OPTIMIZATION=False ; cd src && make install_lib install_nv: - . ./setup_nv_h5.sh; export BUILD_VARIANT=nv ; export BUILD_FULL_OPTIMIZATION=False ; cd src && make install + . ./setup_nv_h5.sh; export BUILD_VARIANT=nv ; export BUILD_FULL_OPTIMIZATION=False ; cd src && make install_lib install_nv_avx2: - . ./setup_nv_h5.sh; export BUILD_VARIANT=nv_avx2 ; export BUILD_FULL_OPTIMIZATION=True ; cd src && make install + . ./setup_nv_h5.sh; export BUILD_VARIANT=nv_avx2 ; export BUILD_FULL_OPTIMIZATION=True ; cd src && make install_lib install_combined: cd combined && make install diff --git a/combined/Makefile b/combined/Makefile index 7abbc31..3ca03f9 100644 --- a/combined/Makefile +++ b/combined/Makefile @@ -19,9 +19,7 @@ libssu.so: libssu.o $(CC) -shared -o libssu.so libssu.o -fPIC -ldl $(LDFLAGS) install: libssu.so - rm -f ${PREFIX}/lib//libssu.so; cp libssu.so ${PREFIX}/lib/ - rm -f ${PREFIX}/bin/ssu; cp ssu ${PREFIX}/bin/ - rm -f ${PREFIX}/bin/faithpd; cp faithpd ${PREFIX}/bin/ + rm -f ${PREFIX}/lib/libssu.so; cp libssu.so ${PREFIX}/lib/ clean: rm -f libssu.o libssu.so diff --git a/combined/faithpd b/combined/faithpd deleted file mode 100755 index b6bbf48..0000000 --- a/combined/faithpd +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/bash - -#default -FPD=faithpd_nv - -# Need at least AVX to support GPUs -if [ "${UNIFRAC_MAX_CPU}" == "basic" ]; then - has_no_avx=1 -else - cat /proc/cpuinfo |grep flags |head -1 | grep -q avx - has_no_avx=$? -fi - -if [ "${has_no_avx}" -eq 1 ]; then - FPD=faithpd_cpu_basic -else - -if [ "${UNIFRAC_MAX_CPU}" == "avx" ]; then - has_no_avx2=1 -else - cat /proc/cpuinfo |grep flags |head -1 | grep -q avx2 - has_no_avx2=$? -fi - -if [ "${has_no_avx2}" -eq 1 ]; then - FPD=faithpd_nv -else - FPD=faithpd_nv_avx2 -fi # if "${has_no_avx2}" -eq 1 - - -fi # if "${has_no_avx}" -eq 1 - -if [ "${UNIFRAC_CPU_INFO}" == "Y" ]; then - echo "INFO (unifrac): Using executable" ${FPD} -fi - -# -# -# -BASEDIR=$(dirname "$0") - -exec ${BASEDIR}/${FPD} "$@" - diff --git a/combined/ssu b/combined/ssu deleted file mode 100755 index 1e8f8b1..0000000 --- a/combined/ssu +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash - -#default -SSU=ssu_nv - -# Need at least AVX to support GPUs -if [ "${UNIFRAC_MAX_CPU}" == "basic" ]; then - has_no_avx=1 -else - cat /proc/cpuinfo |grep flags |head -1 | grep -q avx - has_no_avx=$? -fi - -if [ "${has_no_avx}" -eq 1 ]; then - if [ "${UNIFRAC_GPU_INFO}" == "Y" ]; then - echo "INFO (unifrac): CPU too old, disabling GPU" - fi - SSU=ssu_cpu_basic -else - -if [ "${UNIFRAC_MAX_CPU}" == "avx" ]; then - has_no_avx2=1 -else - cat /proc/cpuinfo |grep flags |head -1 | grep -q avx2 - has_no_avx2=$? -fi - -if [ "${has_no_avx2}" -eq 1 ]; then - SSU=ssu_nv -else - SSU=ssu_nv_avx2 -fi # if "${has_no_avx2}" -eq 1 - - -fi # if "${has_no_avx}" -eq 1 - -if [ "${UNIFRAC_CPU_INFO}" == "Y" ]; then - echo "INFO (unifrac): Using executable" ${SSU} -fi - -# -# -# -BASEDIR=$(dirname "$0") - -exec ${BASEDIR}/${SSU} "$@" - diff --git a/src/Makefile b/src/Makefile index 655f50c..a1767c3 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,4 +1,4 @@ -.PHONY: all main api test test_binaries install clean rapi_test +.PHONY: all main api test test_binaries install install_lib clean rapi_test CXX := h5c++ @@ -138,7 +138,7 @@ endif CPPFLAGS += -Wall -std=c++17 -pedantic -I. $(OPT) -fPIC -L$(PREFIX)/lib -all: api main install +all: api install_lib main install main: $(SSU) $(FPD) @@ -153,11 +153,11 @@ test_ska: test_ska.cpp tree.o tsv.o test_su.cpp biom.o biom_inmem.o biom_subsamp test_api: test_api.cpp tree.o tsv.o test_su.cpp biom.o biom_inmem.o biom_subsampled.o unifrac.o skbio_alt.o api.o $(UNIFRAC_FILES) $(CXX) $(CPPFLAGS) $(EXEFLAGS) test_api.cpp -o test_api tree.o biom.o biom_inmem.o biom_subsampled.o tsv.o $(UNIFRAC_FILES) unifrac.o skbio_alt.o api.o -llz4 $(BLASLIB) -lpthread -$(SSU): su.cpp tree.o biom.o biom_inmem.o biom_subsampled.o tsv.o unifrac.o cmd.o skbio_alt.o api.o $(UNIFRAC_FILES) - $(CXX) $(CPPFLAGS) $(EXEFLAGS) su.cpp -o $(SSU) tree.o biom.o biom_inmem.o biom_subsampled.o tsv.o $(UNIFRAC_FILES) unifrac.o cmd.o skbio_alt.o api.o -lhdf5_cpp -llz4 $(BLASLIB) -lpthread +$(SSU): su.cpp $(PREFIX)/lib/lib$(SSU).so + $(CXX) $(CPPFLAGS) $(EXEFLAGS) su.cpp -o $@ -l$(SSU) -$(FPD): faithpd.cpp tree.o biom.o biom_inmem.o biom_subsampled.o tsv.o unifrac.o cmd.o skbio_alt.o api.o $(UNIFRAC_FILES) - $(CXX) $(CPPFLAGS) $(EXEFLAGS) faithpd.cpp -o $(FPD) tree.o biom.o biom_inmem.o biom_subsampled.o tsv.o $(UNIFRAC_FILES) unifrac.o cmd.o skbio_alt.o api.o -lhdf5_cpp -llz4 $(BLASLIB) -lpthread +$(FPD): faithpd.cpp $(PREFIX)/lib/lib$(SSU).so + $(CXX) $(CPPFLAGS) $(EXEFLAGS) faithpd.cpp -o $@ -l$(SSU) lib$(SSU).so: tree.o biom.o biom_inmem.o biom_subsampled.o tsv.o unifrac.o cmd.o skbio_alt.o api.o $(UNIFRAC_FILES) $(CXX) $(LDDFLAGS) -o lib$(SSU).so tree.o biom.o biom_inmem.o biom_subsampled.o tsv.o $(UNIFRAC_FILES) unifrac.o cmd.o skbio_alt.o api.o -lc -llz4 $(BLASLIB) -L$(PREFIX)/lib -noshlib -lhdf5_cpp -lhdf5_hl_cpp -lhdf5_hl -lhdf5 @@ -195,8 +195,11 @@ test: test_binaries ./test_ska ./test_api -install: lib$(SSU).so $(SSU) $(FPD) - rm -f ${PREFIX}/lib//lib$(SSU).so; cp lib$(SSU).so ${PREFIX}/lib/ +install_lib: lib$(SSU).so + rm -f ${PREFIX}/lib/lib$(SSU).so; cp lib$(SSU).so ${PREFIX}/lib/ + + +install: $(SSU) $(FPD) rm -f ${PREFIX}/bin/$(SSU); cp $(SSU) ${PREFIX}/bin/ rm -f ${PREFIX}/bin/$(FPD); cp $(FPD) ${PREFIX}/bin/ mkdir -p ${PREFIX}/include/unifrac From 518c319c6f81e854f87e0680e0c91f454c2392d0 Mon Sep 17 00:00:00 2001 From: Igor Sfiligoi Date: Thu, 23 Jan 2025 17:41:11 -0800 Subject: [PATCH 6/7] Add missing header include --- src/su.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/su.cpp b/src/su.cpp index 66e69ad..f12cadc 100644 --- a/src/su.cpp +++ b/src/su.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include From b45d9dcc6dab9dea943fb711bd2e30994a0ce73a Mon Sep 17 00:00:00 2001 From: Igor Sfiligoi Date: Thu, 23 Jan 2025 18:01:02 -0800 Subject: [PATCH 7/7] Use explicit object list in rapi_test dependency --- src/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Makefile b/src/Makefile index a1767c3..d9f7aaf 100644 --- a/src/Makefile +++ b/src/Makefile @@ -153,10 +153,10 @@ test_ska: test_ska.cpp tree.o tsv.o test_su.cpp biom.o biom_inmem.o biom_subsamp test_api: test_api.cpp tree.o tsv.o test_su.cpp biom.o biom_inmem.o biom_subsampled.o unifrac.o skbio_alt.o api.o $(UNIFRAC_FILES) $(CXX) $(CPPFLAGS) $(EXEFLAGS) test_api.cpp -o test_api tree.o biom.o biom_inmem.o biom_subsampled.o tsv.o $(UNIFRAC_FILES) unifrac.o skbio_alt.o api.o -llz4 $(BLASLIB) -lpthread -$(SSU): su.cpp $(PREFIX)/lib/lib$(SSU).so +$(SSU): su.cpp api.hpp biom.hpp $(PREFIX)/lib/lib$(SSU).so $(CXX) $(CPPFLAGS) $(EXEFLAGS) su.cpp -o $@ -l$(SSU) -$(FPD): faithpd.cpp $(PREFIX)/lib/lib$(SSU).so +$(FPD): faithpd.cpp api.hpp $(PREFIX)/lib/lib$(SSU).so $(CXX) $(CPPFLAGS) $(EXEFLAGS) faithpd.cpp -o $@ -l$(SSU) lib$(SSU).so: tree.o biom.o biom_inmem.o biom_subsampled.o tsv.o unifrac.o cmd.o skbio_alt.o api.o $(UNIFRAC_FILES) @@ -207,7 +207,7 @@ install: $(SSU) $(FPD) rm -f ${PREFIX}/include/unifrac/api.hpp; cp api.hpp ${PREFIX}/include/unifrac/ rm -f ${PREFIX}/include/unifrac/status_enum.hpp; cp status_enum.hpp ${PREFIX}/include/unifrac/ -rapi_test: main +rapi_test: tree.o biom.o biom_inmem.o biom_subsampled.o tsv.o unifrac.o cmd.o skbio_alt.o api.o $(UNIFRAC_FILES) mkdir -p ~/.R if [ -e ~/.R/Makevars ] ; \ then \