Skip to content
Snippets Groups Projects
Commit 24f81cf6 authored by Christoph Alt's avatar Christoph Alt
Browse files

added submodules from cpu and gpu benchmark generation

parent 3e930f35
No related branches found
No related tags found
1 merge request!1Add CUDA support
from .enums import Compiler from .enums import Compiler
from .benchmark import generate_benchmark, kernel_header, kernel_source from . import gpu
from .benchmark_gpu import generate_benchmark_gpu from . import cpu
from .benchmark import generate_benchmark
from .benchmark import generate_benchmark
...@@ -17,13 +17,13 @@ from pystencils_benchmark.common import (_env, ...@@ -17,13 +17,13 @@ from pystencils_benchmark.common import (_env,
from pystencils_benchmark.enums import Compiler from pystencils_benchmark.enums import Compiler
def generate_benchmark_gpu(kernel_asts: Union[KernelFunction, List[KernelFunction]], def generate_benchmark(kernel_asts: Union[KernelFunction, List[KernelFunction]],
path: Path = None, path: Path = None,
*, *,
compiler: Compiler = Compiler.NVCC, compiler: Compiler = Compiler.NVCC,
timing: bool = True, timing: bool = True,
cuda_block_size: tuple = (32, 1, 1) cuda_block_size: tuple = (32, 1, 1)
) -> None: ) -> None:
src_path, include_path = setup_directories(path) src_path, include_path = setup_directories(path)
......
...@@ -6,7 +6,9 @@ import tempfile ...@@ -6,7 +6,9 @@ import tempfile
import pytest import pytest
import pystencils as ps import pystencils as ps
from pathlib import Path from pathlib import Path
from pystencils_benchmark import generate_benchmark, Compiler, generate_benchmark_gpu
from pystencils_benchmark import Compiler
import pystencils_benchmark as pb
compilers = (Compiler.GCC, Compiler.GCCdebug, Compiler.Clang) compilers = (Compiler.GCC, Compiler.GCCdebug, Compiler.Clang)
...@@ -34,7 +36,7 @@ def test_generate(compiler, config_kwarg): ...@@ -34,7 +36,7 @@ def test_generate(compiler, config_kwarg):
with tempfile.TemporaryDirectory(dir=Path.cwd()) as temp_dir: with tempfile.TemporaryDirectory(dir=Path.cwd()) as temp_dir:
temp_dir = Path(temp_dir) temp_dir = Path(temp_dir)
generate_benchmark([kernel_vadd, kernel_daxpy], temp_dir, compiler=compiler) pb.cpu.generate_benchmark([kernel_vadd, kernel_daxpy], temp_dir, compiler=compiler)
subprocess.run(['make', '-C', f'{temp_dir}'], check=True) subprocess.run(['make', '-C', f'{temp_dir}'], check=True)
subprocess.run([f'{temp_dir}/benchmark-{compiler.name}', '10'], check=True) subprocess.run([f'{temp_dir}/benchmark-{compiler.name}', '10'], check=True)
...@@ -50,6 +52,6 @@ def test_generate_gpu(): ...@@ -50,6 +52,6 @@ def test_generate_gpu():
with tempfile.TemporaryDirectory(dir=Path.cwd()) as temp_dir: with tempfile.TemporaryDirectory(dir=Path.cwd()) as temp_dir:
temp_dir = Path(temp_dir) temp_dir = Path(temp_dir)
generate_benchmark_gpu(kernel_vadd, temp_dir, compiler=compiler) pb.gpu.generate_benchmark(kernel_vadd, temp_dir, compiler=compiler)
# subprocess.run(['make', '-C', f'{temp_dir}'], check=True) # subprocess.run(['make', '-C', f'{temp_dir}'], check=True)
# subprocess.run([f'{temp_dir}/benchmark-{compiler.name}', '10'], check=True) # subprocess.run([f'{temp_dir}/benchmark-{compiler.name}', '10'], check=True)
...@@ -4,15 +4,16 @@ import subprocess ...@@ -4,15 +4,16 @@ import subprocess
import numpy as np import numpy as np
import sympy as sp import sympy as sp
import pystencils as ps import pystencils as ps
from pystencils_benchmark import generate_benchmark, Compiler import pystencils_benchmark as pb
from pathlib import Path from pathlib import Path
def generate(path: Path, compiler: Compiler): def generate(path: Path, compiler: pb.Compiler):
a, b, c = ps.fields(a=np.ones(4000000), b=np.ones(4000000), c=np.ones(4000000)) a, b, c = ps.fields(a=np.ones(4000000), b=np.ones(4000000), c=np.ones(4000000))
alpha = sp.symbols('alpha') alpha = sp.symbols('alpha')
kernels = [] kernels = []
@ps.kernel_config(ps.CreateKernelConfig()) @ps.kernel_config(ps.CreateKernelConfig())
def vadd(): def vadd():
a[0] @= b[0] + c[0] a[0] @= b[0] + c[0]
...@@ -33,20 +34,20 @@ def generate(path: Path, compiler: Compiler): ...@@ -33,20 +34,20 @@ def generate(path: Path, compiler: Compiler):
b[0] @= alpha * a[0] + b[0] b[0] @= alpha * a[0] + b[0]
kernels.append(ps.create_kernel(**daxpy_vector)) kernels.append(ps.create_kernel(**daxpy_vector))
generate_benchmark(kernels, path, compiler=compiler) pb.cpu.generate_benchmark(kernels, path, compiler=compiler)
def make(path: Path): def make(path: Path):
subprocess.run(['make'], check=True) subprocess.run(['make'], check=True)
def execute(path: Path, compiler: Compiler): def execute(path: Path, compiler: pb.Compiler):
subprocess.run([f'./benchmark-{compiler.name}', '100'], check=True) subprocess.run([f'./benchmark-{compiler.name}', '100'], check=True)
def main(): def main():
compiler = Compiler.GCCdebug compiler = pb.Compiler.GCCdebug
path = Path.cwd() path = Path.cwd() / 'generated'
generate(path, compiler) generate(path, compiler)
make(path) make(path)
execute(path, compiler) execute(path, compiler)
...@@ -54,4 +55,3 @@ def main(): ...@@ -54,4 +55,3 @@ def main():
if __name__ == '__main__': if __name__ == '__main__':
main() main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment