Skip to content

Commit c65617d

Browse files
authored
[SYCLomatic] Move the test driver of llama into the subfolder (#612)
Signed-off-by: Zhiwei Jiang <zhiwei.jiang@intel.com>
1 parent 07b0a85 commit c65617d

File tree

2 files changed

+95
-78
lines changed

2 files changed

+95
-78
lines changed

applications/src/llama/do_test.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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

applications/test_applications.py

Lines changed: 4 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -6,90 +6,16 @@
66
#
77
# ===----------------------------------------------------------------------=== #
88

9-
import os
10-
import re
11-
import sys
12-
from pathlib import Path
13-
parent = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
14-
sys.path.append(parent)
15-
16-
from test_utils import *
9+
# Test drivers for the applications suite are in the folder of each case.
1710

1811
def setup_test():
19-
2012
return True
2113

2214
def migrate_test():
23-
src = []
24-
extra_args = []
25-
in_root = os.path.join(os.getcwd(), test_config.current_test)
26-
test_config.out_root = os.path.join(in_root, 'out_root')
27-
28-
if test_config.current_test != 'llama':
29-
for dirpath, dirnames, filenames in os.walk(in_root):
30-
for filename in [f for f in filenames if re.match('.*(cu|cpp|c)$', f)]:
31-
src.append(os.path.abspath(os.path.join(dirpath, filename)))
32-
33-
if test_config.current_test == 'llama':
34-
original_string = '/export/users/placeholder/project/llama.cpp'
35-
new_string = in_root
36-
db_dir = os.path.join(in_root, 'gpubuild')
37-
with open(os.path.join(db_dir, 'compile_commands.json'), "r") as file:
38-
file_contents = file.read()
39-
file_contents = file_contents.replace(original_string, new_string)
40-
db_dir = db_dir.replace('\\', '\\\\')
41-
file_contents = re.sub(r'"directory": ".*?"', '"directory": "' + db_dir + '"', file_contents)
42-
file_contents = file_contents.replace('\\', '\\\\')
43-
with open(os.path.join(db_dir, 'compile_commands.json'), "w") as file:
44-
file.write(file_contents)
45-
src.append(' -p=' + os.path.join(in_root, 'gpubuild'))
46-
src.append(' --enable-profiling ')
47-
src.append(' --use-experimental-features=free-function-queries,local-memory-kernel-scope-allocation ')
48-
49-
return do_migrate(src, in_root, test_config.out_root, extra_args)
15+
return True
5016

5117
def build_test():
52-
if (os.path.exists(test_config.current_test)):
53-
os.chdir(test_config.current_test)
54-
srcs = []
55-
cmp_opts = []
56-
link_opts = []
57-
objects = []
58-
59-
llama_files = ['common.cpp', 'sampling.cpp', 'console.cpp', 'grammar-parser.cpp', 'train.cpp',
60-
'build-info.cpp', 'llama.cpp', 'ggml.c', 'ggml-alloc.c', 'ggml-backend.c', 'ggml-quants.c',
61-
'ggml-cuda.dp.cpp', 'main.cpp']
62-
63-
if test_config.current_test == 'llama':
64-
if platform.system() == 'Linux':
65-
link_opts = test_config.mkl_link_opt_lin
66-
else:
67-
link_opts = test_config.mkl_link_opt_win
68-
cmp_opts.append("-DMKL_ILP64")
69-
cmp_opts.append("-DGGML_CUDA_DMMV_X=32 -DGGML_CUDA_MMV_Y=1 -DGGML_CUDA_PEER_MAX_BATCH_SIZE=128")
70-
cmp_opts.append("-DGGML_USE_CUBLAS -DK_QUANTS_PER_ITERATION=2 -D_GNU_SOURCE -D_XOPEN_SOURCE=600 -O3 -DNDEBUG")
71-
cmp_opts.append("-I " + test_config.out_root)
72-
cmp_opts.append("-I " + os.path.join(test_config.out_root, 'common'))
73-
74-
for dirpath, dirnames, filenames in os.walk(test_config.out_root):
75-
if test_config.current_test == 'llama':
76-
for filename in filenames:
77-
if filename in llama_files:
78-
srcs.append(os.path.abspath(os.path.join(dirpath, filename)))
79-
else:
80-
for filename in [f for f in filenames if re.match('.*(cpp|c)$', f)]:
81-
srcs.append(os.path.abspath(os.path.join(dirpath, filename)))
82-
83-
if platform.system() == 'Linux':
84-
link_opts.append(' -lpthread ')
85-
86-
ret = False
87-
88-
if test_config.current_test == 'llama':
89-
ret = compile_and_link(srcs, cmp_opts, objects, link_opts)
90-
else:
91-
ret = compile_files(srcs, cmp_opts)
92-
return ret
18+
return True
9319

9420
def run_test():
95-
return True
21+
return True

0 commit comments

Comments
 (0)