Skip to content
This repository was archived by the owner on Jun 6, 2025. It is now read-only.

Commit 413a4ed

Browse files
committed
Add runtime test
1 parent 702bebd commit 413a4ed

File tree

2 files changed

+81
-6
lines changed

2 files changed

+81
-6
lines changed

conda-recipe/meta.yaml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ source:
2121
folder: compiler
2222
- path: ..
2323

24-
2524
build:
2625
number: {{ build_number }}
2726
skip: True # [not (linux64 or osx or win)]
@@ -39,13 +38,12 @@ outputs:
3938
run:
4039
- python
4140
test:
42-
commands:
43-
- ls -A1 ${PREFIX}/lib/* # [unix]
44-
- dir %PREFIX%\Library\lib\* # [win]
45-
- test -x $(python -c "import dpcpp_llvm_spirv as dls; print(dls.get_llvm_spirv_path())") # [unix]
46-
- python -c "import dpcpp_llvm_spirv as dls, os, sys; sys.exit(0 if os.path.isfile(dls.get_llvm_spirv_path()) else 1)" # [win]
41+
script: run_test.py
4742
imports:
4843
- dpcpp_llvm_spirv
44+
requires:
45+
- spirv-tools
46+
- llvm-tools
4947
about:
5048
home: https://github.com/IntelPython/dpcpp-llvm-spirv.git
5149
license: LicenseRef-Proprietary-Intel-End-User-License-Agreement-for-Developer-Tools

conda-recipe/run_test.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
from os import remove
2+
from subprocess import check_call
3+
from tempfile import NamedTemporaryFile
4+
5+
from dpcpp_llvm_spirv import get_llvm_spirv_path
6+
7+
test_ll = """source_filename = "<string>"
8+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
9+
target triple = "spir64-unknown-unknown"
10+
11+
define i32 @mult(i32 %a, i32 %b) #0 {
12+
%1 = mul nsw i32 %a, %b
13+
ret i32 %1
14+
}"""
15+
16+
expected_spvasm = """; SPIR-V
17+
; Version: 1.0
18+
; Generator: Khronos LLVM/SPIR-V Translator; 14
19+
; Bound: 9
20+
; Schema: 0
21+
OpCapability Addresses
22+
OpCapability Linkage
23+
OpCapability Kernel
24+
%1 = OpExtInstImport "OpenCL.std"
25+
OpMemoryModel Physical64 OpenCL
26+
OpSource Unknown 0
27+
OpName %mult "mult"
28+
OpName %a "a"
29+
OpName %b "b"
30+
OpDecorate %mult LinkageAttributes "mult" Export
31+
%uint = OpTypeInt 32 0
32+
%3 = OpTypeFunction %uint %uint %uint
33+
%mult = OpFunction %uint None %3
34+
%a = OpFunctionParameter %uint
35+
%b = OpFunctionParameter %uint
36+
%7 = OpLabel
37+
%8 = OpIMul %uint %a %b
38+
OpReturnValue %8
39+
OpFunctionEnd
40+
"""
41+
42+
43+
def main():
44+
ll_file = NamedTemporaryFile(prefix="multiply", suffix=".ll")
45+
ll_file.write(test_ll.encode())
46+
ll_file.flush()
47+
48+
name = ll_file.name[:-3]
49+
50+
check_call(["llvm-as", name + ".ll", "-o", name + ".bc"])
51+
check_call(
52+
[
53+
get_llvm_spirv_path(),
54+
"-spirv-max-version=1.0",
55+
name + ".bc",
56+
"-o",
57+
name + ".spv",
58+
]
59+
)
60+
check_call(["spirv-dis", name + ".spv", "-o", name + ".spvasm"])
61+
62+
spv_file = open(name + ".spvasm", "r")
63+
64+
got_spvasm = spv_file.read()
65+
66+
assert got_spvasm == expected_spvasm
67+
68+
# close file and remove all temp files
69+
spv_file.close()
70+
ll_file.close()
71+
remove(name + ".bc")
72+
remove(name + ".spv")
73+
remove(name + ".spvasm")
74+
75+
76+
if __name__ == "__main__":
77+
main()

0 commit comments

Comments
 (0)