Skip to content
Snippets Groups Projects
Verified Commit 34ba269a authored by raphael.bach's avatar raphael.bach
Browse files

Remove `gen_futhark.py`

parent a65fc29d
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python
# SPDX-License-Identifier: 0BSD
#
# @file
# @license{
# BSD Zero Clause License
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
# }
LICENSE_STR = """\
-- SPDX-License-Identifier: 0BSD
--
-- @license{
-- BSD Zero Clause License
--
-- Permission to use, copy, modify, and/or distribute this software for any
-- purpose with or without fee is hereby granted.
--
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
-- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
-- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
-- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-- PERFORMANCE OF THIS SOFTWARE.
-- }
"""
OUTPUT_PATH = './'
INPUT_PATH = OUTPUT_PATH
DIM_MAX = 3
FUTHARK_TYPE_LIST = [
'i8', 'i16', 'i32', 'i64',
'u8', 'u16', 'u32', 'u64',
'f32', 'f64', 'bool'
]
C_TYPE_LIST = [
'int8_t', 'int16_t', 'int32_t', 'int64_t',
'uint8_t', 'uint16_t', 'uint32_t', 'uint64_t',
'float', 'double', '_Bool'
]
TYPE_LIST_LENGTH = len(FUTHARK_TYPE_LIST)
def futharkmpi_c_types():
str = ''
for type in TYPE_LIST:
for i in range (1, DIM_MAX+1):
str += 'entry make_futhark_{type}_{dim}d (xs: {array}{type}): {type} = 0\n'.format(type = type, dim = i, array = i * "[]")
return str
def futharkmpi_reduce():
str = 'import "{path}"\n\n'.format(path=INPUT_PATH + 'futharkmpi_module_reduce')
func_list = ['sum', 'prod', 'min', 'max']
for i in range(TYPE_LIST_LENGTH):
str += 'module reduce_{type} = module_reduce {type}\n'.format(type = FUTHARK_TYPE_LIST[i])
for func in func_list:
str += 'entry reduce_{func}_{ctype} = reduce_{ftype}.{func}\n'.format(func = func, ctype = C_TYPE_LIST[i], ftype = FUTHARK_TYPE_LIST[i])
return str
##
# Create a file and write generated code to it.
#
# @param generator : A function returning a string containing the generated
# code. Its name is used as a prefix for the file name.
def generate_file(generator):
file_name = generator.__name__ + '.fut'
with open(OUTPUT_PATH + file_name, 'w') as fd:
fd.write(LICENSE_STR)
fd.write(generator())
def main(args):
generator_list = [futharkmpi_reduce]
for generator in generator_list:
generate_file(generator)
return 0
if __name__ == '__main__':
import sys
sys.exit(main(sys.argv))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment