File: generate_memcpy.py

package info (click to toggle)
devicexlib 0.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 7,528 kB
  • sloc: fortran: 15,429; f90: 7,388; sh: 3,287; makefile: 229; python: 108; ansic: 62
file content (53 lines) | stat: -rwxr-xr-x 1,628 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
49
50
51
52
53
#!/usr/bin/env python3

import sys, os, jinja2
from shutil import copyfile

def render(tpl_path, context):
    path, filename = os.path.split(tpl_path)
    return jinja2.Environment(undefined=jinja2.StrictUndefined,
        loader=jinja2.FileSystemLoader(path or './')
    ).get_template(filename).render(context)

####

types_l=['real', 'complex', 'integer']

sp_d={'name':'sp', 'val':'real32'}
dp_d={'name':'dp', 'val':'real64'}
i4_d={'name':'i4', 'val':'int32'}
i8_d={'name':'i8', 'val':'int64'}

kinds_d={'real':    [sp_d, dp_d] , 
         'complex': [sp_d, dp_d] , 
         'integer': [i4_d] }
#         'integer': [i4_d, i8_d] }

nranks=4

# Generate subroutines
with open('device_memcpy.f90', 'w') as f:
    f.write(render('device_memcpy.jf90', 
                    {'types' : types_l, 'kinds' : kinds_d, 'dimensions': nranks }
                  ))

# Generate interfaces
with open('device_memcpy_interf.f90', 'w') as f:
    f.write(render('device_memcpy_interf.jf90', 
                    {'types' : types_l, 'kinds' : kinds_d, 'dimensions': nranks }
                  ))
            
# Generate tests
with open('test_memcpy.f90', 'w') as f:
    f.write(render('test_memcpy.jf90', 
                    {'types' : types_l, 'kinds' : kinds_d, 'dimensions': nranks }
                  ))
with open('test_memcpy_async.f90', 'w') as f:
    f.write(render('test_memcpy_async.jf90', 
                    {'types' : types_l, 'kinds' : kinds_d, 'dimensions': nranks }
                  ))

# set multiple extensions
copyfile("device_memcpy.f90","device_memcpy.F")
copyfile("device_memcpy_interf.f90","device_memcpy_interf.F")