예제 #1
0
   /* Execute the first example */
   uint8 mask1 = (uint8)(1, 2, 0, 1, 3, 1, 2, 3);
   float4 input = (float4)(0.25f, 0.5f, 0.75f, 1.0f);
   *s1 = shuffle(input, mask1);

   /* Execute the second example */
   uchar16 mask2 = (uchar16)(6, 10, 5, 2, 8, 0, 9, 14,
                             7, 5, 12, 3, 11, 15, 1, 13);
   char8 input1 = (char8)('l', 'o', 'f', 'c', 'a', 'u', 's', 'f');
   char8 input2 = (char8)('f', 'e', 'h', 't', 'n', 'n', '2', 'i');
   *s2 = shuffle2(input1, input2, mask2);
}
'''

# Get device and context, create command queue and program
dev = utility.get_default_device()
context = cl.Context(devices=[dev], properties=None, dev_type=None, cache_dir=None)
queue = cl.CommandQueue(context, dev, properties=None)

# Build program in the specified context using the kernel source code
prog = cl.Program(context, kernel_src)
try:
    prog.build(options=['-Werror'], devices=[dev], cache_dir=None)
except:
    print('Build log:')
    print(prog.get_build_info(dev, cl.program_build_info.LOG))
    raise

# Data and buffers
s1 = cl.array.vec.zeros_float8()
s2 = np.empty(shape=(16,), dtype=np.character)  # zeros_char16 would also work
예제 #2
0
   a = 0;
   b = 0;

   /* Increment without atomic add */
   a++;

   /* Increment with atomic add */
   atomic_inc(&b);

   x[0] = a;
   x[1] = b;
}
'''

# Get device and context, create command queue and program
dev = utility.get_default_device()
context = cl.Context(devices=[dev],
                     properties=None,
                     dev_type=None,
                     cache_dir=None)
queue = cl.CommandQueue(context, dev, properties=None)

# Build program in the specified context using the kernel source code
prog = cl.Program(context, kernel_src)
try:
    prog.build(options=['-Werror'], devices=[dev], cache_dir=None)
except:
    print('Build log:')
    print(prog.get_build_info(dev, cl.program_build_info.LOG))
    raise
예제 #3
0
    while(LOCK(mutex));
    *sum += 1;
    UNLOCK(mutex);
    int waiting = 1;
    while(waiting) {
        while(LOCK(mutex));
        if(*sum == get_global_size(0)) {
            waiting = 0;
        }
        UNLOCK(mutex);
    }
}
'''

# Get device and context, create command queue and program
dev = utility.get_default_device(use_gpu=False)
context = cl.Context(devices=[dev], properties=None, dev_type=None, cache_dir=None)
queue = cl.CommandQueue(context, dev, properties=None)

# Check for cl_khr_global_int32_base_atomics availability
if 'cl_khr_global_int32_base_atomics' not in dev.extensions.strip().split(' '):
    raise RuntimeError('Selected device does not support int32 atomic operations.')

# Build program in the specified context using the kernel source code
prog = cl.Program(context, kernel_src)
try:
    prog.build(options=['-Werror'], devices=[dev], cache_dir=None)
except:
    print('Build log:')
    print(prog.get_build_info(dev, cl.program_build_info.LOG))
    raise