You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

build_common.sh 2.2 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/bin/bash
  2. # GPU算法竞赛公共编译配置
  3. # 被各个独立编译脚本调用
  4. # 设置颜色
  5. RED='\033[0;31m'
  6. GREEN='\033[0;32m'
  7. BLUE='\033[0;34m'
  8. YELLOW='\033[0;33m'
  9. NC='\033[0m' # No Color
  10. # 打印函数
  11. print_info() {
  12. echo -e "${BLUE}[INFO]${NC} $1"
  13. }
  14. print_success() {
  15. echo -e "${GREEN}[SUCCESS]${NC} $1"
  16. }
  17. print_error() {
  18. echo -e "${RED}[ERROR]${NC} $1"
  19. }
  20. print_warning() {
  21. echo -e "${YELLOW}[WARNING]${NC} $1"
  22. }
  23. # 编译配置 - 可通过环境变量自定义
  24. COMPILER=${COMPILER:-mxcc}
  25. #COMPILER_FLAGS=${COMPILER_FLAGS:--O3 -std=c++17 --extended-lambda} # not run all test for easy debug
  26. COMPILER_FLAGS=${COMPILER_FLAGS:--O3 -std=c++17 --extended-lambda -DRUN_FULL_TEST}
  27. INCLUDE_DIR=${INCLUDE_DIR:-src}
  28. BUILD_DIR=${BUILD_DIR:-build}
  29. # 编译单个算法的通用函数
  30. # 参数: $1=算法名称, $2=源文件名
  31. compile_algorithm() {
  32. local algo_name="$1"
  33. local source_file="$2"
  34. local target_file="$BUILD_DIR/test_${algo_name,,}" # 转换为小写
  35. print_info "编译 $algo_name 算法..."
  36. # 创建构建目录
  37. mkdir -p "$BUILD_DIR"
  38. # 编译命令
  39. local compile_cmd="$COMPILER $COMPILER_FLAGS -I$INCLUDE_DIR src/$source_file -o $target_file"
  40. print_info "执行: $compile_cmd"
  41. if $compile_cmd; then
  42. print_success "$algo_name 编译完成!"
  43. echo ""
  44. echo "运行测试:"
  45. echo " ./$target_file [correctness|performance|all]"
  46. return 0
  47. else
  48. print_error "$algo_name 编译失败!"
  49. return 1
  50. fi
  51. }
  52. # 显示编译配置信息
  53. show_build_config() {
  54. print_info "编译配置:"
  55. echo " COMPILER: $COMPILER"
  56. echo " COMPILER_FLAGS: $COMPILER_FLAGS"
  57. echo " INCLUDE_DIR: $INCLUDE_DIR"
  58. echo " BUILD_DIR: $BUILD_DIR"
  59. echo ""
  60. }
  61. # 运行单个测试
  62. run_single_test() {
  63. local algo_name="$1"
  64. local test_mode="${2:-all}"
  65. local test_file="$BUILD_DIR/test_${algo_name,,}"
  66. if [ -f "$test_file" ]; then
  67. print_info "运行 $algo_name 测试 (模式: $test_mode)..."
  68. "./$test_file" "$test_mode"
  69. return $?
  70. else
  71. print_error "$algo_name 测试程序不存在: $test_file"
  72. return 1
  73. fi
  74. }