Files
deeplearning4j--deeplearning4j/libnd4j/cmake/SemanticEngine.cmake
T
2026-07-13 12:47:05 +08:00

107 lines
4.9 KiB
CMake

# cmake/SemanticEngine.cmake
# Implements the ML-aware semantic type filtering system.
option(SD_ENABLE_SEMANTIC_FILTERING "Enable ML-aware semantic type filtering" ON)
option(SD_SHOW_COMBINATION_ANALYSIS "Show type combination analysis" ON)
set(SD_TYPE_PROFILE "" CACHE STRING "ML workload profile (quantization/training/inference/nlp/cv)")
if(NOT SD_ENABLE_SEMANTIC_FILTERING)
message(STATUS "Semantic filtering disabled. Using traditional type combination.")
set(USE_SEMANTIC_PAIRWISE_GENERATION FALSE CACHE BOOL "Use semantic generation for pairwise templates")
return()
endif()
print_status_colored("INFO" "=== SEMANTIC TYPE COMBINATION GENERATION ===")
setup_enhanced_semantic_validation()
# Auto-detect profile from type selection if none specified
if((NOT SD_TYPE_PROFILE OR SD_TYPE_PROFILE STREQUAL "") AND SD_TYPES_LIST_COUNT GREATER 0)
set(detected_profile "")
if("int8_t" IN_LIST SD_TYPES_LIST AND "uint8_t" IN_LIST SD_TYPES_LIST)
set(detected_profile "quantization")
elseif("float16" IN_LIST SD_TYPES_LIST OR "bfloat16" IN_LIST SD_TYPES_LIST)
set(detected_profile "training")
elseif(SD_TYPES_LIST MATCHES ".*string.*")
set(detected_profile "nlp")
endif()
if(NOT detected_profile STREQUAL "")
print_status_colored("INFO" "Auto-detected ML workload profile: ${detected_profile}")
set(SD_TYPE_PROFILE "${detected_profile}")
else()
print_status_colored("INFO" "No specific workload detected - using inference profile as default")
set(SD_TYPE_PROFILE "inference")
endif()
elseif(NOT SD_TYPE_PROFILE OR SD_TYPE_PROFILE STREQUAL "")
print_status_colored("INFO" "No workload profile specified - using inference as default")
set(SD_TYPE_PROFILE "inference")
endif()
# Apply type profile if specified
if(SD_TYPE_PROFILE AND NOT SD_TYPE_PROFILE STREQUAL "")
print_status_colored("INFO" "Applying ML workload profile: ${SD_TYPE_PROFILE}")
if(COMMAND apply_type_profile)
apply_type_profile(${SD_TYPE_PROFILE})
else()
message(STATUS "Type profiles not available - using default types")
endif()
endif()
# Generate ML-aware type combinations
message(STATUS "Generating ML-aware type combinations...")
if(SD_TYPE_PROFILE AND NOT SD_TYPE_PROFILE STREQUAL "")
if(COMMAND generate_workload_combinations)
generate_workload_combinations("${SD_TYPE_PROFILE}" optimized_combinations)
set(GENERATED_TYPE_COMBINATIONS "${optimized_combinations}")
else()
message(STATUS "generate_workload_combinations function not available - using traditional approach")
if(COMMAND generate_type_combinations)
generate_type_combinations()
endif()
endif()
else()
if(COMMAND generate_type_combinations)
generate_type_combinations()
endif()
endif()
if(SD_SHOW_COMBINATION_ANALYSIS)
if(SD_TYPES_LIST_COUNT GREATER 0)
validate_ml_type_combinations("${SD_TYPES_LIST}")
endif()
if(DEFINED GENERATED_TYPE_COMBINATIONS)
analyze_combination_patterns("${GENERATED_TYPE_COMBINATIONS}" "${SD_TYPE_PROFILE}")
endif()
endif()
# Process template files with semantic filtering
message(STATUS "Processing template files with semantic filtering...")
#process_template_files()
# Process pairwise templates with enhanced semantic filtering
message(STATUS "Processing pairwise templates with enhanced semantic filtering...")
if(COMMAND process_pairwise_templates_semantic)
process_pairwise_templates_semantic()
else()
message(STATUS "process_pairwise_templates_semantic function not available - skipping")
endif()
# --- PAIRWISE SEMANTIC TYPE PROCESSING ---
print_status_colored("INFO" "=== PAIRWISE SEMANTIC TYPE PROCESSING ===")
message(STATUS "Applying semantic type processing to pairwise instantiations...")
if(SD_TYPE_PROFILE AND NOT SD_TYPE_PROFILE STREQUAL "")
message(STATUS "Using workload profile '${SD_TYPE_PROFILE}' for pairwise semantic processing")
if(COMMAND generate_pairwise_semantic_combinations)
generate_pairwise_semantic_combinations("${SD_TYPE_PROFILE}" SEMANTIC_PAIRWISE_COMBINATIONS)
list(LENGTH SEMANTIC_PAIRWISE_COMBINATIONS semantic_count)
message(STATUS "Generated ${semantic_count} semantic pairwise combinations")
set(PAIRWISE_SEMANTIC_COMBINATIONS "${SEMANTIC_PAIRWISE_COMBINATIONS}" CACHE INTERNAL "Semantic pairwise combinations")
set(USE_SEMANTIC_PAIRWISE_GENERATION TRUE CACHE BOOL "Use semantic generation for pairwise templates")
else()
message(STATUS "generate_pairwise_semantic_combinations function not available.")
set(USE_SEMANTIC_PAIRWISE_GENERATION FALSE CACHE BOOL "Use semantic generation for pairwise templates")
endif()
else()
message(STATUS "No workload profile specified - using traditional pairwise processing")
set(USE_SEMANTIC_PAIRWISE_GENERATION FALSE CACHE BOOL "Use semantic generation for pairwise templates")
endif()