Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix arm neon support #33

Merged
merged 5 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 33 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,27 +108,43 @@ add_custom_command(
$<TARGET_FILE_DIR:awfmindex_static>
)

# Set common compiler options
target_compile_options(
awfmindex_static
PRIVATE
-mtune=native
-march=native
-mavx2
-Wall
-Wextra
${OpenMP_C_FLAGS}
awfmindex_static
PRIVATE
-mtune=native
-march=native
-Wall
-Wextra
${OpenMP_C_FLAGS}
)

target_compile_options(
awfmindex
PRIVATE
-mtune=native
-march=native
-mavx2
-Wall
-Wextra
${OpenMP_C_FLAGS}
)
awfmindex
PRIVATE
-mtune=native
-march=native
-Wall
-Wextra
${OpenMP_C_FLAGS}
)

# Check if the target architecture is x86_64 (Intel) or aarch64 (ARM)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
# Check if the compiler supports AVX2
include(CheckCCompilerFlag)
CHECK_C_COMPILER_FLAG("-mavx2" COMPILER_SUPPORTS_AVX2)

if(COMPILER_SUPPORTS_AVX2)
# Set AVX2 flags for x86_64 (Intel)
target_compile_options(awfmindex_static PRIVATE -mavx2)
target_compile_options(awfmindex PRIVATE -mavx2)
endif()
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
# Set NEON flags for ARM
target_compile_options(awfmindex_static PRIVATE -march=armv8-a+simd)
target_compile_options(awfmindex PRIVATE -march=armv8-a+simd)
endif()

