CMU-SAFARI / Scrooge

Scrooge is a high-performance pairwise sequence aligner based on the GenASM algorithm. Scrooge includes three novel algorithmic improvements on top of GenASM, and high-performance CPU and GPU implementations. Described by Lindegger et al. at https://doi.org/10.48550/arXiv.2208.09985
MIT License
37 stars 4 forks source link

Simple C example (how to use scrooge) #5

Open smarco opened 1 year ago

smarco commented 1 year ago

Hi,

Would it be possible to have a small example on how to use scrooge from C/C++?

I am not sure what function to call, I cannot find anything called/prefixed scrooge on the repo. I can find calls to genasm function. What should I try?

Perhaps on genasm_cpu.cpp

std::vector<Alignment_t> align_all(vector<string> &texts, vector<string> &queries, int threads, long long* core_algorithm_ns)

Let me know, I would like to try scrooge.

joellindegger commented 1 year ago

Hi Santiago

We have brief examples for each supported interface here: https://github.com/CMU-SAFARI/Scrooge/blob/main/src/library_example.cu By default, our implementation has the best combinations of improvements on top of the GenASM enabled for CPU and GPU respectively, i.e., using these interfaces as is runs the Scrooge algorithm.

If you would like to try a different set of algorithmic improvements (e.g., disable all of them so it behaves like the baseline GenASM algorithm), you can do so by either (1) commenting out the respective C macro definitions in the CPU and GPU implementations (e.g., like here for DENT), or (2) passing macro definitions to the compiler from the command line like we do here for our parameter sweep evaluation.

Best, Joel

smarco commented 1 year ago

Hi,

For the moment, I guess, I'm using defaults.

extern "C" void benchmark_scrooge_bridge(
    char* const pattern,
    const int pattern_length,
    char* const text,
    const int text_length,
    char* const edit_operations,
    int* const num_edit_operations,
    uint64_t* const time_ns) {
  // Parameters
  std::vector<std::string> texts;
  std::vector<std::string> queries;

  // Prepare data
  texts.push_back(string(text,text_length));
  queries.push_back(string(pattern,pattern_length));

  // Align
  long long core_algorithm_ns;
  vector<Alignment_t> alignments = genasm_cpu::align_all(texts,queries,1,&core_algorithm_ns);
  fprintf(stderr,"[Scrooge::debug]>>%s\n",alignments[0].cigar.c_str());
  *time_ns = core_algorithm_ns;

  // Process alignment
  benchmark_scrooge_adapt_cigar(
      pattern_length,text_length,(char*)alignments[0].cigar.c_str(),
      edit_operations,num_edit_operations);
}

Does it look right to you?

joellindegger commented 1 year ago

Yes, this looks functionally correct to me. Note that the throughput will not be ideal if pairs are passed one-by-one. E.g., on the CPU, there will be at least an unnecessary repetition of malloc calls.

smarco commented 1 year ago

Ok, I see the mallocs inside. I will ignore the preprocessing steps and mallocs to make a fair comparison.