os/ossrv/genericopenlibs/liboil/tsrc/examples/oil-suggest/src/oil-suggest.c
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2  * LIBOIL - Library of Optimized Inner Loops
     3  * Copyright (c) 2004 David A. Schleef <ds@schleef.org>
     4  * All rights reserved.
     5  *
     6  * Redistribution and use in source and binary forms, with or without
     7  * modification, are permitted provided that the following conditions
     8  * are met:
     9  * 1. Redistributions of source code must retain the above copyright
    10  *    notice, this list of conditions and the following disclaimer.
    11  * 2. Redistributions in binary form must reproduce the above copyright
    12  *    notice, this list of conditions and the following disclaimer in the
    13  *    documentation and/or other materials provided with the distribution.
    14  * 
    15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
    16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
    19  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    21  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
    23  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
    24  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    25  * POSSIBILITY OF SUCH DAMAGE.
    26  */
    27 
    28 #ifdef HAVE_CONFIG_H
    29 #include "config.h"
    30 #endif
    31 
    32 #include <liboil/liboil.h>
    33 #include <liboil/liboilfunction.h>
    34 #include <liboil/liboilcpu.h>
    35 #include <liboil/liboiltest.h>
    36 
    37 #include <stdio.h>
    38 #include <stdlib.h>
    39 #include <string.h>
    40 #include <stdarg.h>
    41 #define LOG_FILE "c:\\logs\\examples_oil-suggest_log.txt"
    42 #include "std_log_result.h"
    43 #define LOG_FILENAME_LINE __FILE__, __LINE__
    44 
    45 void create_xml(int result)
    46 {
    47     if(result)
    48         assert_failed = 1;
    49     
    50     testResultXml("examples_oil-suggest");
    51     close_log_file();
    52 }
    53 
    54 static int
    55 is_poorly_strided (OilFunctionClass *klass)
    56 {
    57   OilPrototype *proto;
    58   int i;
    59   int j;
    60   OilParameter *param;
    61 
    62   proto = oil_prototype_from_string (klass->prototype);
    63   for(i=0;i<proto->n_params;i++) {
    64     if (proto->params[i].is_stride) {
    65       for(j=0;j<proto->n_params;j++) {
    66         param = proto->params + j;
    67         if (param->parameter_type == (proto->params[i].parameter_type - 1)) {
    68           if (param->prestride_length == 1 && param->poststride_length == 0) {
    69             oil_prototype_free (proto);
    70             return 1;
    71           }
    72         }
    73       }
    74     }
    75   }
    76   oil_prototype_free (proto);
    77   return 0;
    78 }
    79 
    80 static double
    81 get_speed_score (OilFunctionClass *klass)
    82 {
    83   OilFunctionImpl *impl;
    84   double max;
    85   double x;
    86 
    87   max = 1.0;
    88   for(impl = klass->first_impl; impl; impl = impl->next) {
    89     x =  klass->reference_impl->profile_ave / impl->profile_ave;
    90     if (x > max) max = x;
    91   }
    92   return max;
    93 }
    94 
    95 static void
    96 oil_suggest_class (OilFunctionClass *klass, int verbose)
    97 {
    98   double x;
    99 
   100   if (is_poorly_strided (klass)) return;
   101 
   102   x = get_speed_score (klass);
   103 
   104   if (x < 20.0) {
   105   std_log(LOG_FILENAME_LINE,"%s %g\n", klass->name, x);
   106   }
   107 }
   108 
   109 static void
   110 oil_suggest_all (void)
   111 {
   112   int i;
   113   int n;
   114 
   115   n = oil_class_get_n_classes ();
   116   for (i = 0; i < n; i++){
   117     OilFunctionClass *klass = oil_class_get_by_index (i);
   118 
   119     oil_suggest_class (klass, 0);
   120   }
   121 }
   122 
   123 static void
   124 oil_suggest (const char *s)
   125 {
   126   OilFunctionClass *klass = oil_class_get (s);
   127 
   128   if (klass) {
   129     oil_suggest_class (klass, 0);
   130   }
   131 }
   132 
   133 int
   134 main (int argc, char *argv[])
   135 {
   136   int i;
   137 
   138   oil_init();
   139 
   140   if (argc == 1) {
   141     oil_suggest_all ();
   142 	create_xml(0);
   143     return 0;
   144   }
   145 
   146   for(i=1;i<argc;i++){
   147     oil_suggest (argv[i]);
   148   }
   149     if(assert_failed)
   150           std_log(LOG_FILENAME_LINE,"Test Fail");
   151     else
   152           std_log(LOG_FILENAME_LINE,"Test Successful");
   153     create_xml(0);
   154     return 0;
   155 }
   156