facebook / rocksdb

A library that provides an embeddable, persistent key-value store for fast storage.
http://rocksdb.org
GNU General Public License v2.0
28.15k stars 6.26k forks source link

Request: make USE_SSE=1 the default #7590

Open absolute8511 opened 3 years ago

absolute8511 commented 3 years ago

I build with the

PORTABLE=1 make static_lib

the make_config.mk showed no -DHAVE_SSE42 will be used which will disable the fast crc32

CC=cc
CXX=g++
PLATFORM=OS_LINUX
PLATFORM_LDFLAGS= -lpthread -lrt -lsnappy -lz -lbz2
JAVA_LDFLAGS= -lpthread -lrt -lsnappy -lz -lbz2
JAVA_STATIC_LDFLAGS= -lpthread -lrt
VALGRIND_VER=
PLATFORM_CCFLAGS= -DROCKSDB_PLATFORM_POSIX -DROCKSDB_LIB_IO_POSIX  -DOS_LINUX -fno-builtin-memcmp -DROCKSDB_FALLOCATE_PRESENT -DSNAPPY -DZLIB -DBZIP2 -DROCKSDB_MALLOC_USABLE_SIZE -DROCKSDB_PTHREAD_ADAPTIVE_MUTEX -DROCKSDB_BACKTRACE -DROCKSDB_RANGESYNC_PRESENT -DROCKSDB_SCHED_GETCPU_PRESENT -DROCKSDB_SUPPORT_THREAD_LOCAL
PLATFORM_CXXFLAGS=-std=c++11  -DROCKSDB_PLATFORM_POSIX -DROCKSDB_LIB_IO_POSIX  -DOS_LINUX -fno-builtin-memcmp -DROCKSDB_FALLOCATE_PRESENT -DSNAPPY -DZLIB -DBZIP2 -DROCKSDB_MALLOC_USABLE_SIZE -DROCKSDB_PTHREAD_ADAPTIVE_MUTEX -DROCKSDB_BACKTRACE -DROCKSDB_RANGESYNC_PRESENT -DROCKSDB_SCHED_GETCPU_PRESENT -DROCKSDB_SUPPORT_THREAD_LOCAL
PLATFORM_SHARED_CFLAGS=-fPIC

While I build with the default make static_lib without using the PORTABLE, the content in the make_config.mk showed

CC=cc
CXX=g++
PLATFORM=OS_LINUX
PLATFORM_LDFLAGS= -lpthread -lrt -lsnappy -lz -lbz2
JAVA_LDFLAGS= -lpthread -lrt -lsnappy -lz -lbz2
JAVA_STATIC_LDFLAGS= -lpthread -lrt
VALGRIND_VER=
PLATFORM_CCFLAGS= -DROCKSDB_PLATFORM_POSIX -DROCKSDB_LIB_IO_POSIX  -DOS_LINUX -fno-builtin-memcmp -DROCKSDB_FALLOCATE_PRESENT -DSNAPPY -DZLIB -DBZIP2 -DROCKSDB_MALLOC_USABLE_SIZE -DROCKSDB_PTHREAD_ADAPTIVE_MUTEX -DROCKSDB_BACKTRACE -DROCKSDB_RANGESYNC_PRESENT -DROCKSDB_SCHED_GETCPU_PRESENT -march=native  -DHAVE_SSE42 -DHAVE_PCLMUL -DROCKSDB_SUPPORT_THREAD_LOCAL
PLATFORM_CXXFLAGS=-std=c++11  -DROCKSDB_PLATFORM_POSIX -DROCKSDB_LIB_IO_POSIX  -DOS_LINUX -fno-builtin-memcmp -DROCKSDB_FALLOCATE_PRESENT -DSNAPPY -DZLIB -DBZIP2 -DROCKSDB_MALLOC_USABLE_SIZE -DROCKSDB_PTHREAD_ADAPTIVE_MUTEX -DROCKSDB_BACKTRACE -DROCKSDB_RANGESYNC_PRESENT -DROCKSDB_SCHED_GETCPU_PRESENT -march=native  -DHAVE_SSE42 -DHAVE_PCLMUL -DROCKSDB_SUPPORT_THREAD_LOCAL
PLATFORM_SHARED_CFLAGS=-fPIC

I can force using the sse by USE_SSE=1 PORTABLE=1 make static_lib.

So, is it expected for a portable build?

adamretter commented 3 years ago

@absolute8511 As SSE is a processor extension set, I would expect it to be disabled for portable builds for the reason that (I would guess) that not all processors have SSE. Does that make sense?

absolute8511 commented 3 years ago

Yeah, I think it makes sense, and just to confirm. But I see it can be detected on the running machine, maybe it will not affect the portable?

adamretter commented 3 years ago

@absolute8511 I guess at the moment it is decided at compile time rather than run time.

pdillinger commented 3 years ago

FWIW, for Facebook developers, USE_SSE=1 is default

build_tools/fbcode_config.sh:test "$USE_SSE" || USE_SSE=1
build_tools/fbcode_config.sh:export USE_SSE

And note (from build_detect_platform):

# The USE_SSE flag now means "attempt to compile with widely-available
# Intel architecture extensions utilized by specific optimizations in the
# source code." It's a qualifier on PORTABLE=1 that means "mostly portable."
# It doesn't even really check that your current CPU is compatible.

@absolute8511 As SSE is a processor extension set, I would expect it to be disabled for portable builds for the reason that (I would guess) that not all processors have SSE.

+1 (even though SSE is now ancient)

@absolute8511 I guess at the moment it is decided at compile time rather than run time.

Runtime detection is a PITA, so RocksDB code doing that is more exception than rule.

If you want "mostly" portable, USE_SSE=1 (along with default PORTABLE=1). If you want best optimizations for your CPU, PORTABLE=0. If you want truly portable for your platform, USE_SSE=0 (currently default).

I'll keep this open as a (reasonable) request to make USE_SSE=1 default for (at least) all Makefile users.