|
| 1 | +#include <stdio.h> |
| 2 | +#include <stdlib.h> |
| 3 | +#include <string.h> |
| 4 | + |
| 5 | +#ifdef _MSC_VER |
| 6 | + |
| 7 | +#define stop() __debugbreak() |
| 8 | +#include <windows.h> |
| 9 | +#define int64 __int64 |
| 10 | +#pragma warning(disable:4127) |
| 11 | + |
| 12 | +#define get_milliseconds GetTickCount |
| 13 | + |
| 14 | +#else |
| 15 | + |
| 16 | +#define stop() __builtin_trap() |
| 17 | +#define int64 long long |
| 18 | + |
| 19 | +typedef unsigned int U32; |
| 20 | +typedef unsigned long long U64; |
| 21 | + |
| 22 | +#include <time.h> |
| 23 | +static int get_milliseconds() |
| 24 | +{ |
| 25 | + struct timespec ts; |
| 26 | + clock_gettime( CLOCK_MONOTONIC, &ts ); |
| 27 | + return (U32) ( ( ((U64)(U32)ts.tv_sec) * 1000LL ) + (U64)(((U32)ts.tv_nsec+500000)/1000000) ); |
| 28 | +} |
| 29 | + |
| 30 | +#endif |
| 31 | + |
| 32 | +#if defined(TIME_SIMD) |
| 33 | + // default for most platforms |
| 34 | +#elif defined(TIME_SCALAR) |
| 35 | + #define STBIR_NO_SIMD |
| 36 | +#else |
| 37 | + #error You must define TIME_SIMD or TIME_SCALAR when compiling this file. |
| 38 | +#endif |
| 39 | + |
| 40 | +#define STBIR_PROFILE |
| 41 | +#define STB_IMAGE_RESIZE_IMPLEMENTATION |
| 42 | +#define STBIR__V_FIRST_INFO_BUFFER v_info |
| 43 | +#include "stb_image_resize2.h" // new one! |
| 44 | + |
| 45 | +#if defined(TIME_SIMD) && !defined(STBIR_SIMD) |
| 46 | +#error Timing SIMD, but scalar was ON! |
| 47 | +#endif |
| 48 | + |
| 49 | +#if defined(TIME_SCALAR) && defined(STBIR_SIMD) |
| 50 | +#error Timing scalar, but SIMD was ON! |
| 51 | +#endif |
| 52 | + |
| 53 | +#define HEADER 32 |
| 54 | + |
| 55 | + |
| 56 | +static int file_write( const char *filename, void * buffer, size_t size ) |
| 57 | +{ |
| 58 | + FILE * f = fopen( filename, "wb" ); |
| 59 | + if ( f == 0 ) return 0; |
| 60 | + if ( fwrite( buffer, 1, size, f) != size ) return 0; |
| 61 | + fclose(f); |
| 62 | + return 1; |
| 63 | +} |
| 64 | + |
| 65 | +int64 nresize( void * o, int ox, int oy, int op, void * i, int ix, int iy, int ip, int buf, int type, int edg, int flt ) |
| 66 | +{ |
| 67 | + STBIR_RESIZE resize; |
| 68 | + int t; |
| 69 | + int64 b; |
| 70 | + |
| 71 | + stbir_resize_init( &resize, i, ix, iy, ip, o, ox, oy, op, buf, type ); |
| 72 | + stbir_set_edgemodes( &resize, edg, edg ); |
| 73 | + stbir_set_filters( &resize, flt, flt ); |
| 74 | + |
| 75 | + stbir_build_samplers_with_splits( &resize, 1 ); |
| 76 | + |
| 77 | + b = 0x7fffffffffffffffULL; |
| 78 | + for( t = 0 ; t < 16 ; t++ ) |
| 79 | + { |
| 80 | + STBIR_PROFILE_INFO profile; |
| 81 | + int64 v; |
| 82 | + if(!stbir_resize_extended( &resize ) ) |
| 83 | + stop(); |
| 84 | + stbir_resize_extended_profile_info( &profile, &resize ); |
| 85 | + v = profile.clocks[1]+profile.clocks[2]; |
| 86 | + if ( v < b ) |
| 87 | + { |
| 88 | + b = v; |
| 89 | + t = 0; |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | + stbir_free_samplers( &resize ); |
| 94 | + |
| 95 | + return b; |
| 96 | +} |
| 97 | + |
| 98 | + |
| 99 | +#define INSIZES 5 |
| 100 | +#define TYPESCOUNT 5 |
| 101 | +#define NUM 64 |
| 102 | + |
| 103 | +static const int sizes[INSIZES]={63,126,252,520,772}; |
| 104 | +static const int types[TYPESCOUNT]={STBIR_1CHANNEL,STBIR_2CHANNEL,STBIR_RGB,STBIR_4CHANNEL,STBIR_RGBA}; |
| 105 | +static const int effective[TYPESCOUNT]={1,2,3,4,7}; |
| 106 | + |
| 107 | +int main( int argc, char ** argv ) |
| 108 | +{ |
| 109 | + unsigned char * input; |
| 110 | + unsigned char * output; |
| 111 | + int dimensionx, dimensiony; |
| 112 | + int scalex, scaley; |
| 113 | + int totalms; |
| 114 | + int timing_count; |
| 115 | + int ir; |
| 116 | + int * file; |
| 117 | + int * ts; |
| 118 | + int64 totalcycles; |
| 119 | + |
| 120 | + if ( argc != 6 ) |
| 121 | + { |
| 122 | + printf("command: dotimings x_samps y_samps x_scale y_scale outfilename\n"); |
| 123 | + exit(1); |
| 124 | + } |
| 125 | + |
| 126 | + input = malloc( 4*1200*1200 ); |
| 127 | + memset( input, 0x80, 4*1200*1200 ); |
| 128 | + output = malloc( 4*10000*10000ULL ); |
| 129 | + |
| 130 | + dimensionx = atoi( argv[1] ); |
| 131 | + dimensiony = atoi( argv[2] ); |
| 132 | + scalex = atoi( argv[3] ); |
| 133 | + scaley = atoi( argv[4] ); |
| 134 | + |
| 135 | + timing_count = dimensionx * dimensiony * INSIZES * TYPESCOUNT; |
| 136 | + |
| 137 | + file = malloc( sizeof(int) * ( 2 * timing_count + HEADER ) ); |
| 138 | + ts = file + HEADER; |
| 139 | + |
| 140 | + totalms = get_milliseconds(); |
| 141 | + totalcycles = STBIR_PROFILE_FUNC(); |
| 142 | + for( ir = 0 ; ir < INSIZES ; ir++ ) |
| 143 | + { |
| 144 | + int ix, iy, ty; |
| 145 | + ix = iy = sizes[ir]; |
| 146 | + |
| 147 | + for( ty = 0 ; ty < TYPESCOUNT ; ty++ ) |
| 148 | + { |
| 149 | + int h, hh; |
| 150 | + |
| 151 | + h = 1; |
| 152 | + for( hh = 0 ; hh < dimensiony; hh++ ) |
| 153 | + { |
| 154 | + int ww, w = 1; |
| 155 | + for( ww = 0 ; ww < dimensionx; ww++ ) |
| 156 | + { |
| 157 | + int64 VF, HF; |
| 158 | + int good; |
| 159 | + |
| 160 | + v_info.control_v_first = 2; // vertical first |
| 161 | + VF = nresize( output, w, h, (w*4*1)&~3, input, ix, iy, ix*4*1, types[ty], STBIR_TYPE_UINT8, STBIR_EDGE_CLAMP, STBIR_FILTER_MITCHELL ); |
| 162 | + v_info.control_v_first = 1; // horizonal first |
| 163 | + HF = nresize( output, w, h, (w*4*1)&~3, input, ix, iy, ix*4*1, types[ty], STBIR_TYPE_UINT8, STBIR_EDGE_CLAMP, STBIR_FILTER_MITCHELL ); |
| 164 | + |
| 165 | + good = ( ((HF<=VF) && (!v_info.v_first)) || ((VF<=HF) && (v_info.v_first))); |
| 166 | + |
| 167 | +// printf("\r%d,%d, %d,%d, %d, %I64d,%I64d, // Good: %c(%c-%d) CompEst: %.1f %.1f\n", ix, iy, w, h, ty, VF, HF, good?'y':'n', v_info.v_first?'v':'h', v_info.v_resize_classification, v_info.v_cost,v_info.h_cost ); |
| 168 | + ts[0] = (int)VF; |
| 169 | + ts[1] = (int)HF; |
| 170 | + |
| 171 | + ts += 2; |
| 172 | + |
| 173 | + w += scalex; |
| 174 | + } |
| 175 | + printf("."); |
| 176 | + h += scaley; |
| 177 | + } |
| 178 | + } |
| 179 | + } |
| 180 | + totalms = get_milliseconds() - totalms; |
| 181 | + totalcycles = STBIR_PROFILE_FUNC() - totalcycles; |
| 182 | + |
| 183 | + printf("\n"); |
| 184 | + |
| 185 | + file[0] = 'VFT1'; |
| 186 | + |
| 187 | + #if defined(_x86_64) || defined( __x86_64__ ) || defined( _M_X64 ) || defined(__x86_64) || defined(__SSE2__) || defined( _M_IX86_FP ) || defined(__i386) || defined( __i386__ ) || defined( _M_IX86 ) || defined( _X86_ ) |
| 188 | + file[1] = 1; // x64 |
| 189 | + #elif defined( _M_AMD64 ) || defined( __aarch64__ ) || defined( __arm64__ ) || defined(__ARM_NEON__) || defined(__ARM_NEON) || defined(__arm__) || defined( _M_ARM ) |
| 190 | + file[1] = 2; // arm |
| 191 | + #else |
| 192 | + file[1] = 99; // who knows??? |
| 193 | + #endif |
| 194 | + |
| 195 | + #ifdef STBIR_SIMD8 |
| 196 | + file[2] = 2; // simd-8 |
| 197 | + #elif defined( STBIR_SIMD ) |
| 198 | + file[2] = 1; // simd-4 |
| 199 | + #else |
| 200 | + file[2] = 0; // nosimd |
| 201 | + #endif |
| 202 | + |
| 203 | + file[3] = dimensionx; // dimx |
| 204 | + file[4] = dimensiony; // dimy |
| 205 | + file[5] = TYPESCOUNT; // channel types |
| 206 | + file[ 6] = types[0]; file[7] = types[1]; file[8] = types[2]; file[9] = types[3]; file[10] = types[4]; // buffer_type |
| 207 | + file[11] = effective[0]; file[12] = effective[1]; file[13] = effective[2]; file[14] = effective[3]; file[15] = effective[4]; // effective channels |
| 208 | + file[16] = INSIZES; // resizes |
| 209 | + file[17] = sizes[0]; file[18] = sizes[0]; // input sizes (w x h) |
| 210 | + file[19] = sizes[1]; file[20] = sizes[1]; |
| 211 | + file[21] = sizes[2]; file[22] = sizes[2]; |
| 212 | + file[23] = sizes[3]; file[24] = sizes[3]; |
| 213 | + file[25] = sizes[4]; file[26] = sizes[4]; |
| 214 | + file[27] = scalex; file[28] = scaley; // scale the dimx and dimy amount ( for(i=0;i<dimx) outputx = 1 + i*scalex; ) |
| 215 | + file[29] = totalms; |
| 216 | + ((int64*)(file+30))[0] = totalcycles; |
| 217 | + |
| 218 | + if ( !file_write( argv[5], file, sizeof(int) * ( 2 * timing_count + HEADER ) ) ) |
| 219 | + printf( "Error writing file: %s\n", argv[5] ); |
| 220 | + else |
| 221 | + printf( "Successfully wrote timing file: %s\n", argv[5] ); |
| 222 | + |
| 223 | + return 0; |
| 224 | +} |
0 commit comments