To protect your data, the CISO officer has suggested users to enable GitLab 2FA as soon as possible.

wasm.py 2.55 KB
Newer Older
Zixian Cai's avatar
Zixian Cai committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/env python3
# Copyright 2017 The Australian National University
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import time
import subprocess as subproc

from mubench.lang import Language
from mubench import CALLBACKS_DIR
22
from mubench.util import expandenv, run_in_subproc
23
from types import SimpleNamespace
Zixian Cai's avatar
Zixian Cai committed
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

logger = logging.getLogger(__name__)


class WASM(Language):
    name = 'wasm'
    src_ext = 'c'
    compiled = True
    default_exec = 'emcc'  # assume presence of clang

    @classmethod
    def get_default_target(cls, task):
        target_dir = task.output_dir
        target_name = '%s-%s.js' % (task.taskset.name, task.name)
        target = target_dir / target_name
        return target

    @classmethod
    def check_compiler(cls, cc, lc, task):
        exe = cc.get('exec', cls.default_exec)
        cc['exec'] = expandenv(exe, task.env)
        return cc

    @classmethod
    def compile(cls, task):
John Zhang's avatar
John Zhang committed
49
        callback_dir = CALLBACKS_DIR
Zixian Cai's avatar
Zixian Cai committed
50
51
52
53
54
55
        cc = task.compiler

        cmd = []
        cmd.append(cc['exec'])

        # flags
56
        flags = ['-s', "WASM=1", '-D__WASM__']
Zixian Cai's avatar
Zixian Cai committed
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
        include_flags = ['-I%(callback_dir)s' % locals()]
        cc_flags = list(
            map(lambda a: expandenv(a, task.env), cc.get('flags', [])))
        flags.extend(cc_flags)
        flags.extend(include_flags)
        target = cls.get_default_target(task)
        flags.extend(['-o', str(target)])
        cmd.extend(flags)

        cmd.append(task.srcfile)

        # callback selected at compile time, initialised at runtime
        callback_file = callback_dir / ('cb_%(name)s.c' % task.callback)
        cmd.append(callback_file)

72
        run_in_subproc(cmd, task.env)
Zixian Cai's avatar
Zixian Cai committed
73
74

        assert target.exists()
Zixian Cai's avatar
Zixian Cai committed
75
        return target
Zixian Cai's avatar
Zixian Cai committed
76
77
78
79
80

    @classmethod
    def run(cls, target, task):
        cmd = ["node"]

Zixian Cai's avatar
Zixian Cai committed
81
        cmd.append(target.resolve())
Zixian Cai's avatar
Zixian Cai committed
82
83
84
85
86
87

        # first argument: callback param
        cmd.append(task.callback['param'])

        cmd.extend(task.benchmark['args'])

88
        return run_in_subproc(cmd, task.env,
89
                                  cwd=str(target.parent.resolve()))