From 8f6f6fee060ff172befafacd68f5236b11ca2776 Mon Sep 17 00:00:00 2001 From: Pedro Vicente Nunes Date: Thu, 19 Aug 2004 14:09:13 -0500 Subject: [svn-r9121] Purpose: new feature Description: added a check that the chunk size must be smaller than pixels per block in SZIP request prints a message and exits, if not met Solution: Platforms tested: linux aix solaris Misc. update: --- tools/h5repack/h5repack.c | 49 -------- tools/h5repack/h5repack.h | 59 --------- tools/h5repack/h5repack_filters.c | 249 -------------------------------------- tools/h5repack/h5repack_list.c | 63 +++++++++- 4 files changed, 60 insertions(+), 360 deletions(-) diff --git a/tools/h5repack/h5repack.c b/tools/h5repack/h5repack.c index c0cc918..14779c5 100644 --- a/tools/h5repack/h5repack.c +++ b/tools/h5repack/h5repack.c @@ -336,55 +336,6 @@ static int check_options(pack_opt_t *options) has_cp=1; -#if defined (CHECK_SZIP) - - /*check for invalid combination of options */ - switch (pack.filter[j].filtn) - { - default: - break; - case H5Z_FILTER_SZIP: - { - - unsigned szip_options_mask=H5_SZIP_NN_OPTION_MASK; - unsigned szip_pixels_per_block; - - szip_pixels_per_block=pack.filter[j].cd_values[0]; - - if (pack.filter[j].szip_coding==0) - szip_options_mask=H5_SZIP_NN_OPTION_MASK; - else - szip_options_mask=H5_SZIP_EC_OPTION_MASK; - - /* check szip parameters */ - if ( pack.chunk.rank!=-1 /* - it means a layout was not input, so there is no - case to try to check it - */ - && check_szip(0, /* do not test size */ - pack.chunk.rank, - pack.chunk.chunk_lengths, - szip_options_mask, - &szip_pixels_per_block, - options)==0) - { - /* Return: 1=can apply the filter - 0=cannot apply the filter - Reset this object filter info - */ - - options->op_tbl->objs[i].filter[j].filtn=-1; - options->op_tbl->objs[i].chunk.rank=-1; - printf(" Object <%s> cannot be filtered\n",name); - - - } - - } - break; - } /* switch */ - -#endif } /* j */ } /* i */ diff --git a/tools/h5repack/h5repack.h b/tools/h5repack/h5repack.h index 4691a74..5c2c7eb 100644 --- a/tools/h5repack/h5repack.h +++ b/tools/h5repack/h5repack.h @@ -21,11 +21,6 @@ #include "h5diff.h" #include "h5tools.h" -#if 0 -#define CHECK_SZIP -#endif - - #define H5FOPENERROR "unable to open file" #define PFORMAT "%-7s %-7s %-7s\n" /*chunk info, compression info, name*/ @@ -328,59 +323,5 @@ int make_attr(hid_t loc_id, -/*------------------------------------------------------------------------- - * check SZIP parameters - *------------------------------------------------------------------------- - */ - -#if defined (CHECK_SZIP) - -int check_szip_params( unsigned bits_per_pixel, - unsigned pixels_per_block, - unsigned pixels_per_scanline, - hsize_t image_pixels); - -int check_szip(hid_t type_id, /* dataset datatype */ - int rank, /* chunk rank */ - hsize_t *dims, /* chunk dims */ - unsigned szip_options_mask /*IN*/, - unsigned *szip_pixels_per_block /*IN,OUT*/, - pack_opt_t *options); - - - -typedef struct -{ - int compression_mode; - int options_mask; - unsigned bits_per_pixel; - unsigned pixels_per_block; - unsigned pixels_per_scanline; - hsize_t pixels; - -}szip_comp_t; - -/* for SZIP */ -#if !defined (NN_OPTION_MASK) -#define NN_OPTION_MASK 32 -#endif -#if !defined (RAW_OPTION_MASK) -#define RAW_OPTION_MASK 128 -#endif -#if !defined (MAX_BLOCKS_PER_SCANLINE) -#define MAX_BLOCKS_PER_SCANLINE 128 -#endif -#if !defined (MAX_PIXELS_PER_BLOCK) -#define MAX_PIXELS_PER_BLOCK 32 -#endif -#if !defined (MAX_PIXELS_PER_SCANLINE) -#define MAX_PIXELS_PER_SCANLINE (MAX_BLOCKS_PER_SCANLINE)*(MAX_PIXELS_PER_BLOCK) -#endif -#if !defined (NN_MODE) -#define NN_MODE 1 -#endif - -#endif /* CHECK_SZIP */ - #endif /* H5REPACK_H__ */ diff --git a/tools/h5repack/h5repack_filters.c b/tools/h5repack/h5repack_filters.c index 2536ced..b506b16 100644 --- a/tools/h5repack/h5repack_filters.c +++ b/tools/h5repack/h5repack_filters.c @@ -212,17 +212,6 @@ int apply_filters(const char* name, /* object name from traverse list */ options_mask=H5_SZIP_NN_OPTION_MASK; else options_mask=H5_SZIP_EC_OPTION_MASK; - -#if defined (CHECK_SZIP) - /* check szip parameters */ - if (check_szip(type_id, - obj->chunk.rank, - obj->chunk.chunk_lengths, - options_mask, - &pixels_per_block, - options)==1) - { -#endif /* set up for szip data */ if(H5Pset_chunk(dcpl_id,obj->chunk.rank,obj->chunk.chunk_lengths)<0) @@ -230,17 +219,6 @@ int apply_filters(const char* name, /* object name from traverse list */ if (H5Pset_szip(dcpl_id,options_mask,pixels_per_block)<0) return -1; - -#if defined (CHECK_SZIP) - } - else - { - if (options->verbose) - printf("Warning: SZIP filter cannot be applied to <%s>\n",name); - } -#endif - - } break; @@ -345,231 +323,4 @@ int print_filters(hid_t dcpl_id) } -#if defined (CHECK_SZIP) - - -/*------------------------------------------------------------------------- - * Function: check_szip - * - * Purpose: utility to check SZIP parameters - * - * SZIP compresses data block by block, with a user-tunable block size. - * This block size is passed in the parameter pixels_per_block and must be even, - * with typical values being 8, 10, 16, and 32. The more pixel values vary, - * the smaller this number should be. For optimal performance, the number of - * pixels per scan line (i.e., the size of the fastest-changing dimension in the chunk) - * should be an even multiple of the number of pixels per block. - * - * Return: 1=can apply the filter - * 0=cannot apply the filter - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: December 23, 2003 - * - *------------------------------------------------------------------------- - */ - -int check_szip(hid_t type_id, /* dataset datatype */ - int rank, /* chunk rank */ - hsize_t *dims, /* chunk dims */ - unsigned szip_options_mask /*IN*/, - unsigned *szip_pixels_per_block /*IN,OUT*/, - pack_opt_t *options) -{ - size_t size=0; /* size of datatype in bytes */ - szip_comp_t szip; - int i; - unsigned ppb=*szip_pixels_per_block; - - if (type_id) - { - if ((size=H5Tget_size(type_id))==0) - return 0; - - switch (H5Tget_class(type_id)) - { - default: - return 0; - case H5T_INTEGER: - case H5T_FLOAT: - break; - } - } - - - /* - pixels_per_scanline = size of the fastest-changing dimension - Must be <= MAX_PIXELS_PER_SCANLINE and <= pixels - */ - szip.pixels_per_scanline = (unsigned)dims[rank-1]; - szip.pixels = 1; - for ( i = 0; i < rank; i++) - { - szip.pixels *= dims[i]; - } - - if (szip.pixels_per_scanline > MAX_PIXELS_PER_SCANLINE) - { - printf("Warning: in SZIP setting, pixels per scanline was set to <%d>, \ - MAX_PIXELS_PER_SCANLINE\n",MAX_PIXELS_PER_SCANLINE); - szip.pixels_per_scanline = MAX_PIXELS_PER_SCANLINE; - } - - /* - pixels_per_block must be an even number, and <= pixels_per_scanline - and <= MAX_PIXELS_PER_BLOCK - */ - - if (ppb > szip.pixels_per_scanline) - { - /* set ppb to pixels per scanline and try to make it an even number */ - ppb=szip.pixels_per_scanline; - if (ppb%2!=0) - ppb--; - if (ppb<=1 ) - { - printf("Warning: in SZIP settings, pixels per block <%d>,\ - cannot be set with pixels per scanline <%d>\n", - ppb, szip.pixels_per_scanline); - return 0; - } - else - { - if (options->verbose) - printf("Warning: In SZIP settings, pixels per block was set to <%d>\n", ppb); - } - } - szip.pixels_per_block = ppb; - *szip_pixels_per_block = ppb; - - szip.options_mask = szip_options_mask; - szip.compression_mode = NN_MODE; - - /* - bits_per_pixel - Must be in range 1..24,32,64 - */ - szip.bits_per_pixel = 0; - if (type_id) { - switch(size) - { - case 1: - szip.bits_per_pixel = 8; - break; - case 2: - szip.bits_per_pixel = 16; - break; - case 4: - szip.bits_per_pixel = 32; - break; - case 8: - szip.bits_per_pixel = 64; - break; - default: - printf("Warning: Invalid numeric type of size <%u> for SZIP\n",(unsigned)size); - return 0; - }} - - return check_szip_params( szip.bits_per_pixel, - szip.pixels_per_block, - szip.pixels_per_scanline, - szip.pixels); - -} - - -/*------------------------------------------------------------------------- - * Function: check_szip_params - * - * Purpose: Adapted from rice.c. Checks the SZIP parameters - * - * Return: 1=can apply the filter - * 0=cannot apply the filter - * - *------------------------------------------------------------------------- - */ - -int check_szip_params( unsigned bits_per_pixel, - unsigned pixels_per_block, - unsigned pixels_per_scanline, - hsize_t image_pixels) -{ - - if (pixels_per_block & 1) - { - printf("Pixels per block must be even.\n"); - return 0; - } - - if (pixels_per_block > pixels_per_scanline) - { - printf("Pixels per block is greater than pixels per scanline.\n"); - return 0; - } - - if (bits_per_pixel) /* if provided for test */ - { - if (bits_per_pixel >= 1 && bits_per_pixel <= 24) - ; - else if (bits_per_pixel == 32 || bits_per_pixel == 64) - ; - else - { - printf("bits per pixel must be in range 1..24,32,64"); - return 0; - } - } - - if (pixels_per_block > MAX_PIXELS_PER_BLOCK) - { - printf("maximum pixels per block exceeded"); - return 0; - } - - if (pixels_per_block & 1) - { - printf("pixels per block must be even"); - return 0; - } - - if (pixels_per_block > pixels_per_scanline) - { - printf("pixels per block > pixels per scanline"); - return 0; - } - - if (pixels_per_scanline > MAX_PIXELS_PER_SCANLINE) - { - printf("maximum pixels per scanline exceeded"); - return 0; - } - - if (image_pixels < pixels_per_scanline) - { - printf("image pixels less than pixels per scanline"); - return 0; - } - - if (image_pixels % pixels_per_scanline) - { - printf("Pixels (%d) must be integer multiple of pixels per scanline (%d)\n", - (unsigned)image_pixels,pixels_per_scanline); - return 0; - } - -#if 0 - if (pixels_per_scanline % pixels_per_block) - { - printf("Pixels per scanline (%d) must be an integer multiple of pixels per block (%d)\n", - pixels_per_scanline, pixels_per_block); - return 0; - } -#endif - - return 1; -} - -#endif /* CHECK_SZIP */ - diff --git a/tools/h5repack/h5repack_list.c b/tools/h5repack/h5repack_list.c index d3a84e1..38b8bc0 100644 --- a/tools/h5repack/h5repack_list.c +++ b/tools/h5repack/h5repack_list.c @@ -46,7 +46,7 @@ int check_objects(const char* fname, *------------------------------------------------------------------------- */ - /* disable error reporting */ + /* disable out reporting */ H5E_BEGIN_TRY { /* Open the files */ @@ -54,7 +54,7 @@ int check_objects(const char* fname, printf("h5repack: <%s>: %s\n", fname, H5FOPENERROR ); exit(1); } - /* enable error reporting */ + /* enable out reporting */ } H5E_END_TRY; @@ -95,7 +95,63 @@ int check_objects(const char* fname, } if (options->verbose) printf("...Found\n"); - } + + + /* check for extra filter conditions */ + switch (options->op_tbl->objs[i].filter->filtn) + { + + /* chunk size must be smaller than pixels per block */ + case H5Z_FILTER_SZIP: + { + int j; + int csize=1; + int ppb=options->op_tbl->objs[i].filter->cd_values[0]; + hsize_t dims[H5S_MAX_RANK]; + int rank; + hid_t did; + hid_t sid; + + if (options->op_tbl->objs[i].chunk.rank>0) + { + rank=options->op_tbl->objs[i].chunk.rank; + for (j=0; jop_tbl->objs[i].chunk.chunk_lengths[j]; + } + else + { + if ((did=H5Dopen(fid,travt->objs[i].name))<0) + goto out; + if ((sid=H5Dget_space(did))<0) + goto out; + if ( (rank=H5Sget_simple_extent_ndims(sid))<0) + goto out; + HDmemset(dims, 0, sizeof dims); + if ( H5Sget_simple_extent_dims(sid,dims,NULL)<0) + goto out; + for (j=0; j