|
| 1 | +# ===------- do_test.py ---------------------------------- *- Python -* ---=== # |
| 2 | +# |
| 3 | +# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +# See https://llvm.org/LICENSE.txt for license information. |
| 5 | +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +# |
| 7 | +# ===----------------------------------------------------------------------=== # |
| 8 | + |
| 9 | +import os |
| 10 | +import re |
| 11 | +import sys |
| 12 | +from pathlib import Path |
| 13 | +from test_utils import * |
| 14 | + |
| 15 | +def setup_test(): |
| 16 | + return True |
| 17 | + |
| 18 | +def migrate_test(): |
| 19 | + src = [] |
| 20 | + extra_args = [] |
| 21 | + in_root = os.path.join(os.getcwd(), test_config.current_test) |
| 22 | + test_config.out_root = os.path.join(in_root, 'out_root') |
| 23 | + |
| 24 | + if test_config.current_test != 'llama': |
| 25 | + for dirpath, dirnames, filenames in os.walk(in_root): |
| 26 | + for filename in [f for f in filenames if re.match('.*(cu|cpp|c)$', f)]: |
| 27 | + src.append(os.path.abspath(os.path.join(dirpath, filename))) |
| 28 | + |
| 29 | + if test_config.current_test == 'llama': |
| 30 | + original_string = '/export/users/placeholder/project/llama.cpp' |
| 31 | + new_string = in_root |
| 32 | + db_dir = os.path.join(in_root, 'gpubuild') |
| 33 | + with open(os.path.join(db_dir, 'compile_commands.json'), "r") as file: |
| 34 | + file_contents = file.read() |
| 35 | + file_contents = file_contents.replace(original_string, new_string) |
| 36 | + db_dir = db_dir.replace('\\', '\\\\') |
| 37 | + file_contents = re.sub(r'"directory": ".*?"', '"directory": "' + db_dir + '"', file_contents) |
| 38 | + file_contents = file_contents.replace('\\', '\\\\') |
| 39 | + with open(os.path.join(db_dir, 'compile_commands.json'), "w") as file: |
| 40 | + file.write(file_contents) |
| 41 | + src.append(' -p=' + os.path.join(in_root, 'gpubuild')) |
| 42 | + src.append(' --enable-profiling ') |
| 43 | + src.append(' --use-experimental-features=free-function-queries,local-memory-kernel-scope-allocation ') |
| 44 | + |
| 45 | + return do_migrate(src, in_root, test_config.out_root, extra_args) |
| 46 | + |
| 47 | +def build_test(): |
| 48 | + if (os.path.exists(test_config.current_test)): |
| 49 | + os.chdir(test_config.current_test) |
| 50 | + srcs = [] |
| 51 | + cmp_opts = [] |
| 52 | + link_opts = [] |
| 53 | + objects = [] |
| 54 | + |
| 55 | + llama_files = ['common.cpp', 'sampling.cpp', 'console.cpp', 'grammar-parser.cpp', 'train.cpp', |
| 56 | + 'build-info.cpp', 'llama.cpp', 'ggml.c', 'ggml-alloc.c', 'ggml-backend.c', 'ggml-quants.c', |
| 57 | + 'ggml-cuda.dp.cpp', 'main.cpp'] |
| 58 | + |
| 59 | + if test_config.current_test == 'llama': |
| 60 | + if platform.system() == 'Linux': |
| 61 | + link_opts = test_config.mkl_link_opt_lin |
| 62 | + else: |
| 63 | + link_opts = test_config.mkl_link_opt_win |
| 64 | + cmp_opts.append("-DMKL_ILP64") |
| 65 | + cmp_opts.append("-DGGML_CUDA_DMMV_X=32 -DGGML_CUDA_MMV_Y=1 -DGGML_CUDA_PEER_MAX_BATCH_SIZE=128") |
| 66 | + cmp_opts.append("-DGGML_USE_CUBLAS -DK_QUANTS_PER_ITERATION=2 -D_GNU_SOURCE -D_XOPEN_SOURCE=600 -O3 -DNDEBUG") |
| 67 | + cmp_opts.append("-I " + test_config.out_root) |
| 68 | + cmp_opts.append("-I " + os.path.join(test_config.out_root, 'common')) |
| 69 | + |
| 70 | + for dirpath, dirnames, filenames in os.walk(test_config.out_root): |
| 71 | + if test_config.current_test == 'llama': |
| 72 | + for filename in filenames: |
| 73 | + if filename in llama_files: |
| 74 | + srcs.append(os.path.abspath(os.path.join(dirpath, filename))) |
| 75 | + else: |
| 76 | + for filename in [f for f in filenames if re.match('.*(cpp|c)$', f)]: |
| 77 | + srcs.append(os.path.abspath(os.path.join(dirpath, filename))) |
| 78 | + |
| 79 | + if platform.system() == 'Linux': |
| 80 | + link_opts.append(' -lpthread ') |
| 81 | + |
| 82 | + ret = False |
| 83 | + |
| 84 | + if test_config.current_test == 'llama': |
| 85 | + ret = compile_and_link(srcs, cmp_opts, objects, link_opts) |
| 86 | + else: |
| 87 | + ret = compile_files(srcs, cmp_opts) |
| 88 | + return ret |
| 89 | + |
| 90 | +def run_test(): |
| 91 | + return True |
0 commit comments