1 module dcl.helpers; 2 3 import dcl; 4 5 import std.typecons; 6 7 alias tss = Tuple!(string,string); 8 9 /// full info about platform 10 auto getCLPlatformFullInfo( CLPlatform pl ) 11 { 12 return [ 13 tss("platform" , pl.name), 14 tss("vendor" , pl.vendor), 15 tss("profile" , pl.profile), 16 tss("version" , pl._version), 17 tss("ext" , pl.extensions), 18 ]; 19 } 20 21 /// full info about platform as string 22 string getCLPlatformFullInfoString( CLPlatform pl, string fmt="", string sep="\n" ) 23 { return formatInfo( getCLPlatformFullInfo(pl), fmt, sep ); } 24 25 /// full info about device 26 auto getCLDeviceFullInfo( CLDevice dev ) 27 { 28 return [ 29 tss("type - name" , format( "%s - %s", fmtFlags(dev.typeMask,[CLDevice.Type.ALL]), dev.name ) ), 30 tss("available" , format( "dev:%s compiler:%s linker:%s", dev.available, dev.compiler_available, dev.linker_available ) ), 31 tss("max_compute_units" , format( "%s", dev.max_compute_units ) ), 32 tss("max_work_item_dimensions" , format( "%s", dev.max_work_item_dimensions ) ), 33 tss("max_work_group_size" , format( "%s", dev.max_work_group_size ) ), 34 tss("max_work_item_sizes" , format( "%s", dev.max_work_item_sizes ) ), 35 tss("image_support" , format( "%s", dev.image_support ) ), 36 tss("max_read_image_args" , format( "%s", dev.max_read_image_args ) ), 37 tss("max_write_image_args" , format( "%s", dev.max_write_image_args ) ), 38 tss("max image2d size" , format( "[%d, %d]", dev.image2d_max_width, dev.image2d_max_height ) ), 39 tss("max image3d size" , format( "[%d, %d, %d]", dev.image3d_max_width, dev.image3d_max_height, dev.image3d_max_depth ) ), 40 tss("image_max_buffer_size" , format( "%s px", dev.image_max_buffer_size ) ), 41 tss("image_max_array_size" , format( "%s", dev.image_max_array_size ) ), 42 tss("address_bits" , format( "%s", dev.address_bits ) ), 43 tss("max_mem_alloc_size" , fmtSize( dev.max_mem_alloc_size ) ), 44 tss("max_clock_frequency" , format( "%s MHz (%.2e sec)", dev.max_clock_frequency, 1.0f / ( dev.max_clock_frequency * 1e6 ) ) ), 45 tss("max_parameter_size" , fmtSize( dev.max_parameter_size ) ), 46 tss("max_samplers" , format( "%s", dev.max_samplers ) ), 47 tss("mem_base_addr_align" , format( "%s bits", dev.mem_base_addr_align ) ), 48 tss("global_mem_cache_type" , format( "%s", dev.global_mem_cache_type ) ), 49 tss("global_mem_cacheline_size" , format( "%s", fmtSize( dev.global_mem_cacheline_size ) ) ), 50 tss("global_mem_cache_size" , format( "%s", fmtSize( dev.global_mem_cache_size ) ) ), 51 tss("global_mem_size" , format( "%s", fmtSize( dev.global_mem_size ) ) ), 52 tss("max_constant_buffer_size" , format( "%s", fmtSize( dev.max_constant_buffer_size ) ) ), 53 tss("max_constant_args" , format( "%s", dev.max_constant_args ) ), 54 tss("local_mem_type" , format( "%s", dev.local_mem_type ) ), 55 tss("local_mem_size" , format( "%s", fmtSize( dev.local_mem_size ) ) ), 56 tss("error_correction_support" , format( "%s", dev.error_correction_support ) ), 57 tss("profiling_timer_resolution" , format( "%s ns", dev.profiling_timer_resolution ) ), 58 tss("endian_little" , format( "%s", dev.endian_little ) ), 59 tss("preferred vector width" , format( "char:%s short:%s int:%s long:%s half:%s float:%s double:%s", 60 dev.preferred_vector_width_char, 61 dev.preferred_vector_width_short, 62 dev.preferred_vector_width_int, 63 dev.preferred_vector_width_long, 64 dev.preferred_vector_width_half, 65 dev.preferred_vector_width_float, 66 dev.preferred_vector_width_double ) ), 67 tss("native vector width" , format( "char:%s short:%s int:%s long:%s half:%s float:%s double:%s", 68 dev.native_vector_width_char, 69 dev.native_vector_width_short, 70 dev.native_vector_width_int, 71 dev.native_vector_width_long, 72 dev.native_vector_width_half, 73 dev.native_vector_width_float, 74 dev.native_vector_width_double ) ), 75 tss("execution_capabilities" , format( "%s", fmtFlags!(CLDevice.ExecCapabilities)(dev.execution_capabilities) ) ), 76 tss("queue_properties" , format( "%s", fmtFlags!(CLCommandQueue.Properties)(dev.queue_properties) ) ), 77 tss("vendor" , format( "%s (id:%s)", dev.vendor, dev.vendor_id ) ), 78 tss("driver_version" , format( "%s", dev.driver_version ) ), 79 tss("profile" , format( "%s", dev.profile ) ), 80 tss("version" , format( "%s", dev._version ) ), 81 tss("extensions" , format( "%s", dev.extensions ) ), 82 tss("built_in_kernels" , format( "%s", dev.built_in_kernels ) ), 83 tss("opencl_c_version" , format( "%s", dev.opencl_c_version ) ), 84 //tss("platform" , format( "%s", dev.platform ) ), 85 tss("single_fp_config" , format( "%s", fmtFlags!(CLDevice.FPConfig)(dev.single_fp_config) ) ), 86 tss("double_fp_config" , format( "%s", fmtFlags!(CLDevice.FPConfig)(dev.double_fp_config) ) ), 87 tss("host_unified_memory" , format( "%s", dev.host_unified_memory ) ), 88 tss("is root device" , format( "%s", !dev.parent_device ) ), 89 tss("partition_max_sub_devices" , format( "%s", dev.partition_max_sub_devices ) ), 90 tss("partition_properties" , format( "%s", dev.partition_properties ) ), 91 tss("partition_affinity_domain" , format( "%s", dev.partition_affinity_domain ) ), 92 tss("partition_type" , format( "%s", dev.partition_type ) ), 93 tss("reference_count" , format( "%s", dev.refcount ) ), 94 tss("preferred_interop_user_sync" , format( "%s", dev.preferred_interop_user_sync ) ), 95 tss("printf_buffer_size" , fmtSize( dev.printf_buffer_size ) ), 96 ]; 97 } 98 99 /// full info about device as string 100 string getCLDeviceFullInfoString( CLDevice dev, string fmt="", string sep="\n" ) 101 { return formatInfo( getCLDeviceFullInfo(dev), fmt, sep ); } 102 103 string formatInfo( Tuple!(string,string)[] info, string fmt="", string sep="\n" ) 104 { 105 string[] ret; 106 107 if( fmt == "" ) fmt = " %30 s : %s"; 108 109 foreach( item; info ) 110 ret ~= format( fmt, item[0], item[1] ); 111 112 return ret.join(sep); 113 } 114 115 import std.traits; 116 117 string fmtSize( ulong bytes ) 118 { 119 string ret = format( "%d bytes", bytes ); 120 if( bytes < 1024 ) return ret; 121 122 enum sizes = [ "", "Ki", "Mi", "Gi", "Ti", "Pi" ]; 123 float size = bytes; 124 ubyte k; 125 do { k++; size /= 1024; } while( size > 1024 ); 126 return format( "%.2f %s (%s)", size, sizes[k]~"b", ret ); 127 } 128 129 string fmtFlags(T)( ulong mask, T[] without=[] ) 130 { return parseFlags!T(mask,without).map!(a=>format("%s",a)).array.join("|"); }