Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
PyFastANI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Martin Larralde
PyFastANI
Commits
33cd43de
Commit
33cd43de
authored
3 years ago
by
Martin Larralde
Browse files
Options
Downloads
Patches
Plain Diff
Fix missing defines in compilation of `cpu_features` library
parent
7acb214b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
pyfastani/_sequtils/sequtils.c
+0
-80
0 additions, 80 deletions
pyfastani/_sequtils/sequtils.c
pyfastani/_sequtils/sequtils.cpp
+86
-0
86 additions, 0 deletions
pyfastani/_sequtils/sequtils.cpp
setup.py
+74
-3
74 additions, 3 deletions
setup.py
with
160 additions
and
83 deletions
pyfastani/_sequtils/sequtils.c
deleted
100644 → 0
+
0
−
80
View file @
7acb214b
#include
<ctype.h>
#include
<stddef.h>
#include
"sequtils.h"
#include
"complement.h"
#if defined(__X86__) || defined(__X86_64__)
#include
"cpu_features_x86.h"
static
const
X86Features
features
=
GetX86Info
().
features
;
#endif
#ifdef __arm__
#include
"cpu_features_arm.h"
static
const
ArmFeatures
features
=
GetArmInfo
().
features
;
#endif
#ifdef __aarch64__
#include
"cpu_features_aarch64.h"
static
const
Aarch64Features
features
=
GetAarch64Info
().
features
;
#endif
// --- Fast copy with uppercase ----------------------------------------------
void
default_copy_upper
(
char
*
dst
,
const
char
*
src
,
size_t
len
)
{
while
(
len
>
16
)
{
for
(
size_t
i
=
0
;
i
<
16
;
++
i
)
{
*
dst
=
toupper
(
*
src
);
src
++
;
dst
++
;
}
len
-=
16
;
}
while
(
len
--
>
0
)
{
*
dst
=
toupper
(
*
src
);
src
++
;
dst
++
;
}
}
void
copy_upper
(
char
*
dst
,
const
char
*
src
,
size_t
len
)
{
#ifdef __arm__
if
(
features
.
neon
)
return
neon_copy_upper
(
dst
,
src
,
len
);
else
#endif
#ifdef __aarch64__
if
(
features
.
neon
)
return
neon_copy_upper
(
dst
,
src
,
len
);
else
#endif
#if defined(__X86__) || defined(__X86_64__)
if
(
features
.
sse2
)
return
sse2_copy_upper
(
dst
,
src
,
len
);
// fast copying plus upper.
else
#endif
return
default_copy_upper
(
dst
,
src
,
len
);
}
// --- Fast reverse complement -----------------------------------------------
void
default_reverse_complement
(
char
*
dst
,
const
char
*
src
,
size_t
len
)
{
while
(
len
>
16
)
{
for
(
size_t
i
=
0
;
i
<
16
;
++
i
)
{
*
dst
=
complement
(
src
[
--
len
]);
dst
++
;
}
}
while
(
len
>
0
)
{
*
dst
=
complement
(
src
[
--
len
]);
dst
++
;
}
}
void
reverse_complement
(
char
*
dst
,
const
char
*
src
,
size_t
len
)
{
#if defined(__X86__) || defined(__X86_64__)
if
(
features
.
ssse3
)
return
ssse3_reverse_complement
(
dst
,
src
,
len
);
// fast reverse complement.
else
#endif
return
default_reverse_complement
(
dst
,
src
,
len
);
}
This diff is collapsed.
Click to expand it.
pyfastani/_sequtils/sequtils.cpp
0 → 100644
+
86
−
0
View file @
33cd43de
#include
<ctype.h>
#include
<stddef.h>
#include
"sequtils.h"
#include
"complement.h"
#if defined(__x86__) || defined(__x86_64__)
#include
"cpuinfo_x86.h"
using
namespace
cpu_features
;
static
const
X86Features
features
=
GetX86Info
().
features
;
#endif
#ifdef __arm__
#include
"cpuinfo_arm.h"
using
namespace
cpu_features
;
static
const
ArmFeatures
features
=
GetArmInfo
().
features
;
#endif
#ifdef __aarch64__
#include
"cpuinfo_aarch64.h"
using
namespace
cpu_features
;
static
const
Aarch64Features
features
=
GetAarch64Info
().
features
;
#endif
extern
"C"
{
// --- Fast copy with uppercase --------------------------------------------
void
default_copy_upper
(
char
*
dst
,
const
char
*
src
,
size_t
len
)
{
while
(
len
>
16
)
{
for
(
size_t
i
=
0
;
i
<
16
;
++
i
)
{
*
dst
=
toupper
(
*
src
);
src
++
;
dst
++
;
}
len
-=
16
;
}
while
(
len
--
>
0
)
{
*
dst
=
toupper
(
*
src
);
src
++
;
dst
++
;
}
}
void
copy_upper
(
char
*
dst
,
const
char
*
src
,
size_t
len
)
{
#ifdef __arm__
if
(
features
.
neon
)
return
neon_copy_upper
(
dst
,
src
,
len
);
else
#endif
#ifdef __aarch64__
if
(
features
.
neon
)
return
neon_copy_upper
(
dst
,
src
,
len
);
else
#endif
#if defined(__x86__) || defined(__x86_64__)
if
(
features
.
sse2
)
return
sse2_copy_upper
(
dst
,
src
,
len
);
// fast copying plus upper.
else
#endif
return
default_copy_upper
(
dst
,
src
,
len
);
}
// --- Fast reverse complement ---------------------------------------------
void
default_reverse_complement
(
char
*
dst
,
const
char
*
src
,
size_t
len
)
{
while
(
len
>
16
)
{
for
(
size_t
i
=
0
;
i
<
16
;
++
i
)
{
*
dst
=
complement
(
src
[
--
len
]);
dst
++
;
}
}
while
(
len
>
0
)
{
*
dst
=
complement
(
src
[
--
len
]);
dst
++
;
}
}
void
reverse_complement
(
char
*
dst
,
const
char
*
src
,
size_t
len
)
{
#if defined(__x86__) || defined(__x86_64__)
if
(
features
.
ssse3
)
return
ssse3_reverse_complement
(
dst
,
src
,
len
);
// fast reverse complement.
else
#endif
return
default_reverse_complement
(
dst
,
src
,
len
);
}
}
This diff is collapsed.
Click to expand it.
setup.py
+
74
−
3
View file @
33cd43de
...
@@ -30,6 +30,13 @@ except ImportError as err:
...
@@ -30,6 +30,13 @@ except ImportError as err:
PLATFORM_MACHINE
=
platform
.
machine
()
PLATFORM_MACHINE
=
platform
.
machine
()
SYS_IMPLEMENTATION
=
sys
.
implementation
.
name
SYS_IMPLEMENTATION
=
sys
.
implementation
.
name
UNIX
=
not
sys
.
platform
.
startswith
(
"
win
"
)
PROCESSOR_IS_MIPS
=
PLATFORM_MACHINE
.
startswith
(
"
mips
"
)
PROCESSOR_IS_ARM
=
PLATFORM_MACHINE
.
startswith
(
"
arm
"
)
PROCESSOR_IS_AARCH64
=
PLATFORM_MACHINE
.
startswith
(
"
aarch64
"
)
PROCESSOR_IS_X86
=
PLATFORM_MACHINE
.
startswith
((
"
x86_64
"
,
"
AMD64
"
,
"
amd64
"
,
"
i386
"
,
"
i486
"
))
PROCESSOR_IS_POWER
=
PLATFORM_MACHINE
.
startswith
((
"
powerpc
"
,
"
ppc
"
))
# --- Utils ------------------------------------------------------------------
# --- Utils ------------------------------------------------------------------
...
@@ -140,6 +147,10 @@ class build_clib(_build_clib):
...
@@ -140,6 +147,10 @@ class build_clib(_build_clib):
except
subprocess
.
CalledProcessError
as
err
:
except
subprocess
.
CalledProcessError
as
err
:
raise
CompileError
(
err
.
stderr
)
raise
CompileError
(
err
.
stderr
)
def
_silent_compile
(
self
,
*
args
,
**
kwargs
):
with
mock
.
patch
.
object
(
self
.
compiler
,
"
spawn
"
,
new
=
self
.
_silent_spawn
):
return
self
.
compiler
.
compile
(
*
args
,
**
kwargs
)
# --- Compatibility with base `build_clib` command ---
# --- Compatibility with base `build_clib` command ---
def
check_library_list
(
self
,
libraries
):
def
check_library_list
(
self
,
libraries
):
...
@@ -153,6 +164,55 @@ class build_clib(_build_clib):
...
@@ -153,6 +164,55 @@ class build_clib(_build_clib):
# --- Build code ---
# --- Build code ---
def
_has_dlopen
(
self
):
self
.
mkpath
(
self
.
build_temp
)
filename
=
os
.
path
.
join
(
self
.
build_temp
,
"
test_dlopen.c
"
)
with
open
(
filename
,
"
w
"
)
as
f
:
f
.
write
(
"""
#include <dlfcn.h>
int main() { dlopen(
""
, 0); }
"""
)
try
:
self
.
compiler
.
compile
([
filename
],
debug
=
True
)
except
CompileError
:
log
.
warn
(
"
could not find `dlopen` function from <dlfcn.h>
"
)
return
False
else
:
log
.
info
(
"
found `dlopen` function from <dlfcn.h>
"
)
return
True
def
_has_getauxval
(
self
):
self
.
mkpath
(
self
.
build_temp
)
filename
=
os
.
path
.
join
(
self
.
build_temp
,
"
test_dlopen.c
"
)
with
open
(
filename
,
"
w
"
)
as
f
:
f
.
write
(
"""
#include <sys/getauxval.h>
int main() { getauxval(0); }
"""
)
try
:
self
.
_silent_compile
([
filename
],
debug
=
True
)
except
CompileError
:
log
.
warn
(
"
could not find `getauxval` function from <sys/getauxval.h>
"
)
return
False
else
:
log
.
info
(
"
found `getauxval` function from <sys/getauxval.h>
"
)
return
True
def
_add_platform_defines
(
self
,
library
):
# add some compatibility defines from `cpu_features`
if
PROCESSOR_IS_X86
and
sys
.
platform
==
"
darwin
"
:
library
.
define_macros
.
append
((
"
HAVE_SYSCTLBYNAME
"
,
1
))
if
UNIX
:
hardware_detect
=
False
if
self
.
_has_dlopen
():
library
.
define_macros
.
append
((
"
HAVE_DLFCN_H
"
,
1
))
hardware_detect
=
True
if
self
.
_has_getauxval
():
library
.
define_macros
.
append
((
"
HAVE_STRONG_GETAUXVAL
"
,
1
))
hardware_detect
=
True
if
hardware_detect
:
library
.
sources
.
append
(
os
.
path
.
join
(
"
vendor
"
,
"
cpu_features
"
,
"
src
"
,
"
hwcaps.c
"
))
def
build_libraries
(
self
,
libraries
):
def
build_libraries
(
self
,
libraries
):
self
.
mkpath
(
self
.
build_clib
)
self
.
mkpath
(
self
.
build_clib
)
for
library
in
libraries
:
for
library
in
libraries
:
...
@@ -167,6 +227,10 @@ class build_clib(_build_clib):
...
@@ -167,6 +227,10 @@ class build_clib(_build_clib):
)
)
def
build_library
(
self
,
library
):
def
build_library
(
self
,
library
):
# add specific code for `cpu_features`
if
library
.
name
==
"
cpu_features
"
:
self
.
_add_platform_defines
(
library
)
# update compile flags if compiling in debug or release mode
# update compile flags if compiling in debug or release mode
if
self
.
debug
:
if
self
.
debug
:
if
self
.
compiler
.
compiler_type
in
{
"
unix
"
,
"
cygwin
"
,
"
mingw32
"
}:
if
self
.
compiler
.
compiler_type
in
{
"
unix
"
,
"
cygwin
"
,
"
mingw32
"
}:
...
@@ -181,7 +245,7 @@ class build_clib(_build_clib):
...
@@ -181,7 +245,7 @@ class build_clib(_build_clib):
for
platform_code
in
library
.
platform_code
:
for
platform_code
in
library
.
platform_code
:
extra_preargs
=
library
.
extra_compile_args
+
platform_code
.
extra_compile_args
extra_preargs
=
library
.
extra_compile_args
+
platform_code
.
extra_compile_args
try
:
try
:
extra_objects
.
extend
(
self
.
compiler
.
compile
(
extra_objects
.
extend
(
self
.
_silent_
compile
(
platform_code
.
sources
,
platform_code
.
sources
,
output_dir
=
self
.
build_temp
,
output_dir
=
self
.
build_temp
,
include_dirs
=
library
.
include_dirs
+
[
self
.
build_clib
],
include_dirs
=
library
.
include_dirs
+
[
self
.
build_clib
],
...
@@ -193,6 +257,7 @@ class build_clib(_build_clib):
...
@@ -193,6 +257,7 @@ class build_clib(_build_clib):
except
CompileError
:
except
CompileError
:
log
.
warn
(
f
"
failed to compile platform-specific
{
platform_code
.
platform
}
code
"
)
log
.
warn
(
f
"
failed to compile platform-specific
{
platform_code
.
platform
}
code
"
)
else
:
else
:
log
.
info
(
f
"
successfully built platform-specific
{
platform_code
.
platform
}
code
"
)
self
.
compiler
.
define_macro
(
f
"
{
platform_code
.
platform
}
_BUILD_SUPPORTED
"
)
self
.
compiler
.
define_macro
(
f
"
{
platform_code
.
platform
}
_BUILD_SUPPORTED
"
)
# build objects and create a static library
# build objects and create a static library
...
@@ -341,6 +406,8 @@ class clean(_clean):
...
@@ -341,6 +406,8 @@ class clean(_clean):
# --- Cython extensions ------------------------------------------------------
# --- Cython extensions ------------------------------------------------------
libraries
=
[
libraries
=
[
Library
(
Library
(
"
cpu_features
"
,
"
cpu_features
"
,
...
@@ -367,9 +434,13 @@ libraries = [
...
@@ -367,9 +434,13 @@ libraries = [
),
),
Library
(
Library
(
"
sequtils
"
,
"
sequtils
"
,
include_dirs
=
[
os
.
path
.
join
(
"
pyfastani
"
,
"
_sequtils
"
)],
include_dirs
=
[
sources
=
[
os
.
path
.
join
(
"
pyfastani
"
,
"
_sequtils
"
,
"
sequtils.c
"
)],
os
.
path
.
join
(
"
pyfastani
"
,
"
_sequtils
"
),
os
.
path
.
join
(
"
vendor
"
,
"
cpu_features
"
,
"
include
"
)
],
sources
=
[
os
.
path
.
join
(
"
pyfastani
"
,
"
_sequtils
"
,
"
sequtils.cpp
"
)],
libraries
=
[
"
cpu_features
"
],
libraries
=
[
"
cpu_features
"
],
language
=
"
c++
"
,
platform_code
=
[
platform_code
=
[
PlatformCode
(
PlatformCode
(
platform
=
"
NEON
"
,
platform
=
"
NEON
"
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment