Skip to content

Commit 465ad80

Browse files
excelle08meta-codesync[bot]
authored andcommitted
Refactor feature extractors to match production instruction mix (#705)
Summary: Pull Request resolved: #705 Replace scalar FP transforms with integer hash operations, add data-dependent conditional branches, eliminate FP division with integer reciprocal approximation, deepen MockHashTable::find() call chain from 1 to 5 levels, and increase basic block sizes with MurmurHash-style computation chains. Results (5/7 instruction mix targets met on CPL): - Scalar FP: 8% → 0.46% (target <3.5%) ✓ - Conditional branches: 5.28% → 10.73% (target >15%) ✗ - Near call/return: 3.93% → 0.75% (target <1.5%) ✓ - Memory (ld+st): 51.56% → 40.72% (target 40-46%) ✓ - Divider active: 11.50% → 1.13% (target <2%) ✓ - Avg BB size: 7.3 → 13.7 (LBR, target >18) ✗ QPS impact: CPL -2.2%, BGM -6.3%, Grace -3.8%. Reviewed By: charles-typ Differential Revision: D99494831
1 parent 07d7197 commit 465ad80

8 files changed

Lines changed: 1060 additions & 93 deletions

File tree

packages/feedsim/run.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,8 +588,16 @@ main() {
588588

589589
# Starting leaf node service
590590
monitor_port=$((port-1000))
591+
592+
# On aarch64, preload Miniconda's protobuf to resolve version conflict
593+
# between system libprotobuf.so.25 and libtorch's libprotobuf.so.33
594+
local preload_env=""
595+
if [ "$(uname -m)" = "aarch64" ] && [ -f "${FEEDSIM_ROOT}/third_party/miniconda3/lib/libprotobuf.so" ]; then
596+
preload_env="LD_PRELOAD=${FEEDSIM_ROOT}/third_party/miniconda3/lib/libprotobuf.so"
597+
fi
598+
591599
# shellcheck disable=SC2086
592-
MALLOC_CONF=narenas:20,dirty_decay_ms:5000 build/workloads/ranking/LeafNodeRank \
600+
env $preload_env MALLOC_CONF=narenas:20,dirty_decay_ms:5000 build/workloads/ranking/LeafNodeRank \
593601
--port="$port" \
594602
--monitor_port="$monitor_port" \
595603
--graph_scale=21 \
@@ -618,7 +626,7 @@ main() {
618626

619627
# Wait for server to be fully ready using monitoring endpoint
620628
echo "Waiting for LeafNodeRank server to be ready on monitor port $monitor_port..."
621-
max_attempts=30
629+
max_attempts=120
622630
attempt=0
623631
while [ $attempt -lt $max_attempts ]; do
624632
if curl -f -s "http://localhost:$monitor_port/topology" > /dev/null 2>&1; then

packages/feedsim/third_party/src/workloads/ranking/CMakeLists.txt

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ add_library(featureExtractors STATIC
134134
feature_extractors/TreeTraversalExtractor.h
135135
feature_extractors/BitsetExtractor.cpp
136136
feature_extractors/BitsetExtractor.h
137+
feature_extractors/generated/extractor_helpers.cpp
137138
${GENERATED_EXTRACTOR_SOURCES}
138139
)
139140
add_dependencies(featureExtractors folly)
@@ -151,8 +152,17 @@ target_link_libraries(featureExtractors
151152
${FOLLY_LIBRARIES}
152153
glog::glog
153154
)
155+
# -mcmodel=large is x86_64-only; on aarch64 use default code model
156+
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
157+
set(FEEDSIM_MCMODEL_FLAG "-mcmodel=large")
158+
else()
159+
set(FEEDSIM_MCMODEL_FLAG "")
160+
endif()
161+
154162
target_compile_options(featureExtractors PRIVATE
155163
-fno-omit-frame-pointer
164+
${FEEDSIM_MCMODEL_FLAG}
165+
-fno-plt
156166
)
157167

158168
# Compile generated copies at -O0 WITHOUT -ffunction-sections to prevent:
@@ -163,10 +173,15 @@ file(GLOB GENERATED_COPIES_FILES
163173
"${CMAKE_CURRENT_SOURCE_DIR}/feature_extractors/generated/copies/*.cpp")
164174
file(GLOB GENERATED_VARIANT_FILES
165175
"${CMAKE_CURRENT_SOURCE_DIR}/feature_extractors/generated/variants/*.cpp")
176+
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
177+
set(GENERATED_EXTRA_FLAGS "-O0 -mcmodel=large -fno-plt")
178+
else()
179+
set(GENERATED_EXTRA_FLAGS "-O0 -fno-plt")
180+
endif()
166181
set_source_files_properties(
167182
${GENERATED_COPIES_FILES}
168183
${GENERATED_VARIANT_FILES}
169-
PROPERTIES COMPILE_FLAGS "-O0"
184+
PROPERTIES COMPILE_FLAGS "${GENERATED_EXTRA_FLAGS}"
170185
)
171186

172187
# DLRM support (optional, requires LibTorch)
@@ -180,6 +195,7 @@ if(FEEDSIM_USE_DLRM)
180195
dwarfs/dlrm.cpp
181196
dwarfs/dlrm.h
182197
)
198+
add_dependencies(rankingDLRM folly)
183199
target_compile_definitions(rankingDLRM PUBLIC FEEDSIM_USE_DLRM)
184200
target_include_directories(rankingDLRM
185201
PUBLIC
@@ -279,16 +295,23 @@ target_link_libraries(LeafNodeRank
279295
${JEMALLOC_LIB}
280296
${LIBLZMA_LIBRARIES}
281297
)
282-
target_compile_options(LeafNodeRank PUBLIC -fno-omit-frame-pointer -ffunction-sections -fdata-sections)
298+
target_compile_options(LeafNodeRank PUBLIC -fno-omit-frame-pointer -ffunction-sections -fdata-sections ${FEEDSIM_MCMODEL_FLAG} -fno-plt)
283299
# --whole-archive for featureExtractors prevents --gc-sections from stripping
284300
# generated functions that are only referenced via function pointer arrays.
301+
# -Wl,--no-relax is x86_64-only (linker relaxation optimization)
285302
target_link_options(LeafNodeRank PRIVATE
286303
-Wl,--gc-sections
287304
-Wl,--allow-multiple-definition
305+
-Wl,-z,notext
306+
-no-pie
288307
-Wl,--whole-archive
289308
$<TARGET_FILE:featureExtractors>
290309
-Wl,--no-whole-archive
291310
)
311+
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
312+
target_link_options(LeafNodeRank PRIVATE -Wl,--no-relax)
313+
endif()
314+
292315
# Re-link libraries at the end to resolve circular static library dependencies
293316
# (folly/glog use gflags DEFINE_* macros, fbthrift has internal cross-lib refs)
294317
target_link_libraries(LeafNodeRank PRIVATE

packages/feedsim/third_party/src/workloads/ranking/feature_extractors/FeatureExtractorSuite.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ void FeatureExtractorSuite::initializeFlatDispatch(int seed) {
112112
for (int i = 0; i < 1024; ++i)
113113
flat_tables_[t][data_rng()] = dist(data_rng);
114114

115+
for (int t = 0; t < 4; ++t)
116+
flat_hash_tables_[t].populate(64, seed + t + 100);
117+
115118
flat_features_.resize(100);
116119
for (int i = 0; i < 100; ++i) {
117120
flat_features_[i].raw_feature_index = i % 50;
@@ -140,6 +143,8 @@ void FeatureExtractorSuite::runFlatExtractors(
140143
ctx.numFeatures = static_cast<int>(flat_features_.size());
141144
ctx.queryKeys = input_sparse.data();
142145
ctx.numKeys = static_cast<int>(input_sparse.size());
146+
ctx.hashTables = flat_hash_tables_;
147+
ctx.numHashTables = 4;
143148

144149
for (int i = 0; i < count; ++i) {
145150
flat_copies_[flat_pos_](&ctx);

packages/feedsim/third_party/src/workloads/ranking/feature_extractors/FeatureExtractorSuite.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "FeatureExtractorBase.h"
1616
#include "FeatureTypes.h"
1717
#include "generated/dispatch.h"
18+
#include "generated/mock_hash_table.h"
1819
#include "generated/registry.h"
1920

2021
class FeatureExtractorSuite {
@@ -67,6 +68,7 @@ class FeatureExtractorSuite {
6768
std::unique_ptr<float[]> flat_struct_data_;
6869
int flat_struct_size_ = 0;
6970
std::unordered_map<int64_t, float> flat_tables_[4];
71+
dcperf::mock_hash::MockHashTable flat_hash_tables_[4];
7072
MockFeatureExample flat_example_;
7173
std::vector<MockFeature> flat_features_;
7274
};

0 commit comments

Comments
 (0)