import json
import codecs
def generate_code_file():
config = {}
with codecs.open("config.json","rb","UTF-8") as f:
config = json.loads(f.read())
if not config:
return
s = ""
template = config.get("templateFile")
with codecs.open(template, "rb", "UTF-8") as f:
s = f.read()
if not s:
return
s = s % config
fn = config["fileNamePrefix"]
with codecs.open(fn, "wb", "UTF-8") as f:
f.write(s)
f.flush()
def generate_a_batch_of_code_file():
config = {}
with codecs.open("config.json","rb","UTF-8") as f:
config = json.loads(f.read())
if not config:
return
s_template = ""
template = config.get("templateFile")
with codecs.open(template, "rb", "UTF-8") as f:
s_template = f.read()
if not s_template:
return
for i in range(1, 8):
config["kernelSize"] = str(i)
s = s_template % config
fn = config["fileNamePrefix"] + "_" +\
config["nonlineTypeLower"] +\
"_ksize" + str(i) + ".cu"
print('generating {}...'.format(fn))
with codecs.open(fn, "wb", "UTF-8") as f:
f.write(s)
f.flush()
if __name__ == '__main__':
generate_a_batch_of_code_file()
try:
generate_code_file()
except Exception, ex:
print(ex)