123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- """Generate burst laminographic backprojection OpenCL kernels."""
- import argparse
- IDX_TO_VEC_ELEM = dict(zip(range(10), range(10)))
- IDX_TO_VEC_ELEM[10] = 'a'
- IDX_TO_VEC_ELEM[11] = 'b'
- IDX_TO_VEC_ELEM[12] = 'c'
- IDX_TO_VEC_ELEM[13] = 'd'
- IDX_TO_VEC_ELEM[14] = 'e'
- IDX_TO_VEC_ELEM[15] = 'f'
- def fill_compute_template(tmpl, num_items, index):
- """Fill the template doing the pixel computation and texture fetch."""
- operation = '+' if index else ''
- access = '.s{}'.format(IDX_TO_VEC_ELEM[index]) if num_items > 1 else ''
- return tmpl.format(index, access, operation)
- def fill_kernel_template(input_tmpl, compute_tmpl, kernel_tmpl, num_items):
- """Construct the whole kernel."""
- vector_length = num_items if num_items > 1 else ''
- computes = '\n'.join([fill_compute_template(compute_tmpl, num_items, i)
- for i in range(num_items)])
- inputs = '\n'.join([input_tmpl.format(i) for i in range(num_items)])
- return kernel_tmpl.format(num_items, inputs, vector_length, computes)
- def parse_args():
- """Parse command line arguments."""
- parser = argparse.ArgumentParser()
- parser.add_argument('filename', type=str, help='File name with the kernel template')
- parser.add_argument('burst', type=int,
- help='Number of projections processed by one kernel invocation')
- return parser.parse_args()
- def main():
- """execute program."""
- args = parse_args()
- allowed_bursts = [2 ** i for i in range(5)]
- if args.burst not in allowed_bursts:
- raise ValueError('Specified burst mode `{}` must be one of `{}`'.format(args.burst,
- allowed_bursts))
- in_tmpl = "read_only image2d_t projection_{},"
- comp_tmpl, ker_tmpl = open(args.filename, 'r').read().split('\n%nl\n')
- print fill_kernel_template(in_tmpl, comp_tmpl, ker_tmpl, args.burst)
- if __name__ == '__main__':
- main()
|