diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index c5cbab0697bf..fc93cdc83c50 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -141,6 +141,12 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") # macOS. See https://github.com/boostorg/stacktrace/issues/88 and comments # therein. add_compile_definitions(_GNU_SOURCE) + + # Only make default symbol visibility as 'default' when we want to build test + # or benchmark + if(BUILD_TESTS OR BUILD_BENCHMARKS) + add_compile_options(-fvisibility=default) + endif() endif() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${KNOWN_WARNINGS}") diff --git a/cpp/core/benchmarks/CompressionBenchmark.cc b/cpp/core/benchmarks/CompressionBenchmark.cc index 1966c8ef1c18..808ce9192a4b 100644 --- a/cpp/core/benchmarks/CompressionBenchmark.cc +++ b/cpp/core/benchmarks/CompressionBenchmark.cc @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -213,11 +214,21 @@ class BenchmarkCompression { } protected: - long setCpu(uint32_t cpuindex) { + void setCpu(uint32_t cpuindex) { +#ifndef __APPLE__ + static const auto kTotalCores = std::thread::hardware_concurrency(); + cpuindex = cpuindex % kTotalCores; cpu_set_t cs; CPU_ZERO(&cs); CPU_SET(cpuindex, &cs); - return sched_setaffinity(0, sizeof(cs), &cs); + if (sched_setaffinity(0, sizeof(cs), &cs) == -1) { + LOG(WARNING) << "Error binding CPU " << std::to_string(cpuindex); + exit(EXIT_FAILURE); + } +#else + LOG(WARNING) << "Binding CPU is currently not supported on macOS." << std::endl; + exit(EXIT_FAILURE); +#endif } virtual void doCompress( diff --git a/cpp/velox/benchmarks/ColumnarToRowBenchmark.cc b/cpp/velox/benchmarks/ColumnarToRowBenchmark.cc index 8a55050015d0..9c1e10f175de 100644 --- a/cpp/velox/benchmarks/ColumnarToRowBenchmark.cc +++ b/cpp/velox/benchmarks/ColumnarToRowBenchmark.cc @@ -87,10 +87,15 @@ class GoogleBenchmarkColumnarToRow { protected: long setCpu(uint32_t cpuindex) { +#ifndef __APPLE__ cpu_set_t cs; CPU_ZERO(&cs); CPU_SET(cpuindex, &cs); return sched_setaffinity(0, sizeof(cs), &cs); +#else + LOG(WARNING) << "Binding CPU is currently not supported on macOS." << std::endl; + exit(EXIT_FAILURE); +#endif } velox::VectorPtr recordBatch2RowVector(const arrow::RecordBatch& rb) { diff --git a/cpp/velox/benchmarks/ParquetWriteBenchmark.cc b/cpp/velox/benchmarks/ParquetWriteBenchmark.cc index 45348ed4a63b..0904e48dec67 100644 --- a/cpp/velox/benchmarks/ParquetWriteBenchmark.cc +++ b/cpp/velox/benchmarks/ParquetWriteBenchmark.cc @@ -92,10 +92,15 @@ class GoogleBenchmarkParquetWrite { protected: long setCpu(uint32_t cpuindex) { +#ifndef __APPLE__ cpu_set_t cs; CPU_ZERO(&cs); CPU_SET(cpuindex, &cs); return sched_setaffinity(0, sizeof(cs), &cs); +#else + LOG(WARNING) << "Binding CPU is currently not supported on macOS." << std::endl; + exit(EXIT_FAILURE); +#endif } std::shared_ptr recordBatch2VeloxColumnarBatch(const arrow::RecordBatch& rb) { diff --git a/cpp/velox/benchmarks/common/BenchmarkUtils.cc b/cpp/velox/benchmarks/common/BenchmarkUtils.cc index 345f9da8e16d..66afd7f5e9c4 100644 --- a/cpp/velox/benchmarks/common/BenchmarkUtils.cc +++ b/cpp/velox/benchmarks/common/BenchmarkUtils.cc @@ -140,6 +140,7 @@ std::shared_ptr createReader(const std::string& path) #endif void setCpu(uint32_t cpuindex) { +#ifndef __APPLE__ static const auto kTotalCores = std::thread::hardware_concurrency(); cpuindex = cpuindex % kTotalCores; cpu_set_t cs; @@ -149,6 +150,10 @@ void setCpu(uint32_t cpuindex) { LOG(WARNING) << "Error binding CPU " << std::to_string(cpuindex); exit(EXIT_FAILURE); } +#else + LOG(WARNING) << "Binding CPU is currently not supported on macOS." << std::endl; + exit(EXIT_FAILURE); +#endif } arrow::Status diff --git a/cpp/velox/tests/CMakeLists.txt b/cpp/velox/tests/CMakeLists.txt index b8ea12e944aa..52af155b892c 100644 --- a/cpp/velox/tests/CMakeLists.txt +++ b/cpp/velox/tests/CMakeLists.txt @@ -27,7 +27,7 @@ function(add_velox_test TEST_EXEC) endif() add_executable(${TEST_EXEC} ${SOURCES} ${VELOX_TEST_COMMON_SRCS}) target_include_directories( - ${TEST_EXEC} PRIVATE ${CMAKE_SOURCE_DIR}/velox ${CMAKE_SOURCE_DIR}/src + ${TEST_EXEC} PRIVATE ${CMAKE_SOURCE_DIR}/src ${VELOX_BUILD_PATH}/_deps/duckdb-src/src/include) target_link_libraries(${TEST_EXEC} velox GTest::gtest GTest::gtest_main google::glog) diff --git a/cpp/velox/tests/FunctionTest.cc b/cpp/velox/tests/FunctionTest.cc index b55b64ba9811..73b3898e2f02 100644 --- a/cpp/velox/tests/FunctionTest.cc +++ b/cpp/velox/tests/FunctionTest.cc @@ -72,7 +72,7 @@ TEST_F(FunctionTest, getIdxFromNodeName) { TEST_F(FunctionTest, getNameBeforeDelimiter) { std::string functionSpec = "lte:fp64_fp64"; - std::string_view funcName = SubstraitParser::getNameBeforeDelimiter(functionSpec); + std::string funcName = SubstraitParser::getNameBeforeDelimiter(functionSpec); ASSERT_EQ(funcName, "lte"); functionSpec = "lte:"; diff --git a/cpp/velox/tests/VeloxRowToColumnarTest.cc b/cpp/velox/tests/VeloxRowToColumnarTest.cc index c784dbd59c34..8994aef8711d 100644 --- a/cpp/velox/tests/VeloxRowToColumnarTest.cc +++ b/cpp/velox/tests/VeloxRowToColumnarTest.cc @@ -42,16 +42,16 @@ class VeloxRowToColumnarTest : public ::testing::Test, public test::VectorTestBa uint8_t* address = columnarToRowConverter->getBufferAddress(); auto lengthVec = columnarToRowConverter->getLengths(); - long lengthArr[lengthVec.size()]; + std::vector int64Lengths(lengthVec.size()); for (int i = 0; i < lengthVec.size(); i++) { - lengthArr[i] = lengthVec[i]; + int64Lengths[i] = lengthVec[i]; } ArrowSchema cSchema; toArrowSchema(vector->type(), pool(), &cSchema); auto rowToColumnarConverter = std::make_shared(&cSchema, pool_); - auto cb = rowToColumnarConverter->convert(numRows, lengthArr, address); + auto cb = rowToColumnarConverter->convert(numRows, int64Lengths.data(), address); auto vp = std::dynamic_pointer_cast(cb)->getRowVector(); velox::test::assertEqualVectors(vector, vp); }