From c1f773cd0dd6b1f1913e55bf0e2668af13909dfe Mon Sep 17 00:00:00 2001 From: "Ahmed, Daiyaan" Date: Mon, 31 Jul 2023 13:10:12 +0800 Subject: [PATCH 1/2] [SYCLomatic #1123] Remove redundant -c flag Signed-off-by: Ahmed, Daiyaan --- behavior_tests/behavior_tests.xml | 1 + .../src/cmp_cmds_c_opt_test/Makefile | 10 ++++ .../compile_commands.json_ref | 22 +++++++++ .../src/cmp_cmds_c_opt_test/do_test.py | 49 +++++++++++++++++++ .../src/cmp_cmds_c_opt_test/four.cu | 4 ++ behavior_tests/src/cmp_cmds_c_opt_test/one.cu | 3 ++ .../src/cmp_cmds_c_opt_test/three.cu | 4 ++ behavior_tests/src/cmp_cmds_c_opt_test/two.cu | 4 ++ 8 files changed, 97 insertions(+) create mode 100644 behavior_tests/src/cmp_cmds_c_opt_test/Makefile create mode 100644 behavior_tests/src/cmp_cmds_c_opt_test/compile_commands.json_ref create mode 100644 behavior_tests/src/cmp_cmds_c_opt_test/do_test.py create mode 100644 behavior_tests/src/cmp_cmds_c_opt_test/four.cu create mode 100644 behavior_tests/src/cmp_cmds_c_opt_test/one.cu create mode 100644 behavior_tests/src/cmp_cmds_c_opt_test/three.cu create mode 100644 behavior_tests/src/cmp_cmds_c_opt_test/two.cu diff --git a/behavior_tests/behavior_tests.xml b/behavior_tests/behavior_tests.xml index 7b87145db..a85a235c3 100644 --- a/behavior_tests/behavior_tests.xml +++ b/behavior_tests/behavior_tests.xml @@ -44,6 +44,7 @@ + diff --git a/behavior_tests/src/cmp_cmds_c_opt_test/Makefile b/behavior_tests/src/cmp_cmds_c_opt_test/Makefile new file mode 100644 index 000000000..4b4e378d6 --- /dev/null +++ b/behavior_tests/src/cmp_cmds_c_opt_test/Makefile @@ -0,0 +1,10 @@ +all: one two three + +one: one.cu + $(CC) -O2 --use_fast_math -DKERNEL_USE_PROFILE=1 -gencode arch=compute_${USE_SM},code=sm_${USE_SM} -DRUN_ON_GPU=1 one.cu -o one -allow-unsupported-compiler + +two: two.cu + $(CC) -O2 --use_fast_math -DKERNEL_USE_PROFILE=1 -gencode arch=compute_${USE_SM},code=sm_${USE_SM} -DRUN_ON_GPU=1 two.cu + +three: three.cu four.cu + $(CC) -O2 --use_fast_math -DKERNEL_USE_PROFILE=1 -gencode arch=compute_${USE_SM},code=sm_${USE_SM} -DRUN_ON_GPU=1 three.cu four.cu diff --git a/behavior_tests/src/cmp_cmds_c_opt_test/compile_commands.json_ref b/behavior_tests/src/cmp_cmds_c_opt_test/compile_commands.json_ref new file mode 100644 index 000000000..95d47a602 --- /dev/null +++ b/behavior_tests/src/cmp_cmds_c_opt_test/compile_commands.json_ref @@ -0,0 +1,22 @@ +[ + { + "command": "nvcc -O2 -DKERNEL_USE_PROFILE=1 -DRUN_ON_GPU=1 -o one -allow-unsupported-compiler -D__CUDACC__=1 one.cu", + "directory": "/export/users/dahmed/up/build/tools/clang/test/dpct/compile_commands_c_opt_test/Output/compile_commands_c_opt_test", + "file": "/export/users/dahmed/up/build/tools/clang/test/dpct/compile_commands_c_opt_test/Output/compile_commands_c_opt_test/one.cu" + }, + { + "command": "nvcc -c -O2 -DKERNEL_USE_PROFILE=1 -DRUN_ON_GPU=1 -D__CUDACC__=1 two.cu", + "directory": "/export/users/dahmed/up/build/tools/clang/test/dpct/compile_commands_c_opt_test/Output/compile_commands_c_opt_test", + "file": "/export/users/dahmed/up/build/tools/clang/test/dpct/compile_commands_c_opt_test/Output/compile_commands_c_opt_test/two.cu" + }, + { + "command": "nvcc -c -O2 -DKERNEL_USE_PROFILE=1 -DRUN_ON_GPU=1 -D__CUDACC__=1 three.cu", + "directory": "/export/users/dahmed/up/build/tools/clang/test/dpct/compile_commands_c_opt_test/Output/compile_commands_c_opt_test", + "file": "/export/users/dahmed/up/build/tools/clang/test/dpct/compile_commands_c_opt_test/Output/compile_commands_c_opt_test/three.cu" + }, + { + "command": "nvcc -c -O2 -DKERNEL_USE_PROFILE=1 -DRUN_ON_GPU=1 -D__CUDACC__=1 four.cu", + "directory": "/export/users/dahmed/up/build/tools/clang/test/dpct/compile_commands_c_opt_test/Output/compile_commands_c_opt_test", + "file": "/export/users/dahmed/up/build/tools/clang/test/dpct/compile_commands_c_opt_test/Output/compile_commands_c_opt_test/four.cu" + } +] diff --git a/behavior_tests/src/cmp_cmds_c_opt_test/do_test.py b/behavior_tests/src/cmp_cmds_c_opt_test/do_test.py new file mode 100644 index 000000000..d471aefd0 --- /dev/null +++ b/behavior_tests/src/cmp_cmds_c_opt_test/do_test.py @@ -0,0 +1,49 @@ +# ====------ do_test.py---------- *- Python -* ----===## +# +# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +# +# +# ===----------------------------------------------------------------------===# +import subprocess +import platform +import os +import sys +import json + +from test_utils import * + +def setup_test(): + change_dir(test_config.current_test) + return True + +def parse_compilation_database(compilation_database_name): + if (not os.path.isfile(compilation_database_name)): + print("The compilation database is not existed, please double check\n") + + with open(compilation_database_name) as compilation_database: + compilation_database_items = json.load(compilation_database) + database_source_files = [] + for entry in compilation_database_items: + compilation_item = entry['file']; + database_source_files.append(os.path.basename(compilation_item)) + return database_source_files + +def migrate_test(): + call_subprocess("intercept-build make -f Makefile CC=nvcc USE_SM=70 -B") + new_database = parse_compilation_database("compile_commands.json") + reference_database = parse_compilation_database("compile_commands.json_ref") + new_database = list(set(new_database)) + reference_database = list(set(reference_database)) + new_database.sort() + reference_database.sort() + if(new_database == reference_database): + return True + return False + +def build_test(): + return True + +def run_test(): + return True diff --git a/behavior_tests/src/cmp_cmds_c_opt_test/four.cu b/behavior_tests/src/cmp_cmds_c_opt_test/four.cu new file mode 100644 index 000000000..5cad78566 --- /dev/null +++ b/behavior_tests/src/cmp_cmds_c_opt_test/four.cu @@ -0,0 +1,4 @@ +// RUN: echo +__global__ void foo(){ + +} diff --git a/behavior_tests/src/cmp_cmds_c_opt_test/one.cu b/behavior_tests/src/cmp_cmds_c_opt_test/one.cu new file mode 100644 index 000000000..4cce7f667 --- /dev/null +++ b/behavior_tests/src/cmp_cmds_c_opt_test/one.cu @@ -0,0 +1,3 @@ +int main() { + return 0; +} diff --git a/behavior_tests/src/cmp_cmds_c_opt_test/three.cu b/behavior_tests/src/cmp_cmds_c_opt_test/three.cu new file mode 100644 index 000000000..5cad78566 --- /dev/null +++ b/behavior_tests/src/cmp_cmds_c_opt_test/three.cu @@ -0,0 +1,4 @@ +// RUN: echo +__global__ void foo(){ + +} diff --git a/behavior_tests/src/cmp_cmds_c_opt_test/two.cu b/behavior_tests/src/cmp_cmds_c_opt_test/two.cu new file mode 100644 index 000000000..5cad78566 --- /dev/null +++ b/behavior_tests/src/cmp_cmds_c_opt_test/two.cu @@ -0,0 +1,4 @@ +// RUN: echo +__global__ void foo(){ + +} From 7e5484c937147c6ff6218fa4c9bdef1249368e09 Mon Sep 17 00:00:00 2001 From: "Ahmed, Daiyaan" Date: Wed, 2 Aug 2023 15:25:12 +0800 Subject: [PATCH 2/2] Fix behavior test Signed-off-by: Ahmed, Daiyaan --- .../compile_commands.json_ref | 18 +++---- .../src/cmp_cmds_c_opt_test/do_test.py | 47 ++++++++++++------- 2 files changed, 38 insertions(+), 27 deletions(-) diff --git a/behavior_tests/src/cmp_cmds_c_opt_test/compile_commands.json_ref b/behavior_tests/src/cmp_cmds_c_opt_test/compile_commands.json_ref index 95d47a602..dc49b7317 100644 --- a/behavior_tests/src/cmp_cmds_c_opt_test/compile_commands.json_ref +++ b/behavior_tests/src/cmp_cmds_c_opt_test/compile_commands.json_ref @@ -1,22 +1,22 @@ [ { "command": "nvcc -O2 -DKERNEL_USE_PROFILE=1 -DRUN_ON_GPU=1 -o one -allow-unsupported-compiler -D__CUDACC__=1 one.cu", - "directory": "/export/users/dahmed/up/build/tools/clang/test/dpct/compile_commands_c_opt_test/Output/compile_commands_c_opt_test", - "file": "/export/users/dahmed/up/build/tools/clang/test/dpct/compile_commands_c_opt_test/Output/compile_commands_c_opt_test/one.cu" + "directory": "${TEST_DIRECTORY}", + "file": "${TEST_DIRECTORY}/one.cu" }, { "command": "nvcc -c -O2 -DKERNEL_USE_PROFILE=1 -DRUN_ON_GPU=1 -D__CUDACC__=1 two.cu", - "directory": "/export/users/dahmed/up/build/tools/clang/test/dpct/compile_commands_c_opt_test/Output/compile_commands_c_opt_test", - "file": "/export/users/dahmed/up/build/tools/clang/test/dpct/compile_commands_c_opt_test/Output/compile_commands_c_opt_test/two.cu" + "directory": "${TEST_DIRECTORY}", + "file": "${TEST_DIRECTORY}/two.cu" }, { "command": "nvcc -c -O2 -DKERNEL_USE_PROFILE=1 -DRUN_ON_GPU=1 -D__CUDACC__=1 three.cu", - "directory": "/export/users/dahmed/up/build/tools/clang/test/dpct/compile_commands_c_opt_test/Output/compile_commands_c_opt_test", - "file": "/export/users/dahmed/up/build/tools/clang/test/dpct/compile_commands_c_opt_test/Output/compile_commands_c_opt_test/three.cu" + "directory": "${TEST_DIRECTORY}", + "file": "${TEST_DIRECTORY}/three.cu" }, { "command": "nvcc -c -O2 -DKERNEL_USE_PROFILE=1 -DRUN_ON_GPU=1 -D__CUDACC__=1 four.cu", - "directory": "/export/users/dahmed/up/build/tools/clang/test/dpct/compile_commands_c_opt_test/Output/compile_commands_c_opt_test", - "file": "/export/users/dahmed/up/build/tools/clang/test/dpct/compile_commands_c_opt_test/Output/compile_commands_c_opt_test/four.cu" + "directory": "${TEST_DIRECTORY}", + "file": "${TEST_DIRECTORY}/four.cu" } -] +] \ No newline at end of file diff --git a/behavior_tests/src/cmp_cmds_c_opt_test/do_test.py b/behavior_tests/src/cmp_cmds_c_opt_test/do_test.py index d471aefd0..16c038035 100644 --- a/behavior_tests/src/cmp_cmds_c_opt_test/do_test.py +++ b/behavior_tests/src/cmp_cmds_c_opt_test/do_test.py @@ -6,6 +6,7 @@ # # # ===----------------------------------------------------------------------===# +import filecmp import subprocess import platform import os @@ -14,36 +15,46 @@ from test_utils import * + def setup_test(): change_dir(test_config.current_test) return True + def parse_compilation_database(compilation_database_name): - if (not os.path.isfile(compilation_database_name)): - print("The compilation database is not existed, please double check\n") + if (not os.path.isfile(compilation_database_name)): + print("The compilation database is not existed, please double check\n") + + with open(compilation_database_name) as compilation_database: + compilation_database_items = json.load(compilation_database) + database_source_files = [] + for entry in compilation_database_items: + compilation_item = entry['file'] + database_source_files.append(os.path.basename(compilation_item)) + return database_source_files - with open(compilation_database_name) as compilation_database: - compilation_database_items = json.load(compilation_database) - database_source_files = [] - for entry in compilation_database_items: - compilation_item = entry['file']; - database_source_files.append(os.path.basename(compilation_item)) - return database_source_files def migrate_test(): call_subprocess("intercept-build make -f Makefile CC=nvcc USE_SM=70 -B") - new_database = parse_compilation_database("compile_commands.json") - reference_database = parse_compilation_database("compile_commands.json_ref") - new_database = list(set(new_database)) - reference_database = list(set(reference_database)) - new_database.sort() - reference_database.sort() - if(new_database == reference_database): - return True - return False + test_dir = os.path.join(os.getcwd()) + print(test_dir) + ref_cmp_db_file = open(test_dir+"/compile_commands.json_ref", "rt") + cmp_cmds = ref_cmp_db_file.read() + cmp_cmds = cmp_cmds.replace('${TEST_DIRECTORY}', test_dir) + ref_cmp_db_file.close() + ref_cmp_db_file = open(test_dir+"/compile_commands.json_ref", "wt") + ref_cmp_db_file.write(cmp_cmds) + ref_cmp_db_file.close() + + result = filecmp.cmp(test_dir+"/compile_commands.json", + test_dir+"/compile_commands.json_ref", shallow=False) + + return result + def build_test(): return True + def run_test(): return True