--- OpenCL/OpenCL.pm 2012/05/03 23:32:47 1.70 +++ OpenCL/OpenCL.pm 2012/05/04 14:29:35 1.71 @@ -45,7 +45,8 @@ =head2 HELPFUL RESOURCES -The OpenCL specs used to develop this module: +The OpenCL specs used to develop this module - download these and keept +hema round, they are required reference material: http://www.khronos.org/registry/cl/specs/opencl-1.1.pdf http://www.khronos.org/registry/cl/specs/opencl-1.2.pdf @@ -212,7 +213,7 @@ $ev->wait; =head2 Use the OpenGL module to share a texture between OpenCL and OpenGL and draw some julia -set tunnel effect. +set flight effect. This is quite a long example to get you going - you can download it from L. @@ -322,7 +323,7 @@ my $tex = $ctx->image2d (OpenCL::MEM_WRITE_ONLY, OpenCL::RGBA, OpenCL::UNORM_INT8, $S, $S); -And in the darw loop, intead of acquire_gl_objects/release_gl_objects, you +And in the draw loop, intead of acquire_gl_objects/release_gl_objects, you would read the image2d after the kernel has written it: $queue->read_image ($tex, 0, 0, 0, 0, $S, $S, 1, 0, 0, my $data); @@ -334,6 +335,23 @@ The fully modified example can be found at L. +=head2 Julia sets look soooo 80ies. + +Then colour them differently, e.g. using orbit traps! Replace the loop and +colour calculation from the previous examples by this: + + float2 dm = (float2)(1.f, 1.f); + + for (int i = 0; i < 25; ++i) + { + z = (float2)(z.x * z.x - z.y * z.y, 2.f * z.x * z.y) + c; + dm = fmin (dm, (float2)(fabs (dot (z, z) - 1.f), fabs (z.x - 1.f))); + } + + float3 colour = (float3)(dm.x * dm.y, dm.x * dm.y, dm.x); + +Also try C<-10.f> instead of C<-1.f>. + =head1 DOCUMENTATION =head2 BASIC CONVENTIONS @@ -546,6 +564,8 @@ @OpenCL::Kernel::ISA = @OpenCL::Event::ISA = OpenCL::Object::; + @OpenCL::SubDevice::ISA = OpenCL::Device::; + @OpenCL::Buffer::ISA = @OpenCL::Image::ISA = OpenCL::Memory::; @@ -596,6 +616,9 @@ Tries to create a context from a default device and platform type - never worked for me. +type: OpenCL::DEVICE_TYPE_DEFAULT, OpenCL::DEVICE_TYPE_CPU, OpenCL::DEVICE_TYPE_GPU, +OpenCL::DEVICE_TYPE_ACCELERATOR, OpenCL::DEVICE_TYPE_CUSTOM, OpenCL::DEVICE_TYPE_ALL. + L =item $ctx = OpenCL::context $properties, \@devices, $callback->($err, $pvt) = $print_stderr) @@ -718,23 +741,23 @@ =item $string = $platform->profile -Calls C with C and returns the result. +Calls C with C and returns the result. =item $string = $platform->version -Calls C with C and returns the result. +Calls C with C and returns the result. =item $string = $platform->name -Calls C with C and returns the result. +Calls C with C and returns the result. =item $string = $platform->vendor -Calls C with C and returns the result. +Calls C with C and returns the result. =item $string = $platform->extensions -Calls C with C and returns the result. +Calls C with C and returns the result. =for gengetinfo end platform @@ -750,271 +773,277 @@ L +=item @devices = $device->sub_devices (\@properties) + +Creates OpencL::SubDevice objects by partitioning an existing device. + +L + =for gengetinfo begin device =item $device_type = $device->type -Calls C with C and returns the result. +Calls C with C and returns the result. =item $uint = $device->vendor_id -Calls C with C and returns the result. +Calls C with C and returns the result. =item $uint = $device->max_compute_units -Calls C with C and returns the result. +Calls C with C and returns the result. =item $uint = $device->max_work_item_dimensions -Calls C with C and returns the result. +Calls C with C and returns the result. =item $int = $device->max_work_group_size -Calls C with C and returns the result. +Calls C with C and returns the result. =item @ints = $device->max_work_item_sizes -Calls C with C and returns the result. +Calls C with C and returns the result. =item $uint = $device->preferred_vector_width_char -Calls C with C and returns the result. +Calls C with C and returns the result. =item $uint = $device->preferred_vector_width_short -Calls C with C and returns the result. +Calls C with C and returns the result. =item $uint = $device->preferred_vector_width_int -Calls C with C and returns the result. +Calls C with C and returns the result. =item $uint = $device->preferred_vector_width_long -Calls C with C and returns the result. +Calls C with C and returns the result. =item $uint = $device->preferred_vector_width_float -Calls C with C and returns the result. +Calls C with C and returns the result. =item $uint = $device->preferred_vector_width_double -Calls C with C and returns the result. +Calls C with C and returns the result. =item $uint = $device->max_clock_frequency -Calls C with C and returns the result. +Calls C with C and returns the result. =item $bitfield = $device->address_bits -Calls C with C and returns the result. +Calls C with C and returns the result. =item $uint = $device->max_read_image_args -Calls C with C and returns the result. +Calls C with C and returns the result. =item $uint = $device->max_write_image_args -Calls C with C and returns the result. +Calls C with C and returns the result. =item $ulong = $device->max_mem_alloc_size -Calls C with C and returns the result. +Calls C with C and returns the result. =item $int = $device->image2d_max_width -Calls C with C and returns the result. +Calls C with C and returns the result. =item $int = $device->image2d_max_height -Calls C with C and returns the result. +Calls C with C and returns the result. =item $int = $device->image3d_max_width -Calls C with C and returns the result. +Calls C with C and returns the result. =item $int = $device->image3d_max_height -Calls C with C and returns the result. +Calls C with C and returns the result. =item $int = $device->image3d_max_depth -Calls C with C and returns the result. +Calls C with C and returns the result. =item $uint = $device->image_support -Calls C with C and returns the result. +Calls C with C and returns the result. =item $int = $device->max_parameter_size -Calls C with C and returns the result. +Calls C with C and returns the result. =item $uint = $device->max_samplers -Calls C with C and returns the result. +Calls C with C and returns the result. =item $uint = $device->mem_base_addr_align -Calls C with C and returns the result. +Calls C with C and returns the result. =item $uint = $device->min_data_type_align_size -Calls C with C and returns the result. +Calls C with C and returns the result. =item $device_fp_config = $device->single_fp_config -Calls C with C and returns the result. +Calls C with C and returns the result. =item $device_mem_cache_type = $device->global_mem_cache_type -Calls C with C and returns the result. +Calls C with C and returns the result. =item $uint = $device->global_mem_cacheline_size -Calls C with C and returns the result. +Calls C with C and returns the result. =item $ulong = $device->global_mem_cache_size -Calls C with C and returns the result. +Calls C with C and returns the result. =item $ulong = $device->global_mem_size -Calls C with C and returns the result. +Calls C with C and returns the result. =item $ulong = $device->max_constant_buffer_size -Calls C with C and returns the result. +Calls C with C and returns the result. =item $uint = $device->max_constant_args -Calls C with C and returns the result. +Calls C with C and returns the result. =item $device_local_mem_type = $device->local_mem_type -Calls C with C and returns the result. +Calls C with C and returns the result. =item $ulong = $device->local_mem_size -Calls C with C and returns the result. +Calls C with C and returns the result. =item $boolean = $device->error_correction_support -Calls C with C and returns the result. +Calls C with C and returns the result. =item $int = $device->profiling_timer_resolution -Calls C with C and returns the result. +Calls C with C and returns the result. =item $boolean = $device->endian_little -Calls C with C and returns the result. +Calls C with C and returns the result. =item $boolean = $device->available -Calls C with C and returns the result. +Calls C with C and returns the result. =item $boolean = $device->compiler_available -Calls C with C and returns the result. +Calls C with C and returns the result. =item $device_exec_capabilities = $device->execution_capabilities -Calls C with C and returns the result. +Calls C with C and returns the result. =item $command_queue_properties = $device->properties -Calls C with C and returns the result. +Calls C with C and returns the result. =item $ = $device->platform -Calls C with C and returns the result. +Calls C with C and returns the result. =item $string = $device->name -Calls C with C and returns the result. +Calls C with C and returns the result. =item $string = $device->vendor -Calls C with C and returns the result. +Calls C with C and returns the result. =item $string = $device->driver_version -Calls C with C and returns the result. +Calls C with C and returns the result. =item $string = $device->profile -Calls C with C and returns the result. +Calls C with C and returns the result. =item $string = $device->version -Calls C with C and returns the result. +Calls C with C and returns the result. =item $string = $device->extensions -Calls C with C and returns the result. +Calls C with C and returns the result. =item $uint = $device->preferred_vector_width_half -Calls C with C and returns the result. +Calls C with C and returns the result. =item $uint = $device->native_vector_width_char -Calls C with C and returns the result. +Calls C with C and returns the result. =item $uint = $device->native_vector_width_short -Calls C with C and returns the result. +Calls C with C and returns the result. =item $uint = $device->native_vector_width_int -Calls C with C and returns the result. +Calls C with C and returns the result. =item $uint = $device->native_vector_width_long -Calls C with C and returns the result. +Calls C with C and returns the result. =item $uint = $device->native_vector_width_float -Calls C with C and returns the result. +Calls C with C and returns the result. =item $uint = $device->native_vector_width_double -Calls C with C and returns the result. +Calls C with C and returns the result. =item $uint = $device->native_vector_width_half -Calls C with C and returns the result. +Calls C with C and returns the result. =item $device_fp_config = $device->double_fp_config -Calls C with C and returns the result. +Calls C with C and returns the result. =item $device_fp_config = $device->half_fp_config -Calls C with C and returns the result. +Calls C with C and returns the result. =item $boolean = $device->host_unified_memory -Calls C with C and returns the result. +Calls C with C and returns the result. =item $device = $device->parent_device_ext -Calls C with C and returns the result. +Calls C with C and returns the result. =item @device_partition_property_exts = $device->partition_types_ext -Calls C with C and returns the result. +Calls C with C and returns the result. =item @device_partition_property_exts = $device->affinity_domains_ext -Calls C with C and returns the result. +Calls C with C and returns the result. =item $uint = $device->reference_count_ext -Calls C with C and returns the result. +Calls C with C and returns the result. =item @device_partition_property_exts = $device->partition_style_ext -Calls C with C and returns the result. +Calls C with C and returns the result. =for gengetinfo end device @@ -1022,6 +1051,32 @@ =head2 THE OpenCL::Context CLASS +An OpenCL::Context is basically a container, or manager, for a number of +devices of a platform. It is used to create all sorts of secondary objects +such as buffers, queues, programs and so on. + +All context creation functions and methods take a list of properties +(type-value pairs). All property values can be specified as integers - +some additionally support other types: + +=over 4 + +=item OpenCL::CONTEXT_PLATFORM + +Also accepts OpenCL::Platform objects. + +=item OpenCL::GLX_DISPLAY_KHR + +Also accepts C, in which case a deep and troubling hack is engaged +to find the current glx display (see L). + +=item OpenCL::GL_CONTEXT_KHR + +Also accepts C, in which case a deep and troubling hack is engaged +to find the current glx context (see L). + +=back + =over 4 =item $prog = $ctx->build_program ($program, $options = "") @@ -1078,6 +1133,10 @@ Creates a new OpenCL::Buffer (actually OpenCL::BufferObj) object with the given flags and octet-size. +flags: OpenCL::MEM_READ_WRITE, OpenCL::MEM_WRITE_ONLY, OpenCL::MEM_READ_ONLY, +OpenCL::MEM_USE_HOST_PTR, OpenCL::MEM_ALLOC_HOST_PTR, OpenCL::MEM_COPY_HOST_PTR, +OpenCL::MEM_HOST_WRITE_ONLY, OpenCL::MEM_HOST_READ_ONLY, OpenCL::MEM_HOST_NO_ACCESS. + L =item $buf = $ctx->buffer_sv ($flags, $data) @@ -1090,6 +1149,22 @@ Creates a new OpenCL::Image object and optionally initialises it with the given data values. +channel_order: OpenCL::R, OpenCL::A, OpenCL::RG, OpenCL::RA, OpenCL::RGB, +OpenCL::RGBA, OpenCL::BGRA, OpenCL::ARGB, OpenCL::INTENSITY, OpenCL::LUMINANCE, +OpenCL::Rx, OpenCL::RGx, OpenCL::RGBx. + +channel_type: OpenCL::SNORM_INT8, OpenCL::SNORM_INT16, OpenCL::UNORM_INT8, +OpenCL::UNORM_INT16, OpenCL::UNORM_SHORT_565, OpenCL::UNORM_SHORT_555, +OpenCL::UNORM_INT_101010, OpenCL::SIGNED_INT8, OpenCL::SIGNED_INT16, +OpenCL::SIGNED_INT32, OpenCL::UNSIGNED_INT8, OpenCL::UNSIGNED_INT16, +OpenCL::UNSIGNED_INT32, OpenCL::HALF_FLOAT, OpenCL::FLOAT. + + +type: OpenCL::MEM_OBJECT_BUFFER, OpenCL::MEM_OBJECT_IMAGE2D, +OpenCL::MEM_OBJECT_IMAGE3D, OpenCL::MEM_OBJECT_IMAGE2D_ARRAY, +OpenCL::MEM_OBJECT_IMAGE1D, OpenCL::MEM_OBJECT_IMAGE1D_ARRAY, +OpenCL::MEM_OBJECT_IMAGE1D_BUFFER. + L =item $img = $ctx->image2d ($flags, $channel_order, $channel_type, $width, $height, $row_pitch = 0, $data = undef) @@ -1111,6 +1186,8 @@ Creates a new OpenCL::Buffer (actually OpenCL::BufferObj) object that refers to the given OpenGL buffer object. +flags: OpenCL::MEM_READ_WRITE, OpenCL::MEM_READ_ONLY, OpenCL::MEM_WRITE_ONLY. + http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateFromGLBuffer.html =item $img = $ctx->gl_texture ($flags, $target, $miplevel, $texture) @@ -1118,6 +1195,13 @@ Creates a new OpenCL::Image object that refers to the given OpenGL texture object or buffer. +target: GL_TEXTURE_1D, GL_TEXTURE_1D_ARRAY, GL_TEXTURE_BUFFER, +GL_TEXTURE_2D, GL_TEXTURE_2D_ARRAY, GL_TEXTURE_3D, +GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, +GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, +GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, +GL_TEXTURE_RECTANGLE/GL_TEXTURE_RECTANGLE_ARB. + http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clCreateFromGLTexture.html =item $img = $ctx->gl_texture2d ($flags, $target, $miplevel, $texture) @@ -1152,6 +1236,11 @@ Creates a new OpenCL::Sampler object. +addressing_mode: OpenCL::ADDRESS_NONE, OpenCL::ADDRESS_CLAMP_TO_EDGE, +OpenCL::ADDRESS_CLAMP, OpenCL::ADDRESS_REPEAT, OpenCL::ADDRESS_MIRRORED_REPEAT. + +filter_mode: OpenCL::FILTER_NEAREST, OpenCL::FILTER_LINEAR. + L =item $program = $ctx->program_with_source ($string) @@ -1171,6 +1260,12 @@ my $clone = $ctx->program_with_binary ([$prog->devices], [$prog->binaries]); +=item $program = $ctx->program_with_built_in_kernels (\@devices, $kernel_names) + +Creates a new OpenCL::Program object from the given built-in kernel names. + +L + =item $packed_value = $ctx->info ($name) See C<< $platform->info >> for details. @@ -1181,19 +1276,19 @@ =item $uint = $context->reference_count -Calls C with C and returns the result. +Calls C with C and returns the result. =item @devices = $context->devices -Calls C with C and returns the result. +Calls C with C and returns the result. =item @property_ints = $context->properties -Calls C with C and returns the result. +Calls C with C and returns the result. =item $uint = $context->num_devices -Calls C with C and returns the result. +Calls C with C and returns the result. =for gengetinfo end context @@ -1319,6 +1414,14 @@ L +=item $ev = $queue->migrate_mem_objects (\@mem_objects, $flags, $wait_events...) + +Migrates a number of OpenCL::Memory objects to or from the device. + +flags: OpenCL::MIGRATE_MEM_OBJECT_HOST, OpenCL::MIGRATE_MEM_OBJECT_CONTENT_UNDEFINED + +L + =item $ev = $queue->acquire_gl_objects ([object, ...], $wait_events...) Enqueues a list (an array-ref of OpenCL::Memory objects) to be acquired @@ -1363,19 +1466,19 @@ =item $ctx = $command_queue->context -Calls C with C and returns the result. +Calls C with C and returns the result. =item $device = $command_queue->device -Calls C with C and returns the result. +Calls C with C and returns the result. =item $uint = $command_queue->reference_count -Calls C with C and returns the result. +Calls C with C and returns the result. =item $command_queue_properties = $command_queue->properties -Calls C with C and returns the result. +Calls C with C and returns the result. =for gengetinfo end command_queue @@ -1404,6 +1507,8 @@ C object. If C<$size> is specified as undef, then the map will extend to the end of the buffer. +map_flags: OpenCL::MAP_READ, OpenCL::MAP_WRITE, OpenCL::MAP_WRITE_INVALIDATE_REGION. + L Example: map the buffer $buf fully and replace the first 4 bytes by "abcd", then unmap. @@ -1465,39 +1570,39 @@ =item $mem_object_type = $mem->type -Calls C with C and returns the result. +Calls C with C and returns the result. =item $mem_flags = $mem->flags -Calls C with C and returns the result. +Calls C with C and returns the result. =item $int = $mem->size -Calls C with C and returns the result. +Calls C with C and returns the result. =item $ptr_value = $mem->host_ptr -Calls C with C and returns the result. +Calls C with C and returns the result. =item $uint = $mem->map_count -Calls C with C and returns the result. +Calls C with C and returns the result. =item $uint = $mem->reference_count -Calls C with C and returns the result. +Calls C with C and returns the result. =item $ctx = $mem->context -Calls C with C and returns the result. +Calls C with C and returns the result. =item $mem = $mem->associated_memobject -Calls C with C and returns the result. +Calls C with C and returns the result. =item $int = $mem->offset -Calls C with C and returns the result. +Calls C with C and returns the result. =for gengetinfo end mem @@ -1559,27 +1664,27 @@ =item $int = $image->element_size -Calls C with C and returns the result. +Calls C with C and returns the result. =item $int = $image->row_pitch -Calls C with C and returns the result. +Calls C with C and returns the result. =item $int = $image->slice_pitch -Calls C with C and returns the result. +Calls C with C and returns the result. =item $int = $image->width -Calls C with C and returns the result. +Calls C with C and returns the result. =item $int = $image->height -Calls C with C and returns the result. +Calls C with C and returns the result. =item $int = $image->depth -Calls C with C and returns the result. +Calls C with C and returns the result. =for gengetinfo end image @@ -1587,11 +1692,11 @@ =item $GLenum = $gl_texture->target -Calls C with C and returns the result. +Calls C with C and returns the result. =item $GLint = $gl_texture->gl_mipmap_level -Calls C with C and returns the result. +Calls C with C and returns the result. =for gengetinfo end gl_texture @@ -1611,23 +1716,23 @@ =item $uint = $sampler->reference_count -Calls C with C and returns the result. +Calls C with C and returns the result. =item $ctx = $sampler->context -Calls C with C and returns the result. +Calls C with C and returns the result. =item $addressing_mode = $sampler->normalized_coords -Calls C with C and returns the result. +Calls C with C and returns the result. =item $filter_mode = $sampler->addressing_mode -Calls C with C and returns the result. +Calls C with C and returns the result. =item $boolean = $sampler->filter_mode -Calls C with C and returns the result. +Calls C with C and returns the result. =for gengetinfo end sampler @@ -1655,6 +1760,14 @@ Some implementations fail with C when the compilation state is successful but some later stage fails. +options: C<-D name>, C<-D name=definition>, C<-I dir>, +C<-cl-single-precision-constant>, C<-cl-denorms-are-zero>, +C<-cl-fp32-correctly-rounded-divide-sqrt>, C<-cl-opt-disable>, +C<-cl-mad-enable>, C<-cl-no-signed-zeros>, C<-cl-unsafe-math-optimizations>, +C<-cl-finite-math-only>, C<-cl-fast-relaxed-math>, +C<-w>, C<-Werror>, C<-cl-std=CL1.1/CL1.2>, C<-cl-kernel-arg-info>, +C<-create-library>, C<-enable-link-options>. + L =item $program->build_async (\@devices = undef, $options = "", $cb->($program) = undef) @@ -1686,15 +1799,18 @@ =item $build_status = $program->build_status ($device) -Calls C with C and returns the result. +Calls C with C and returns the result. + +build_status: OpenCL::BUILD_SUCCESS, OpenCL::BUILD_NONE, +OpenCL::BUILD_ERROR, OpenCL::BUILD_IN_PROGRESS. =item $string = $program->build_options ($device) -Calls C with C and returns the result. +Calls C with C and returns the result. =item $string = $program->build_log ($device) -Calls C with C and returns the result. +Calls C with C and returns the result. =for gengetinfo end program_build @@ -1708,27 +1824,27 @@ =item $uint = $program->reference_count -Calls C with C and returns the result. +Calls C with C and returns the result. =item $ctx = $program->context -Calls C with C and returns the result. +Calls C with C and returns the result. =item $uint = $program->num_devices -Calls C with C and returns the result. +Calls C with C and returns the result. =item @devices = $program->devices -Calls C with C and returns the result. +Calls C with C and returns the result. =item $string = $program->source -Calls C with C and returns the result. +Calls C with C and returns the result. =item @ints = $program->binary_sizes -Calls C with C and returns the result. +Calls C with C and returns the result. =for gengetinfo end program @@ -1759,23 +1875,23 @@ =item $string = $kernel->function_name -Calls C with C and returns the result. +Calls C with C and returns the result. =item $uint = $kernel->num_args -Calls C with C and returns the result. +Calls C with C and returns the result. =item $uint = $kernel->reference_count -Calls C with C and returns the result. +Calls C with C and returns the result. =item $ctx = $kernel->context -Calls C with C and returns the result. +Calls C with C and returns the result. =item $program = $kernel->program -Calls C with C and returns the result. +Calls C with C and returns the result. =for gengetinfo end kernel @@ -1792,23 +1908,23 @@ =item $int = $kernel->work_group_size ($device) -Calls C with C and returns the result. +Calls C with C and returns the result. =item @ints = $kernel->compile_work_group_size ($device) -Calls C with C and returns the result. +Calls C with C and returns the result. =item $ulong = $kernel->local_mem_size ($device) -Calls C with C and returns the result. +Calls C with C and returns the result. =item $int = $kernel->preferred_work_group_size_multiple ($device) -Calls C with C and returns the result. +Calls C with C and returns the result. =item $ulong = $kernel->private_mem_size ($device) -Calls C with C and returns the result. +Calls C with C and returns the result. =for gengetinfo end kernel_work_group @@ -1932,23 +2048,23 @@ =item $queue = $event->command_queue -Calls C with C and returns the result. +Calls C with C and returns the result. =item $command_type = $event->command_type -Calls C with C and returns the result. +Calls C with C and returns the result. =item $uint = $event->reference_count -Calls C with C and returns the result. +Calls C with C and returns the result. =item $uint = $event->command_execution_status -Calls C with C and returns the result. +Calls C with C and returns the result. =item $ctx = $event->context -Calls C with C and returns the result. +Calls C with C and returns the result. =for gengetinfo end event @@ -1965,19 +2081,19 @@ =item $ulong = $event->profiling_command_queued -Calls C with C and returns the result. +Calls C with C and returns the result. =item $ulong = $event->profiling_command_submit -Calls C with C and returns the result. +Calls C with C and returns the result. =item $ulong = $event->profiling_command_start -Calls C with C and returns the result. +Calls C with C and returns the result. =item $ulong = $event->profiling_command_end -Calls C with C and returns the result. +Calls C with C and returns the result. =for gengetinfo end profiling @@ -1994,6 +2110,8 @@ Sets the execution status of the user event. Can only be called once, either with OpenCL::COMPLETE or a negative number as status. +execution_status: OpenCL::COMPLETE or a negative integer. + L =back