install(
TARGETS awfmindex awfmindex_static
Expand Down
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,37 @@ it manually for either the CMake or legacy Make builds.

```
git clone https://github.com/TravisWheelerLab/AvxWindowFmIndex.git
git submodule init
git submodule update
git submodule update --init --recursive --remote
```

Now the project is ready to build.

## CMake Build

The default way to build AwFmIndex is to use CMake. The usual CMake incantations
will work. This will result in both shared and static libraries written to the
will work. This will result in both shared libraries written to the
`build/` directory.

```
cmake .
make
```

to instead make static libraries, set the BUILD_SHARED_LIBS variable as follows:
```
cmake -DBUILD_SHARED_LIBS=OFF .
make
```


If you want both, it's eas easy as running both back-to-back
```
cmake -DBUILD_SHARED_LIBS=OFF .
make
cmake -DBUILD_SHARED_LIBS=ON .
make
```

To install on MacOS, you will need to specify the install location of your
GCC compiler. An Example is given below:

Expand Down
6 changes: 2 additions & 4 deletions test/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
These tests are mostly stand-alone, and do not require the AwFmIndex library to be installed. However, some of these tests require libdivsufsort64 to be installed in a find-able location. Before running these tests, install libdivsufsort64 as a shared library in a manner consistent with the library's readme. Note that the 64-bit version is required, and so the cmake call requires the DBUILD_DIVSUFSORT64 flag to be set:

These tests require that the project be built for static libraries. Nothing needs to be installed for these to function. To build the static libraries, cd into the project's home directory and run
'''
cd build
cmake -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_BUILD_TYPE="Release" -DUSE_OPENMP="ON" -DBUILD_SHARED_LIBS="ON" -DBUILD_DIVSUFSORT64:BOOL=ON .. && make
cmake -DBUILD_SHARED_LIBS="OFF" . && make
'''
4 changes: 2 additions & 2 deletions test/backtraceTest/backtraceTest.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "../../lib/FastaVector/src/FastaVector.h"
#include "../../lib/libdivsufsort/build/include/divsufsort64.h"
#include "../../build/FastaVector.h"
#include "../../build/divsufsort64.h"
#include "../../src/AwFmCreate.h"
#include "../../src/AwFmIndex.h"
#include "../../src/AwFmIndexStruct.h"
Expand Down
6 changes: 4 additions & 2 deletions test/backtraceTest/makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
TEST_SRC = backtraceTest.c
SRC = $(wildcard ../../src/*.c)


CFLAGS = -std=c11 -fsanitize=address -Wall -mtune=native -fopenmp -mavx2 -O3
LDLIBS = ../../lib/FastaVector/build/libfastavector_static.a ../../lib/libdivsufsort/build/lib/libdivsufsort64.a
LDFLAGS = -L../../build
LDLIBS = -lfastavector_static -ldivsufsort64

EXE = backtraceTest.out

backtraceTest: $(SRC)
gcc $(TEST_SRC) $(SRC) -o $(EXE) $(CFLAGS) $(LDLIBS)
gcc $(TEST_SRC) $(SRC) -o $(EXE) $(CFLAGS) $(LDFLAGS) $(LDLIBS)

.PHONY: clean
clean:
Expand Down
2 changes: 1 addition & 1 deletion test/bwtTest/bwtTest.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <string.h>
#include <time.h>

#include "../../lib/libdivsufsort/build/include/divsufsort64.h"
#include "../../build/divsufsort64.h"
#include "../../src/AwFmCreate.h"
#include "../../src/AwFmIndex.h"
#include "../../src/AwFmIndexStruct.h"
Expand Down
2 changes: 1 addition & 1 deletion test/bwtTest/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ TEST_SRC = bwtTest.c
SRC = $(wildcard ../../src/*.c)

CFLAGS = -std=c11 -fsanitize=address -Wall -mtune=native -fopenmp -mavx2 -O3
LDLIBS = ../../lib/FastaVector/build/libfastavector_static.a ../../lib/libdivsufsort/build/lib/libdivsufsort64.a
LDLIBS = ../../build/libfastavector_static.a ../../build/libdivsufsort64.a

EXE = bwtTest.out

Expand Down
2 changes: 1 addition & 1 deletion test/createTests/AwFmCreationTest.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <string.h>
#include <time.h>

#include "../../lib/libdivsufsort/build/include/divsufsort64.h"
#include "../../build/divsufsort64.h"
#include "../../src/AwFmCreate.h"
#include "../../src/AwFmIndex.h"
#include "../../src/AwFmIndexStruct.h"
Expand Down
2 changes: 1 addition & 1 deletion test/createTests/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ TEST_SRC = AwFmCreationTest.c
SRC = $(wildcard ../../src/*.c)

CFLAGS = -std=c11 -fsanitize=address -Wall -mtune=native -fopenmp -mavx2 -O3
LDLIBS = ../../lib/FastaVector/build/libfastavector_static.a ../../lib/libdivsufsort/build/lib/libdivsufsort64.a
LDLIBS = ../../build/libfastavector_static.a ../../build/libdivsufsort64.a

EXE = createTest.out

Expand Down
2 changes: 1 addition & 1 deletion test/fileTests/AwFmFileTests.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <string.h>
#include <time.h>

#include "../../lib/libdivsufsort/build/include/divsufsort64.h"
#include "../../build/divsufsort64.h"
#include "../../src/AwFmCreate.h"
#include "../../src/AwFmIndex.h"
#include "../../src/AwFmIndexStruct.h"
Expand Down
2 changes: 1 addition & 1 deletion test/fileTests/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ TEST_SRC = AwFmFileTests.c
SRC = $(wildcard ../../src/*.c)

CFLAGS = -std=c11 -fsanitize=address -Wall -mtune=native -fopenmp -mavx2 -O3
LDLIBS = ../../lib/FastaVector/build/libfastavector_static.a ../../lib/libdivsufsort/build/lib/libdivsufsort64.a
LDLIBS = ../../build/libfastavector_static.a ../../build/libdivsufsort64.a

EXE = fileTests.out

Expand Down
2 changes: 1 addition & 1 deletion test/inMemorySaTest/inMemorySaTest.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <string.h>
#include <time.h>

#include "../../lib/libdivsufsort/build/include/divsufsort64.h"
#include "../../build/divsufsort64.h"
#include "../../src/AwFmCreate.h"
#include "../../src/AwFmIndex.h"
#include "../../src/AwFmIndexStruct.h"
Expand Down
2 changes: 1 addition & 1 deletion test/inMemorySaTest/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ TEST_SRC = inMemorySaTest.c
SRC = $(wildcard ../../src/*.c)

CFLAGS = -std=c11 -fsanitize=address -Wall -mtune=native -fopenmp -mavx2 -O3
LDLIBS = ../../lib/FastaVector/build/libfastavector_static.a ../../lib/libdivsufsort/build/lib/libdivsufsort64.a
LDLIBS = ../../build/libfastavector_static.a ../../build/libdivsufsort64.a

EXE = saInMemTest.out

Expand Down
2 changes: 1 addition & 1 deletion test/kmerSeedTableTests/kmerSeedTableTests.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <string.h>
#include <time.h>

#include "../../lib/libdivsufsort/build/include/divsufsort64.h"
#include "../../build/divsufsort64.h"
#include "../../src/AwFmCreate.h"
#include "../../src/AwFmIndex.h"
#include "../../src/AwFmIndexStruct.h"
Expand Down
2 changes: 1 addition & 1 deletion test/kmerSeedTableTests/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ TEST_SRC = kmerSeedTableTests.c
SRC = $(wildcard ../../src/*.c)

CFLAGS = -std=c11 -fsanitize=address -Wall -mtune=native -fopenmp -mavx2 -O3
LDLIBS = ../../lib/FastaVector/build/libfastavector_static.a ../../lib/libdivsufsort/build/lib/libdivsufsort64.a
LDLIBS = ../../build/libfastavector_static.a ../../build/libdivsufsort64.a

EXE = kmerSeedTableTests.out

Expand Down
2 changes: 1 addition & 1 deletion test/multiSequenceIndexTest/AwFmMultiSequenceTest.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "../../src/AwFmSuffixArray.h"
#include "../test.h"
#include "FastaVector.h"
// #include "../../libdivsufsort/build/include/divsufsort64.h"
// #include "../../lib/libdivsufsort/include/divsufsort64.h"


char buffer[2048];
Expand Down
2 changes: 1 addition & 1 deletion test/multiSequenceIndexTest/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ TEST_SRC = AwFmMultiSequenceTest.c
SRC = $(wildcard ../../src/*.c)

CFLAGS = -std=c11 -fsanitize=address -Wall -mtune=native -fopenmp -mavx2 -O0 -g
LDLIBS = ../../lib/FastaVector/build/libfastavector_static.a ../../lib/libdivsufsort/build/lib/libdivsufsort64.a
LDLIBS = ../../build/libfastavector_static.a ../../build/libdivsufsort64.a

EXE = multiSequenceTest.out

Expand Down
2 changes: 1 addition & 1 deletion test/occurrenceTests/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ TEST_SRC = occurrenceTests.c
SRC = $(wildcard ../../src/*.c)

CFLAGS = -std=c11 -fsanitize=address -Wall -mtune=native -fopenmp -mavx2 -O0 -g
LDLIBS = ../../lib/FastaVector/build/libfastavector_static.a ../../lib/libdivsufsort/build/lib/libdivsufsort64.a
LDLIBS = ../../build/libfastavector_static.a ../../build/libdivsufsort64.a

EXE = occurrenceTests.out

Expand Down
2 changes: 1 addition & 1 deletion test/occurrenceTests/occurrenceTests.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <stdlib.h>
#include <time.h>

#include "../../lib/libdivsufsort/build/include/divsufsort64.h"
#include "../../build/divsufsort64.h"
#include "../../src/AwFmCreate.h"
#include "../../src/AwFmIndex.h"
#include "../../src/AwFmIndexStruct.h"
Expand Down
2 changes: 1 addition & 1 deletion test/parallelSearch/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ TEST_SRC = parallelSearchTest.c
SRC = $(wildcard ../../src/*.c)

CFLAGS = -std=c11 -fsanitize=address -Wall -mtune=native -fopenmp -mavx2 -O0 -g
LDLIBS = ../../lib/FastaVector/build/libfastavector_static.a ../../lib/libdivsufsort/build/lib/libdivsufsort64.a
LDLIBS = ../../build/libfastavector_static.a ../../build/libdivsufsort64.a

EXE = parallelSearchTest.out

Expand Down
2 changes: 1 addition & 1 deletion test/parallelSearch/parallelSearchTest.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "../../src/AwFmSearch.h"
#include "../../src/AwFmSuffixArray.h"
#include "../test.h"
#include "divsufsort64.h"
#include "../../build/divsufsort64.h"

char buffer[2048];
uint8_t aminoLookup[21] = {
Expand Down
8 changes: 6 additions & 2 deletions test/searchTest/makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
TEST_SRC = searchTest.c
SRC = $(wildcard ../../src/*.c)
CFLAGS = -std=c11 -fsanitize=address -Wall -mtune=native -g -fopenmp -ldivsufsort64 -lfastavector -mavx2 -L../../lib/libdivsufsort/build/lib

CFLAGS = -std=c11 -fsanitize=address -Wall -mtune=native -fopenmp -mavx2 -O0 -g
LDLIBS = ../../build/libfastavector_static.a ../../build/libdivsufsort64.a

EXE = searchTest.out

bwtTest: $(SRC)
gcc $(TEST_SRC) $(SRC) -o $(EXE) $(CFLAGS)
gcc $(TEST_SRC) $(SRC) -o $(EXE) $(CFLAGS) $(LDLIBS)
10 changes: 5 additions & 5 deletions test/searchTest/searchTest.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <string.h>
#include <time.h>

#include "../../libdivsufsort/build/include/divsufsort64.h"
#include "../../build/divsufsort64.h"
#include "../../src/AwFmCreate.h"
#include "../../src/AwFmIndex.h"
#include "../../src/AwFmIndexStruct.h"
Expand Down Expand Up @@ -69,7 +69,7 @@ int main(int argc, char **argv) {
void generateRandomIndex(struct AwFmIndex **index, uint8_t **sequence, size_t sequenceLength, uint64_t **suffixArray) {
printf("generating random index.\n");
// decide if we're building a nucleotide or amino index.
enum AwFmAlphabetType alphabetType = (rand() & 1) ? AwFmAlphabetNucleotide : AwFmAlphabetAmino;
enum AwFmAlphabetType alphabetType = (rand() & 1) ? AwFmAlphabetDna : AwFmAlphabetAmino;
struct AwFmIndexConfiguration config = {.suffixArrayCompressionRatio = 200,
.kmerLengthInSeedTable = 4,
.alphabetType = alphabetType,
Expand All @@ -90,7 +90,7 @@ void generateRandomIndex(struct AwFmIndex **index, uint8_t **sequence, size_t se
exit(-2);
}

uint8_t *characterLookupTable = alphabetType == AwFmAlphabetNucleotide ? nucleotideLookup : aminoLookup;
uint8_t *characterLookupTable = alphabetType == AwFmAlphabetDna ? nucleotideLookup : aminoLookup;
uint8_t alphabetCardinalty = awFmGetAlphabetCardinality(alphabetType);
for(size_t i = 0; i < sequenceLength; i++) {
uint8_t characterIndex = rand() % (alphabetCardinalty + 1); //+1 is for ambiguity character
Expand Down Expand Up @@ -121,7 +121,7 @@ void testSearchForRandomKmers(
// build the kmer.
// printf("nuclookup ptr %p, amino %p, index p: %p\n", nucleotideLookup, aminoLookup, index);
uint8_t *characterLookupTable =
(index->config.alphabetType == AwFmAlphabetNucleotide) ? &nucleotideLookup[0] : &aminoLookup[0];
(index->config.alphabetType == AwFmAlphabetDna) ? &nucleotideLookup[0] : &aminoLookup[0];
uint8_t alphabetCardinalty = awFmGetAlphabetCardinality(index->config.alphabetType);
for(size_t i = 0; i < kmerLength; i++) {
kmer[i] = characterLookupTable[rand() % alphabetCardinalty];
Expand Down Expand Up @@ -181,5 +181,5 @@ void testRangeForCorrectness(const struct AwFmSearchRange *range, const uint8_t

struct AwFmSearchRange findRangeForKmer(
const struct AwFmIndex *_RESTRICT_ const index, const char *kmer, const uint64_t kmerLength) {
return awFmDatabaseSingleKmerExactMatch(index, kmer, kmerLength);
return awFmFindSearchRangeForString(index, kmer, kmerLength);
}
2 changes: 1 addition & 1 deletion test/suffixArrayCompressionTests/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ TEST_SRC = saTest.c
SRC = $(wildcard ../../src/*.c)

CFLAGS = -std=c11 -fsanitize=address -Wall -mtune=native -fopenmp -mavx2 -O0 -g
LDLIBS = ../../lib/FastaVector/build/libfastavector_static.a ../../lib/libdivsufsort/build/lib/libdivsufsort64.a
LDLIBS = ../../build/libfastavector_static.a ../../build/libdivsufsort64.a

EXE = saTest.out

Expand Down