Exemple #1
0
for path in paths:
    files = os.listdir(path)
    for f in files:
        if f[-2:] == 'cl':
            kernel_sources += (path + f,)
        elif f[-3:] == 'clh':
            header_name = f.split('.')[0] + '.clh'
            kernel_headers += ((path + f, header_name),)

# endregion : Load kernel sources

# region : Initialize CL

# > create OpenCL context
cl.create_context()
# > create and build program on context
cl.compile_link_program(kernel_headers, kernel_sources)

print('-=> dip.ip initialized')

# endregion : Initialize CL

# region : Self-test

if __name__ == '__main__':
    import numpy as np

    x = np.zeros((2, 2), np.int32)
    x[0, 0] = 800
    x[0, 1] = 801
Exemple #2
0
a_np = np.random.rand(50000).astype(np.float32)
b_np = np.random.rand(50000).astype(np.float32)
res_np = np.empty_like(a_np)

src = """
__kernel void sum(__global const float *a_g,
                  __global const float *b_g,
                  __global float *res_g) {
  int gid = get_global_id(0);
  res_g[gid] = a_g[gid] + b_g[gid];
}
"""

# create context
context = cl.create_context(cl.device_types.GPU)
print('>>> Context created')

# create and build program
program = context.create_build_program(src)
print('>>> Program created and built')

# create buffers
am = cl.mem_access_mode
hm = cl.mem_host_ptr_mode
a_g = context.create_buffer(am.READ_ONLY, hostbuf=a_np,
                            host_ptr_mode=hm.COPY_HOST_PTR)
b_g = context.create_buffer(am.READ_ONLY, hostbuf=b_np,
                            host_ptr_mode=hm.COPY_HOST_PTR)
res_g = context.create_buffer(am.WRITE_ONLY, a_np.nbytes)
print('>>> Buffers created')
Exemple #3
0
for path in paths:
    files = os.listdir(path)
    for f in files:
        if f[-2:] == 'cl':
            kernel_sources += (path + f, )
        elif f[-3:] == 'clh':
            header_name = f.split('.')[0] + '.clh'
            kernel_headers += ((path + f, header_name), )

# endregion : Load kernel sources

# region : Initialize CL

# > create OpenCL context
cl.create_context()
# > create and build program on context
cl.compile_link_program(kernel_headers, kernel_sources)

print('-=> dip.ip initialized')

# endregion : Initialize CL

# region : Self-test

if __name__ == '__main__':
    import numpy as np

    x = np.zeros((2, 2), np.int32)
    x[0, 0] = 800
    x[0, 1] = 801