diff --git a/llvm/test/VISC/parboil/benchmarks/kmeans/Makefile b/llvm/test/VISC/parboil/benchmarks/kmeans/Makefile index 9b0242c6e7273999cc79771f222531c7d108235c..1248caba70003effd3cc24cfb77e2f9ba66552f7 100644 --- a/llvm/test/VISC/parboil/benchmarks/kmeans/Makefile +++ b/llvm/test/VISC/parboil/benchmarks/kmeans/Makefile @@ -3,7 +3,7 @@ APP = kmeans # Default compile visc ifeq ($(VERSION),) - VERSION = opencl + VERSION = visc endif # Default use small test case diff --git a/llvm/test/VISC/parboil/benchmarks/kmeans/src/visc/.kmeans_clustering.c.swo b/llvm/test/VISC/parboil/benchmarks/kmeans/src/visc/.kmeans_clustering.c.swo new file mode 100644 index 0000000000000000000000000000000000000000..6c023714dd555f5490adaad6f3ca9e7555bcf53c Binary files /dev/null and b/llvm/test/VISC/parboil/benchmarks/kmeans/src/visc/.kmeans_clustering.c.swo differ diff --git a/llvm/test/VISC/parboil/benchmarks/kmeans/src/visc/Makefile b/llvm/test/VISC/parboil/benchmarks/kmeans/src/visc/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..5ea2472c7d95c8c3cdcbd1cf57cd02f81291ed39 --- /dev/null +++ b/llvm/test/VISC/parboil/benchmarks/kmeans/src/visc/Makefile @@ -0,0 +1,8 @@ +# (c) 2010 The Board of Trustees of the University of Illinois. + +LANGUAGE=visc +SRCDIR_OBJS=cluster.ll getopt.ll read_input.ll kmeans_clustering.ll rmse.ll #compute_gold.o +VISC_OBJS=kmeans.visc.ll +APP_CUDALDFLAGS=-lm -lstdc++ +APP_CFLAGS= -O2 +APP_CXXFLAGS= -O2 diff --git a/llvm/test/VISC/parboil/benchmarks/kmeans/src/visc/README b/llvm/test/VISC/parboil/benchmarks/kmeans/src/visc/README new file mode 100755 index 0000000000000000000000000000000000000000..05c5443196287e5d1c200dbc592acbec8fdd0c42 --- /dev/null +++ b/llvm/test/VISC/parboil/benchmarks/kmeans/src/visc/README @@ -0,0 +1,9 @@ +NOTE: The current Kmeans implementation doesn't use texture/constant memories, and is different from the CUDA implementation. + +******Adjustable work group size***** +RD_WG_SIZE_0 or RD_WG_SIZE_0_0 for kernel_swap +RD_WG_SIZE_1 or RD_WG_SIZE_1_0 for kernel_kmeans + +USAGE: +make clean +make KERNEL_DIM="-DRD_WG_SIZE_0=128 -DRD_WG_SIZE_1=512" \ No newline at end of file diff --git a/llvm/test/VISC/parboil/benchmarks/kmeans/src/visc/cluster.c b/llvm/test/VISC/parboil/benchmarks/kmeans/src/visc/cluster.c new file mode 100644 index 0000000000000000000000000000000000000000..987e874ab3b077e6d685b208bce31ec88f3e65af --- /dev/null +++ b/llvm/test/VISC/parboil/benchmarks/kmeans/src/visc/cluster.c @@ -0,0 +1,157 @@ +/*****************************************************************************/ +/*IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. */ +/*By downloading, copying, installing or using the software you agree */ +/*to this license. If you do not agree to this license, do not download, */ +/*install, copy or use the software. */ +/* */ +/* */ +/*Copyright (c) 2005 Northwestern University */ +/*All rights reserved. */ + +/*Redistribution of the software in source and binary forms, */ +/*with or without modification, is permitted provided that the */ +/*following conditions are met: */ +/* */ +/*1 Redistributions of source code must retain the above copyright */ +/* notice, this list of conditions and the following disclaimer. */ +/* */ +/*2 Redistributions in binary form must reproduce the above copyright */ +/* notice, this list of conditions and the following disclaimer in the */ +/* documentation and/or other materials provided with the distribution.*/ +/* */ +/*3 Neither the name of Northwestern University nor the names of its */ +/* contributors may be used to endorse or promote products derived */ +/* from this software without specific prior written permission. */ +/* */ +/*THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS */ +/*IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED */ +/*TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND */ +/*FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL */ +/*NORTHWESTERN UNIVERSITY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, */ +/*INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */ +/*(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR */ +/*SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ +/*HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, */ +/*STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN */ +/*ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */ +/*POSSIBILITY OF SUCH DAMAGE. */ +/******************************************************************************/ + +/*************************************************************************/ +/** File: cluster.c **/ +/** Description: Takes as input a file, containing 1 data point per **/ +/** per line, and performs a fuzzy c-means clustering **/ +/** on the data. Fuzzy clustering is performed using **/ +/** min to max clusters and the clustering that gets **/ +/** the best score according to a compactness and **/ +/** separation criterion are returned. **/ +/** Author: Brendan McCane **/ +/** James Cook University of North Queensland. **/ +/** Australia. email: mccane@cs.jcu.edu.au **/ +/** **/ +/** Edited by: Jay Pisharath, Wei-keng Liao **/ +/** Northwestern University. **/ +/** **/ +/** ================================================================ **/ +/** **/ +/** Edited by: Shuai Che, David Tarjan, Sang-Ha Lee **/ +/** University of Virginia **/ +/** **/ +/** Description: No longer supports fuzzy c-means clustering; **/ +/** only regular k-means clustering. **/ +/** No longer performs "validity" function to analyze **/ +/** compactness and separation crietria; instead **/ +/** calculate root mean squared error. **/ +/** **/ +/*************************************************************************/ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <limits.h> +#include <math.h> +#include <float.h> + +#include "kmeans.h" + +float min_rmse_ref = FLT_MAX; +extern double wtime(void); +/* reference min_rmse value */ + +/*---< cluster() >-----------------------------------------------------------*/ +int cluster(int npoints, /* number of data points */ + int nfeatures, /* number of attributes for each point */ + float **features, /* array: [npoints][nfeatures] */ + int min_nclusters, /* range of min to max number of clusters */ + int max_nclusters, + float threshold, /* loop terminating factor */ + int *best_nclusters, /* out: number between min and max with lowest RMSE */ + float ***cluster_centres, /* out: [best_nclusters][nfeatures] */ + float *min_rmse, /* out: minimum RMSE */ + int isRMSE, /* calculate RMSE */ + int nloops /* number of iteration for each number of clusters */ + ) +{ + int nclusters; /* number of clusters k */ + int index =0; /* number of iteration to reach the best RMSE */ + int rmse; /* RMSE for each clustering */ + int *membership; /* which cluster a data point belongs to */ + float **tmp_cluster_centres; /* hold coordinates of cluster centers */ + int i; + + /* allocate memory for membership */ + membership = (int*) malloc(npoints * sizeof(int)); + + /* sweep k from min to max_nclusters to find the best number of clusters */ + for(nclusters = min_nclusters; nclusters <= max_nclusters; nclusters++) + { + if (nclusters > npoints) break; /* cannot have more clusters than points */ + + /* allocate device memory, invert data array (@ kmeans_cuda.cu) */ + allocate(npoints, nfeatures, nclusters, features); + + /* iterate nloops times for each number of clusters */ + for(i = 0; i < nloops; i++) + { + /* initialize initial cluster centers, CUDA calls (@ kmeans_cuda.cu) */ + tmp_cluster_centres = kmeans_clustering(features, + nfeatures, + npoints, + nclusters, + threshold, + membership); + + if (*cluster_centres) { + llvm_visc_untrack_mem((*cluster_centres)[0]); + free((*cluster_centres)[0]); + free(*cluster_centres); + } + *cluster_centres = tmp_cluster_centres; + + + /* find the number of clusters with the best RMSE */ + if(isRMSE) + { + rmse = rms_err(features, + nfeatures, + npoints, + tmp_cluster_centres, + nclusters); + + if(rmse < min_rmse_ref) { + min_rmse_ref = rmse; //update reference min RMSE + *min_rmse = min_rmse_ref; //update return min RMSE + *best_nclusters = nclusters; //update optimum number of clusters + index = i; //update number of iteration to reach best RMSE + } + } + } + + deallocateMemory(); /* free device memory (@ kmeans_cuda.cu) */ + } + + free(membership); + + return index; +} + diff --git a/llvm/test/VISC/parboil/benchmarks/kmeans/src/visc/getopt.c b/llvm/test/VISC/parboil/benchmarks/kmeans/src/visc/getopt.c new file mode 100644 index 0000000000000000000000000000000000000000..23262ae282adec89cb861023fc332e4a31d041a0 --- /dev/null +++ b/llvm/test/VISC/parboil/benchmarks/kmeans/src/visc/getopt.c @@ -0,0 +1,1184 @@ +/* Getopt for GNU. + NOTE: getopt is now part of the C library, so if you don't know what + "Keep this file name-space clean" means, talk to drepper@gnu.org + before changing it! + Copyright (C) 1987,88,89,90,91,92,93,94,95,96,98,99,2000,2001 + Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +/* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>. + Ditto for AIX 3.2 and <stdlib.h>. */ +#ifndef _NO_PROTO +# define _NO_PROTO +#endif + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#if !defined __STDC__ || !__STDC__ +/* This is a separate conditional since some stdc systems + reject `defined (const)'. */ +# ifndef const +# define const +# endif +#endif + +#include <stdio.h> + +/* Comment out all this code if we are using the GNU C Library, and are not + actually compiling the library itself. This code is part of the GNU C + Library, but also included in many other GNU distributions. Compiling + and linking in this code is a waste when using the GNU C library + (especially if it is a shared library). Rather than having every GNU + program understand `configure --with-gnu-libc' and omit the object files, + it is simpler to just do this in the source for each such file. */ + +#define GETOPT_INTERFACE_VERSION 2 +#if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2 +# include <gnu-versions.h> +# if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION +# define ELIDE_CODE +# endif +#endif + +#ifndef ELIDE_CODE + + +/* This needs to come after some library #include + to get __GNU_LIBRARY__ defined. */ +#ifdef __GNU_LIBRARY__ +/* Don't include stdlib.h for non-GNU C libraries because some of them + contain conflicting prototypes for getopt. */ +# include <stdlib.h> +# include <unistd.h> +#endif /* GNU C library. */ + +#ifdef VMS +# include <unixlib.h> +# if HAVE_STRING_H - 0 +# include <string.h> +# endif +#endif + +#ifndef _ +/* This is for other GNU distributions with internationalized messages. */ +# if (HAVE_LIBINTL_H && ENABLE_NLS) || defined _LIBC +# include <libintl.h> +# ifndef _ +# define _(msgid) gettext (msgid) +# endif +# else +# define _(msgid) (msgid) +# endif +# if defined _LIBC && defined USE_IN_LIBIO +# include <wchar.h> +# endif +#endif + +/* This version of `getopt' appears to the caller like standard Unix `getopt' + but it behaves differently for the user, since it allows the user + to intersperse the options with the other arguments. + + As `getopt' works, it permutes the elements of ARGV so that, + when it is done, all the options precede everything else. Thus + all application programs are extended to handle flexible argument order. + + Setting the environment variable POSIXLY_CORRECT disables permutation. + Then the behavior is completely standard. + + GNU application programs can use a third alternative mode in which + they can distinguish the relative order of options and other arguments. */ + +#include "getopt.h" + +/* For communication from `getopt' to the caller. + When `getopt' finds an option that takes an argument, + the argument value is returned here. + Also, when `ordering' is RETURN_IN_ORDER, + each non-option ARGV-element is returned here. */ + +char *optarg; + +/* Index in ARGV of the next element to be scanned. + This is used for communication to and from the caller + and for communication between successive calls to `getopt'. + + On entry to `getopt', zero means this is the first call; initialize. + + When `getopt' returns -1, this is the index of the first of the + non-option elements that the caller should itself scan. + + Otherwise, `optind' communicates from one call to the next + how much of ARGV has been scanned so far. */ + +/* 1003.2 says this must be 1 before any call. */ +int optind = 1; + +/* Formerly, initialization of getopt depended on optind==0, which + causes problems with re-calling getopt as programs generally don't + know that. */ + +int __getopt_initialized; + +/* The next char to be scanned in the option-element + in which the last option character we returned was found. + This allows us to pick up the scan where we left off. + + If this is zero, or a null string, it means resume the scan + by advancing to the next ARGV-element. */ + +static char *nextchar; + +/* Callers store zero here to inhibit the error message + for unrecognized options. */ + +int opterr = 1; + +/* Set to an option character which was unrecognized. + This must be initialized on some systems to avoid linking in the + system's own getopt implementation. */ + +int optopt = '?'; + +/* Describe how to deal with options that follow non-option ARGV-elements. + + If the caller did not specify anything, + the default is REQUIRE_ORDER if the environment variable + POSIXLY_CORRECT is defined, PERMUTE otherwise. + + REQUIRE_ORDER means don't recognize them as options; + stop option processing when the first non-option is seen. + This is what Unix does. + This mode of operation is selected by either setting the environment + variable POSIXLY_CORRECT, or using `+' as the first character + of the list of option characters. + + PERMUTE is the default. We permute the contents of ARGV as we scan, + so that eventually all the non-options are at the end. This allows options + to be given in any order, even with programs that were not written to + expect this. + + RETURN_IN_ORDER is an option available to programs that were written + to expect options and other ARGV-elements in any order and that care about + the ordering of the two. We describe each non-option ARGV-element + as if it were the argument of an option with character code 1. + Using `-' as the first character of the list of option characters + selects this mode of operation. + + The special argument `--' forces an end of option-scanning regardless + of the value of `ordering'. In the case of RETURN_IN_ORDER, only + `--' can cause `getopt' to return -1 with `optind' != ARGC. */ + +static enum +{ + REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER +} ordering; + +/* Value of POSIXLY_CORRECT environment variable. */ +static char *posixly_correct; + +#ifdef __GNU_LIBRARY__ +/* We want to avoid inclusion of string.h with non-GNU libraries + because there are many ways it can cause trouble. + On some systems, it contains special magic macros that don't work + in GCC. */ +# include <string.h> +# define my_index strchr +#else + +//# if HAVE_STRING_H || WIN32 /* Pete Wilson mod 7/28/02 */ +# include <string.h> +//# else +//# include <strings.h> +//# endif + +/* Avoid depending on library functions or files + whose names are inconsistent. */ + +#ifndef getenv +extern char *getenv (); +#endif + +static char * +my_index (str, chr) +const char *str; +int chr; +{ + while (*str) + { + if (*str == chr) + return (char *) str; + str++; + } + return 0; +} + +/* If using GCC, we can safely declare strlen this way. + If not using GCC, it is ok not to declare it. */ +#ifdef __GNUC__ +/* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h. + That was relevant to code that was here before. */ +# if (!defined __STDC__ || !__STDC__) && !defined strlen +/* gcc with -traditional declares the built-in strlen to return int, + and has done so at least since version 2.4.5. -- rms. */ +extern int strlen (const char *); +# endif /* not __STDC__ */ +#endif /* __GNUC__ */ + +#endif /* not __GNU_LIBRARY__ */ + +/* Handle permutation of arguments. */ + +/* Describe the part of ARGV that contains non-options that have + been skipped. `first_nonopt' is the index in ARGV of the first of them; + `last_nonopt' is the index after the last of them. */ + +static int first_nonopt; +static int last_nonopt; + +#ifdef _LIBC +/* Stored original parameters. + XXX This is no good solution. We should rather copy the args so + that we can compare them later. But we must not use malloc(3). */ +extern int __libc_argc; +extern char **__libc_argv; + +/* Bash 2.0 gives us an environment variable containing flags + indicating ARGV elements that should not be considered arguments. */ + +# ifdef USE_NONOPTION_FLAGS +/* Defined in getopt_init.c */ +extern char *__getopt_nonoption_flags; + +static int nonoption_flags_max_len; +static int nonoption_flags_len; +# endif + +# ifdef USE_NONOPTION_FLAGS +# define SWAP_FLAGS(ch1, ch2) \ + if (nonoption_flags_len > 0) \ + { \ + char __tmp = __getopt_nonoption_flags[ch1]; \ + __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2]; \ + __getopt_nonoption_flags[ch2] = __tmp; \ + } +# else +# define SWAP_FLAGS(ch1, ch2) +# endif +#else /* !_LIBC */ +# define SWAP_FLAGS(ch1, ch2) +#endif /* _LIBC */ + +/* Exchange two adjacent subsequences of ARGV. + One subsequence is elements [first_nonopt,last_nonopt) + which contains all the non-options that have been skipped so far. + The other is elements [last_nonopt,optind), which contains all + the options processed since those non-options were skipped. + + `first_nonopt' and `last_nonopt' are relocated so that they describe + the new indices of the non-options in ARGV after they are moved. */ + +#if defined __STDC__ && __STDC__ +static void exchange (char **); +#endif + +static void +exchange (argv) +char **argv; +{ + int bottom = first_nonopt; + int middle = last_nonopt; + int top = optind; + char *tem; + + /* Exchange the shorter segment with the far end of the longer segment. + That puts the shorter segment into the right place. + It leaves the longer segment in the right place overall, + but it consists of two parts that need to be swapped next. */ + +#if defined _LIBC && defined USE_NONOPTION_FLAGS + /* First make sure the handling of the `__getopt_nonoption_flags' + string can work normally. Our top argument must be in the range + of the string. */ + if (nonoption_flags_len > 0 && top >= nonoption_flags_max_len) + { + /* We must extend the array. The user plays games with us and + presents new arguments. */ + char *new_str = malloc (top + 1); + if (new_str == NULL) + nonoption_flags_len = nonoption_flags_max_len = 0; + else + { + memset (__mempcpy (new_str, __getopt_nonoption_flags, + nonoption_flags_max_len), + '\0', top + 1 - nonoption_flags_max_len); + nonoption_flags_max_len = top + 1; + __getopt_nonoption_flags = new_str; + } + } +#endif + + while (top > middle && middle > bottom) + { + if (top - middle > middle - bottom) + { + /* Bottom segment is the short one. */ + int len = middle - bottom; + register int i; + + /* Swap it with the top part of the top segment. */ + for (i = 0; i < len; i++) + { + tem = argv[bottom + i]; + argv[bottom + i] = argv[top - (middle - bottom) + i]; + argv[top - (middle - bottom) + i] = tem; + SWAP_FLAGS (bottom + i, top - (middle - bottom) + i); + } + /* Exclude the moved bottom segment from further swapping. */ + top -= len; + } + else + { + /* Top segment is the short one. */ + int len = top - middle; + register int i; + + /* Swap it with the bottom part of the bottom segment. */ + for (i = 0; i < len; i++) + { + tem = argv[bottom + i]; + argv[bottom + i] = argv[middle + i]; + argv[middle + i] = tem; + SWAP_FLAGS (bottom + i, middle + i); + } + /* Exclude the moved top segment from further swapping. */ + bottom += len; + } + } + + /* Update records for the slots the non-options now occupy. */ + + first_nonopt += (optind - last_nonopt); + last_nonopt = optind; +} + +/* Initialize the internal data when the first call is made. */ + +#if defined __STDC__ && __STDC__ +static const char *_getopt_initialize (int, char *const *, const char *); +#endif +static const char * +_getopt_initialize (argc, argv, optstring) +int argc; +char *const *argv; +const char *optstring; +{ + /* Start processing options with ARGV-element 1 (since ARGV-element 0 + is the program name); the sequence of previously skipped + non-option ARGV-elements is empty. */ + + first_nonopt = last_nonopt = optind; + + nextchar = NULL; + + posixly_correct = getenv ("POSIXLY_CORRECT"); + + /* Determine how to handle the ordering of options and nonoptions. */ + + if (optstring[0] == '-') + { + ordering = RETURN_IN_ORDER; + ++optstring; + } + else if (optstring[0] == '+') + { + ordering = REQUIRE_ORDER; + ++optstring; + } + else if (posixly_correct != NULL) + ordering = REQUIRE_ORDER; + else + ordering = PERMUTE; + +#if defined _LIBC && defined USE_NONOPTION_FLAGS + if (posixly_correct == NULL + && argc == __libc_argc && argv == __libc_argv) + { + if (nonoption_flags_max_len == 0) + { + if (__getopt_nonoption_flags == NULL + || __getopt_nonoption_flags[0] == '\0') + nonoption_flags_max_len = -1; + else + { + const char *orig_str = __getopt_nonoption_flags; + int len = nonoption_flags_max_len = strlen (orig_str); + if (nonoption_flags_max_len < argc) + nonoption_flags_max_len = argc; + __getopt_nonoption_flags = + (char *) malloc (nonoption_flags_max_len); + if (__getopt_nonoption_flags == NULL) + nonoption_flags_max_len = -1; + else + memset (__mempcpy (__getopt_nonoption_flags, orig_str, len), + '\0', nonoption_flags_max_len - len); + } + } + nonoption_flags_len = nonoption_flags_max_len; + } + else + nonoption_flags_len = 0; +#endif + + return optstring; +} + +/* Scan elements of ARGV (whose length is ARGC) for option characters + given in OPTSTRING. + + If an element of ARGV starts with '-', and is not exactly "-" or "--", + then it is an option element. The characters of this element + (aside from the initial '-') are option characters. If `getopt' + is called repeatedly, it returns successively each of the option characters + from each of the option elements. + + If `getopt' finds another option character, it returns that character, + updating `optind' and `nextchar' so that the next call to `getopt' can + resume the scan with the following option character or ARGV-element. + + If there are no more option characters, `getopt' returns -1. + Then `optind' is the index in ARGV of the first ARGV-element + that is not an option. (The ARGV-elements have been permuted + so that those that are not options now come last.) + + OPTSTRING is a string containing the legitimate option characters. + If an option character is seen that is not listed in OPTSTRING, + return '?' after printing an error message. If you set `opterr' to + zero, the error message is suppressed but we still return '?'. + + If a char in OPTSTRING is followed by a colon, that means it wants an arg, + so the following text in the same ARGV-element, or the text of the following + ARGV-element, is returned in `optarg'. Two colons mean an option that + wants an optional arg; if there is text in the current ARGV-element, + it is returned in `optarg', otherwise `optarg' is set to zero. + + If OPTSTRING starts with `-' or `+', it requests different methods of + handling the non-option ARGV-elements. + See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above. + + Long-named options begin with `--' instead of `-'. + Their names may be abbreviated as long as the abbreviation is unique + or is an exact match for some defined option. If they have an + argument, it follows the option name in the same ARGV-element, separated + from the option name by a `=', or else the in next ARGV-element. + When `getopt' finds a long-named option, it returns 0 if that option's + `flag' field is nonzero, the value of the option's `val' field + if the `flag' field is zero. + + The elements of ARGV aren't really const, because we permute them. + But we pretend they're const in the prototype to be compatible + with other systems. + + LONGOPTS is a vector of `struct option' terminated by an + element containing a name which is zero. + + LONGIND returns the index in LONGOPT of the long-named option found. + It is only valid when a long-named option has been found by the most + recent call. + + If LONG_ONLY is nonzero, '-' as well as '--' can introduce + long-named options. */ + +int +_getopt_internal (argc, argv, optstring, longopts, longind, long_only) +int argc; +char *const *argv; +const char *optstring; +const struct option *longopts; +int *longind; +int long_only; +{ + int print_errors = opterr; + if (optstring[0] == ':') + print_errors = 0; + + if (argc < 1) + return -1; + + optarg = NULL; + + if (optind == 0 || !__getopt_initialized) + { + if (optind == 0) + optind = 1; /* Don't scan ARGV[0], the program name. */ + optstring = _getopt_initialize (argc, argv, optstring); + __getopt_initialized = 1; + } + + /* Test whether ARGV[optind] points to a non-option argument. + Either it does not have option syntax, or there is an environment flag + from the shell indicating it is not an option. The later information + is only used when the used in the GNU libc. */ +#if defined _LIBC && defined USE_NONOPTION_FLAGS +# define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0' \ + || (optind < nonoption_flags_len \ + && __getopt_nonoption_flags[optind] == '1')) +#else +# define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0') +#endif + + if (nextchar == NULL || *nextchar == '\0') + { + /* Advance to the next ARGV-element. */ + + /* Give FIRST_NONOPT and LAST_NONOPT rational values if OPTIND has been + moved back by the user (who may also have changed the arguments). */ + if (last_nonopt > optind) + last_nonopt = optind; + if (first_nonopt > optind) + first_nonopt = optind; + + if (ordering == PERMUTE) + { + /* If we have just processed some options following some non-options, + exchange them so that the options come first. */ + + if (first_nonopt != last_nonopt && last_nonopt != optind) + exchange ((char **) argv); + else if (last_nonopt != optind) + first_nonopt = optind; + + /* Skip any additional non-options + and extend the range of non-options previously skipped. */ + + while (optind < argc && NONOPTION_P) + optind++; + last_nonopt = optind; + } + + /* The special ARGV-element `--' means premature end of options. + Skip it like a null option, + then exchange with previous non-options as if it were an option, + then skip everything else like a non-option. */ + + if (optind != argc && !strcmp (argv[optind], "--")) + { + optind++; + + if (first_nonopt != last_nonopt && last_nonopt != optind) + exchange ((char **) argv); + else if (first_nonopt == last_nonopt) + first_nonopt = optind; + last_nonopt = argc; + + optind = argc; + } + + /* If we have done all the ARGV-elements, stop the scan + and back over any non-options that we skipped and permuted. */ + + if (optind == argc) + { + /* Set the next-arg-index to point at the non-options + that we previously skipped, so the caller will digest them. */ + if (first_nonopt != last_nonopt) + optind = first_nonopt; + return -1; + } + + /* If we have come to a non-option and did not permute it, + either stop the scan or describe it to the caller and pass it by. */ + + if (NONOPTION_P) + { + if (ordering == REQUIRE_ORDER) + return -1; + optarg = argv[optind++]; + return 1; + } + + /* We have found another option-ARGV-element. + Skip the initial punctuation. */ + + nextchar = (argv[optind] + 1 + + (longopts != NULL && argv[optind][1] == '-')); + } + + /* Decode the current option-ARGV-element. */ + + /* Check whether the ARGV-element is a long option. + + If long_only and the ARGV-element has the form "-f", where f is + a valid short option, don't consider it an abbreviated form of + a long option that starts with f. Otherwise there would be no + way to give the -f short option. + + On the other hand, if there's a long option "fubar" and + the ARGV-element is "-fu", do consider that an abbreviation of + the long option, just like "--fu", and not "-f" with arg "u". + + This distinction seems to be the most useful approach. */ + + if (longopts != NULL + && (argv[optind][1] == '-' + || (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1]))))) + { + char *nameend; + const struct option *p; + const struct option *pfound = NULL; + int exact = 0; + int ambig = 0; + int indfound = -1; + int option_index; + + for (nameend = nextchar; *nameend && *nameend != '='; nameend++) + /* Do nothing. */ ; + + /* Test all long options for either exact match + or abbreviated matches. */ + for (p = longopts, option_index = 0; p->name; p++, option_index++) + if (!strncmp (p->name, nextchar, nameend - nextchar)) + { + if ((unsigned int) (nameend - nextchar) + == (unsigned int) strlen (p->name)) + { + /* Exact match found. */ + pfound = p; + indfound = option_index; + exact = 1; + break; + } + else if (pfound == NULL) + { + /* First nonexact match found. */ + pfound = p; + indfound = option_index; + } + else if (long_only + || pfound->has_arg != p->has_arg + || pfound->flag != p->flag + || pfound->val != p->val) + /* Second or later nonexact match found. */ + ambig = 1; + } + + if (ambig && !exact) + { + if (print_errors) + { +#if defined _LIBC && defined USE_IN_LIBIO + char *buf; + + __asprintf (&buf, _("%s: option `%s' is ambiguous\n"), + argv[0], argv[optind]); + + if (_IO_fwide (stderr, 0) > 0) + __fwprintf (stderr, L"%s", buf); + else + fputs (buf, stderr); + + free (buf); +#else + fprintf (stderr, _("%s: option `%s' is ambiguous\n"), + argv[0], argv[optind]); +#endif + } + nextchar += strlen (nextchar); + optind++; + optopt = 0; + return '?'; + } + + if (pfound != NULL) + { + option_index = indfound; + optind++; + if (*nameend) + { + /* Don't test has_arg with >, because some C compilers don't + allow it to be used on enums. */ + if (pfound->has_arg) + optarg = nameend + 1; + else + { + if (print_errors) + { +#if defined _LIBC && defined USE_IN_LIBIO + char *buf; +#endif + + if (argv[optind - 1][1] == '-') + { + /* --option */ +#if defined _LIBC && defined USE_IN_LIBIO + __asprintf (&buf, _("\ +%s: option `--%s' doesn't allow an argument\n"), + argv[0], pfound->name); +#else + fprintf (stderr, _("\ +%s: option `--%s' doesn't allow an argument\n"), + argv[0], pfound->name); +#endif + } + else + { + /* +option or -option */ +#if defined _LIBC && defined USE_IN_LIBIO + __asprintf (&buf, _("\ +%s: option `%c%s' doesn't allow an argument\n"), + argv[0], argv[optind - 1][0], + pfound->name); +#else + fprintf (stderr, _("\ +%s: option `%c%s' doesn't allow an argument\n"), + argv[0], argv[optind - 1][0], pfound->name); +#endif + } + +#if defined _LIBC && defined USE_IN_LIBIO + if (_IO_fwide (stderr, 0) > 0) + __fwprintf (stderr, L"%s", buf); + else + fputs (buf, stderr); + + free (buf); +#endif + } + + nextchar += strlen (nextchar); + + optopt = pfound->val; + return '?'; + } + } + else if (pfound->has_arg == 1) + { + if (optind < argc) + optarg = argv[optind++]; + else + { + if (print_errors) + { +#if defined _LIBC && defined USE_IN_LIBIO + char *buf; + + __asprintf (&buf, + _("%s: option `%s' requires an argument\n"), + argv[0], argv[optind - 1]); + + if (_IO_fwide (stderr, 0) > 0) + __fwprintf (stderr, L"%s", buf); + else + fputs (buf, stderr); + + free (buf); +#else + fprintf (stderr, + _("%s: option `%s' requires an argument\n"), + argv[0], argv[optind - 1]); +#endif + } + nextchar += strlen (nextchar); + optopt = pfound->val; + return optstring[0] == ':' ? ':' : '?'; + } + } + nextchar += strlen (nextchar); + if (longind != NULL) + *longind = option_index; + if (pfound->flag) + { + *(pfound->flag) = pfound->val; + return 0; + } + return pfound->val; + } + + /* Can't find it as a long option. If this is not getopt_long_only, + or the option starts with '--' or is not a valid short + option, then it's an error. + Otherwise interpret it as a short option. */ + if (!long_only || argv[optind][1] == '-' + || my_index (optstring, *nextchar) == NULL) + { + if (print_errors) + { +#if defined _LIBC && defined USE_IN_LIBIO + char *buf; +#endif + + if (argv[optind][1] == '-') + { + /* --option */ +#if defined _LIBC && defined USE_IN_LIBIO + __asprintf (&buf, _("%s: unrecognized option `--%s'\n"), + argv[0], nextchar); +#else + fprintf (stderr, _("%s: unrecognized option `--%s'\n"), + argv[0], nextchar); +#endif + } + else + { + /* +option or -option */ +#if defined _LIBC && defined USE_IN_LIBIO + __asprintf (&buf, _("%s: unrecognized option `%c%s'\n"), + argv[0], argv[optind][0], nextchar); +#else + fprintf (stderr, _("%s: unrecognized option `%c%s'\n"), + argv[0], argv[optind][0], nextchar); +#endif + } + +#if defined _LIBC && defined USE_IN_LIBIO + if (_IO_fwide (stderr, 0) > 0) + __fwprintf (stderr, L"%s", buf); + else + fputs (buf, stderr); + + free (buf); +#endif + } + nextchar = (char *) ""; + optind++; + optopt = 0; + return '?'; + } + } + + /* Look at and handle the next short option-character. */ + + { + char c = *nextchar++; + char *temp = my_index (optstring, c); + + /* Increment `optind' when we start to process its last character. */ + if (*nextchar == '\0') + ++optind; + + if (temp == NULL || c == ':') + { + if (print_errors) + { +#if defined _LIBC && defined USE_IN_LIBIO + char *buf; +#endif + + if (posixly_correct) + { + /* 1003.2 specifies the format of this message. */ +#if defined _LIBC && defined USE_IN_LIBIO + __asprintf (&buf, _("%s: illegal option -- %c\n"), + argv[0], c); +#else + fprintf (stderr, _("%s: illegal option -- %c\n"), argv[0], c); +#endif + } + else + { +#if defined _LIBC && defined USE_IN_LIBIO + __asprintf (&buf, _("%s: invalid option -- %c\n"), + argv[0], c); +#else + fprintf (stderr, _("%s: invalid option -- %c\n"), argv[0], c); +#endif + } + +#if defined _LIBC && defined USE_IN_LIBIO + if (_IO_fwide (stderr, 0) > 0) + __fwprintf (stderr, L"%s", buf); + else + fputs (buf, stderr); + + free (buf); +#endif + } + optopt = c; + return '?'; + } + /* Convenience. Treat POSIX -W foo same as long option --foo */ + if (temp[0] == 'W' && temp[1] == ';') + { + char *nameend; + const struct option *p; + const struct option *pfound = NULL; + int exact = 0; + int ambig = 0; + int indfound = 0; + int option_index; + + /* This is an option that requires an argument. */ + if (*nextchar != '\0') + { + optarg = nextchar; + /* If we end this ARGV-element by taking the rest as an arg, + we must advance to the next element now. */ + optind++; + } + else if (optind == argc) + { + if (print_errors) + { + /* 1003.2 specifies the format of this message. */ +#if defined _LIBC && defined USE_IN_LIBIO + char *buf; + + __asprintf (&buf, _("%s: option requires an argument -- %c\n"), + argv[0], c); + + if (_IO_fwide (stderr, 0) > 0) + __fwprintf (stderr, L"%s", buf); + else + fputs (buf, stderr); + + free (buf); +#else + fprintf (stderr, _("%s: option requires an argument -- %c\n"), + argv[0], c); +#endif + } + optopt = c; + if (optstring[0] == ':') + c = ':'; + else + c = '?'; + return c; + } + else + /* We already incremented `optind' once; + increment it again when taking next ARGV-elt as argument. */ + optarg = argv[optind++]; + + /* optarg is now the argument, see if it's in the + table of longopts. */ + + for (nextchar = nameend = optarg; *nameend && *nameend != '='; nameend++) + /* Do nothing. */ ; + + /* Test all long options for either exact match + or abbreviated matches. */ + for (p = longopts, option_index = 0; p->name; p++, option_index++) + if (!strncmp (p->name, nextchar, nameend - nextchar)) + { + if ((unsigned int) (nameend - nextchar) == strlen (p->name)) + { + /* Exact match found. */ + pfound = p; + indfound = option_index; + exact = 1; + break; + } + else if (pfound == NULL) + { + /* First nonexact match found. */ + pfound = p; + indfound = option_index; + } + else + /* Second or later nonexact match found. */ + ambig = 1; + } + if (ambig && !exact) + { + if (print_errors) + { +#if defined _LIBC && defined USE_IN_LIBIO + char *buf; + + __asprintf (&buf, _("%s: option `-W %s' is ambiguous\n"), + argv[0], argv[optind]); + + if (_IO_fwide (stderr, 0) > 0) + __fwprintf (stderr, L"%s", buf); + else + fputs (buf, stderr); + + free (buf); +#else + fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"), + argv[0], argv[optind]); +#endif + } + nextchar += strlen (nextchar); + optind++; + return '?'; + } + if (pfound != NULL) + { + option_index = indfound; + if (*nameend) + { + /* Don't test has_arg with >, because some C compilers don't + allow it to be used on enums. */ + if (pfound->has_arg) + optarg = nameend + 1; + else + { + if (print_errors) + { +#if defined _LIBC && defined USE_IN_LIBIO + char *buf; + + __asprintf (&buf, _("\ +%s: option `-W %s' doesn't allow an argument\n"), + argv[0], pfound->name); + + if (_IO_fwide (stderr, 0) > 0) + __fwprintf (stderr, L"%s", buf); + else + fputs (buf, stderr); + + free (buf); +#else + fprintf (stderr, _("\ +%s: option `-W %s' doesn't allow an argument\n"), + argv[0], pfound->name); +#endif + } + + nextchar += strlen (nextchar); + return '?'; + } + } + else if (pfound->has_arg == 1) + { + if (optind < argc) + optarg = argv[optind++]; + else + { + if (print_errors) + { +#if defined _LIBC && defined USE_IN_LIBIO + char *buf; + + __asprintf (&buf, _("\ +%s: option `%s' requires an argument\n"), + argv[0], argv[optind - 1]); + + if (_IO_fwide (stderr, 0) > 0) + __fwprintf (stderr, L"%s", buf); + else + fputs (buf, stderr); + + free (buf); +#else + fprintf (stderr, + _("%s: option `%s' requires an argument\n"), + argv[0], argv[optind - 1]); +#endif + } + nextchar += strlen (nextchar); + return optstring[0] == ':' ? ':' : '?'; + } + } + nextchar += strlen (nextchar); + if (longind != NULL) + *longind = option_index; + if (pfound->flag) + { + *(pfound->flag) = pfound->val; + return 0; + } + return pfound->val; + } + nextchar = NULL; + return 'W'; /* Let the application handle it. */ + } + if (temp[1] == ':') + { + if (temp[2] == ':') + { + /* This is an option that accepts an argument optionally. */ + if (*nextchar != '\0') + { + optarg = nextchar; + optind++; + } + else + optarg = NULL; + nextchar = NULL; + } + else + { + /* This is an option that requires an argument. */ + if (*nextchar != '\0') + { + optarg = nextchar; + /* If we end this ARGV-element by taking the rest as an arg, + we must advance to the next element now. */ + optind++; + } + else if (optind == argc) + { + if (print_errors) + { + /* 1003.2 specifies the format of this message. */ +#if defined _LIBC && defined USE_IN_LIBIO + char *buf; + + __asprintf (&buf, + _("%s: option requires an argument -- %c\n"), + argv[0], c); + + if (_IO_fwide (stderr, 0) > 0) + __fwprintf (stderr, L"%s", buf); + else + fputs (buf, stderr); + + free (buf); +#else + fprintf (stderr, + _("%s: option requires an argument -- %c\n"), + argv[0], c); +#endif + } + optopt = c; + if (optstring[0] == ':') + c = ':'; + else + c = '?'; + } + else + /* We already incremented `optind' once; + increment it again when taking next ARGV-elt as argument. */ + optarg = argv[optind++]; + nextchar = NULL; + } + } + return c; + } +} + +int +getopt (argc, argv, optstring) +int argc; +char *const *argv; +const char *optstring; +{ + return _getopt_internal (argc, argv, optstring, + (const struct option *) 0, + (int *) 0, + 0); +} + +#endif /* Not ELIDE_CODE. */ + + +/* Compile with -DTEST to make an executable for use in testing + the above definition of `getopt'. */ \ No newline at end of file diff --git a/llvm/test/VISC/parboil/benchmarks/kmeans/src/visc/getopt.h b/llvm/test/VISC/parboil/benchmarks/kmeans/src/visc/getopt.h new file mode 100644 index 0000000000000000000000000000000000000000..943432ce30d884a30e681b96123d61a33e2ba16b --- /dev/null +++ b/llvm/test/VISC/parboil/benchmarks/kmeans/src/visc/getopt.h @@ -0,0 +1,191 @@ + + +/* getopt.h */ +/* Declarations for getopt. + Copyright (C) 1989-1994, 1996-1999, 2001 Free Software + Foundation, Inc. This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute + it and/or modify it under the terms of the GNU Lesser + General Public License as published by the Free Software + Foundation; either version 2.1 of the License, or + (at your option) any later version. + + The GNU C Library is distributed in the hope that it will + be useful, but WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A + PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General + Public License along with the GNU C Library; if not, write + to the Free Software Foundation, Inc., 59 Temple Place, + Suite 330, Boston, MA 02111-1307 USA. */ + + + + + +#ifndef _GETOPT_H + +#ifndef __need_getopt +# define _GETOPT_H 1 +#endif + +/* If __GNU_LIBRARY__ is not already defined, either we are being used + standalone, or this is the first header included in the source file. + If we are being used with glibc, we need to include <features.h>, but + that does not exist if we are standalone. So: if __GNU_LIBRARY__ is + not defined, include <ctype.h>, which will pull in <features.h> for us + if it's from glibc. (Why ctype.h? It's guaranteed to exist and it + doesn't flood the namespace with stuff the way some other headers do.) */ +#if !defined __GNU_LIBRARY__ +# include <ctype.h> +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* For communication from `getopt' to the caller. + When `getopt' finds an option that takes an argument, + the argument value is returned here. + Also, when `ordering' is RETURN_IN_ORDER, + each non-option ARGV-element is returned here. */ + +extern char *optarg; + +/* Index in ARGV of the next element to be scanned. + This is used for communication to and from the caller + and for communication between successive calls to `getopt'. + + On entry to `getopt', zero means this is the first call; initialize. + + When `getopt' returns -1, this is the index of the first of the + non-option elements that the caller should itself scan. + + Otherwise, `optind' communicates from one call to the next + how much of ARGV has been scanned so far. */ + +extern int optind; + +/* Callers store zero here to inhibit the error message `getopt' prints + for unrecognized options. */ + +extern int opterr; + +/* Set to an option character which was unrecognized. */ + +extern int optopt; + +#ifndef __need_getopt +/* Describe the long-named options requested by the application. + The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector + of `struct option' terminated by an element containing a name which is + zero. + + The field `has_arg' is: + no_argument (or 0) if the option does not take an argument, + required_argument (or 1) if the option requires an argument, + optional_argument (or 2) if the option takes an optional argument. + + If the field `flag' is not NULL, it points to a variable that is set + to the value given in the field `val' when the option is found, but + left unchanged if the option is not found. + + To have a long-named option do something other than set an `int' to + a compiled-in constant, such as set a value from `optarg', set the + option's `flag' field to zero and its `val' field to a nonzero + value (the equivalent single-letter option character, if there is + one). For long options that have a zero `flag' field, `getopt' + returns the contents of the `val' field. */ + +struct option +{ +# if (defined __STDC__ && __STDC__) || defined __cplusplus + const char *name; +# else + char *name; +# endif + /* has_arg can't be an enum because some compilers complain about + type mismatches in all the code that assumes it is an int. */ + int has_arg; + int *flag; + int val; +}; + +/* Names for the values of the `has_arg' field of `struct option'. */ + +# define no_argument 0 +# define required_argument 1 +# define optional_argument 2 +#endif /* need getopt */ + + +/* Get definitions and prototypes for functions to process the + arguments in ARGV (ARGC of them, minus the program name) for + options given in OPTS. + + Return the option character from OPTS just read. Return -1 when + there are no more options. For unrecognized options, or options + missing arguments, `optopt' is set to the option letter, and '?' is + returned. + + The OPTS string is a list of characters which are recognized option + letters, optionally followed by colons, specifying that that letter + takes an argument, to be placed in `optarg'. + + If a letter in OPTS is followed by two colons, its argument is + optional. This behavior is specific to the GNU `getopt'. + + The argument `--' causes premature termination of argument + scanning, explicitly telling `getopt' that there are no more + options. + + If OPTS begins with `--', then non-option arguments are treated as + arguments to the option '\0'. This behavior is specific to the GNU + `getopt'. */ + +#if (defined __STDC__ && __STDC__) || defined __cplusplus +# ifdef __GNU_LIBRARY__ +/* Many other libraries have conflicting prototypes for getopt, with + differences in the consts, in stdlib.h. To avoid compilation + errors, only prototype getopt for the GNU C library. */ +extern int getopt (int ___argc, char *const *___argv, const char *__shortopts); +# else /* not __GNU_LIBRARY__ */ +extern int getopt (); +# endif /* __GNU_LIBRARY__ */ + +# ifndef __need_getopt +extern int getopt_long (int ___argc, char *const *___argv, + const char *__shortopts, + const struct option *__longopts, int *__longind); +extern int getopt_long_only (int ___argc, char *const *___argv, + const char *__shortopts, + const struct option *__longopts, int *__longind); + +/* Internal only. Users should not call this directly. */ +extern int _getopt_internal (int ___argc, char *const *___argv, + const char *__shortopts, + const struct option *__longopts, int *__longind, + int __long_only); +# endif +#else /* not __STDC__ */ +extern int getopt (); +# ifndef __need_getopt +extern int getopt_long (); +extern int getopt_long_only (); + +extern int _getopt_internal (); +# endif +#endif /* __STDC__ */ + +#ifdef __cplusplus +} +#endif + +/* Make sure we later can get all the definitions and declarations. */ +#undef __need_getopt + +#endif /* getopt.h */ + diff --git a/llvm/test/VISC/parboil/benchmarks/kmeans/src/visc/kmeans.cl b/llvm/test/VISC/parboil/benchmarks/kmeans/src/visc/kmeans.cl new file mode 100644 index 0000000000000000000000000000000000000000..88dd2c2e215884acf19703645d8c70e2e3325e07 --- /dev/null +++ b/llvm/test/VISC/parboil/benchmarks/kmeans/src/visc/kmeans.cl @@ -0,0 +1,56 @@ +#ifndef FLT_MAX +#define FLT_MAX 3.40282347e+38 +#endif + +__kernel void +kmeans_kernel_c(__global float *feature, + __global float *clusters, + __global int *membership, + int npoints, + int nclusters, + int nfeatures, + int offset, + int size + ) +{ + unsigned int point_id = get_global_id(0); + int index = 0; + //const unsigned int point_id = get_global_id(0); + if (point_id < npoints) + { + float min_dist=FLT_MAX; + for (int i=0; i < nclusters; i++) { + + float dist = 0; + float ans = 0; + for (int l=0; l<nfeatures; l++) { + ans += (feature[l * npoints + point_id]-clusters[i*nfeatures+l])* + (feature[l * npoints + point_id]-clusters[i*nfeatures+l]); + } + + dist = ans; + if (dist < min_dist) { + min_dist = dist; + index = i; + + } + } + //printf("%d\n", index); + membership[point_id] = index; + } + + return; +} + +__kernel void +kmeans_swap(__global float *feature, + __global float *feature_swap, + int npoints, + int nfeatures + ) { + + unsigned int tid = get_global_id(0); + for(int i = 0; i < nfeatures; i++) + feature_swap[i * npoints + tid] = feature[tid * nfeatures + i]; + +} diff --git a/llvm/test/VISC/parboil/benchmarks/kmeans/src/visc/kmeans.cpp b/llvm/test/VISC/parboil/benchmarks/kmeans/src/visc/kmeans.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c664fde69e0a89c2be0daa5801a80bfa6042af6a --- /dev/null +++ b/llvm/test/VISC/parboil/benchmarks/kmeans/src/visc/kmeans.cpp @@ -0,0 +1,226 @@ +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <math.h> +#include <iostream> +#include <string> +#include "kmeans.h" + +#include <parboil.h> +#include <visc.h> + +#ifdef WIN +#include <windows.h> +#else +#include <pthread.h> +#include <sys/time.h> +double gettime() { + struct timeval t; + gettimeofday(&t,NULL); + return t.tv_sec+t.tv_usec*1e-6; +} +#endif + + +#ifdef NV +#else +#endif + +#ifndef FLT_MAX +#define FLT_MAX 3.40282347e+38 +#endif + +#ifdef RD_WG_SIZE_0_0 +#define BLOCK_SIZE RD_WG_SIZE_0_0 +#elif defined(RD_WG_SIZE_0) +#define BLOCK_SIZE RD_WG_SIZE_0 +#elif defined(RD_WG_SIZE) +#define BLOCK_SIZE RD_WG_SIZE +#else +#define BLOCK_SIZE 256 +#endif + +#ifdef RD_WG_SIZE_1_0 +#define BLOCK_SIZE2 RD_WG_SIZE_1_0 +#elif defined(RD_WG_SIZE_1) +#define BLOCK_SIZE2 RD_WG_SIZE_1 +#elif defined(RD_WG_SIZE) +#define BLOCK_SIZE2 RD_WG_SIZE +#else +#define BLOCK_SIZE2 256 +#endif + + +#ifndef FLT_MAX +#define FLT_MAX 3.40282347e+38 +#endif + +void +kmeans_kernel_c(float *feature, + float *clusters, + int *membership, + int npoints, + int nclusters, + int nfeatures, + int offset, + int size + ) +{ + __visc__attributes(3, feature, clusters, membership, 1, membership); + unsigned int point_id = get_global_id(0); + int index = 0; + //const unsigned int point_id = get_global_id(0); + if (point_id < npoints) + { + float min_dist=FLT_MAX; + for (int i=0; i < nclusters; i++) { + + float dist = 0; + float ans = 0; + for (int l=0; l<nfeatures; l++) { + ans += (feature[l * npoints + point_id]-clusters[i*nfeatures+l])* + (feature[l * npoints + point_id]-clusters[i*nfeatures+l]); + } + + dist = ans; + if (dist < min_dist) { + min_dist = dist; + index = i; + + } + } + //printf("%d\n", index); + membership[point_id] = index; + } + +} + +void +kmeans_swap(float *feature, + float *feature_swap, + int npoints, + int nfeatures + ) { + __visc__attributes(2, feature, feature_swap, 1, feature_swap); + + unsigned int tid = get_global_id(0); + for(int i = 0; i < nfeatures; i++) + feature_swap[i * npoints + tid] = feature[tid * nfeatures + i]; + +} + +// local variables + + +int *membership_OCL; +int *membership_d; +float *feature_d; +float *clusters_d; +float *center_d; + +float* feature_swap_d; + +__attribute__((noinline)) int allocate(int n_points, int n_features, int n_clusters, float **feature) +{ + + int sourcesize = 1024*1024; + char * source = (char *)calloc(sourcesize, sizeof(char)); + if(!source) { + printf("ERROR: calloc(%d) failed\n", sourcesize); + return -1; + } + + size_t bytes = n_points * n_features * sizeof(float); + feature_swap_d = (float*)malloc (bytes); + llvm_visc_track_mem(feature_swap_d, bytes); + unsigned global_work[3] = { n_points, 1, 1 }; + /// Ke Wang adjustable local group size 2013/08/07 10:37:33 + unsigned local_work_size= BLOCK_SIZE; // work group size is defined by RD_WG_SIZE_0 or RD_WG_SIZE_0_0 2014/06/10 17:00:51 + if(global_work[0]%local_work_size !=0) + global_work[0]=(global_work[0]/local_work_size+1)*local_work_size; + + unsigned swapDFG = __visc__node(kmeans_swap, 2, 1, local_work_size, + global_work[0]/local_work_size, 6, feature[0], bytes, (float*) + feature_swap_d, bytes, n_points, n_features, 0); + __visc__wait(swapDFG); + + llvm_visc_request_mem(feature_swap_d, n_points * n_features * sizeof(float)); + //for(int i = 0; i < n_points * n_features; i++) { + //std::cout << "feature_swap[" <<i << "] = " << feature_swap_d[i] << "\n"; + //} + membership_OCL = (int*) malloc(n_points * sizeof(int)); + llvm_visc_track_mem(membership_OCL, n_points * sizeof(int)); + return 0; +} + +void deallocateMemory() +{ + llvm_visc_untrack_mem(feature_swap_d); + llvm_visc_untrack_mem(membership_OCL); + free(feature_swap_d); + free(membership_OCL); +} + + +int main( int argc, char** argv) +{ + + __visc__init(); + printf("WG size of kernel_swap = %d, WG size of kernel_kmeans = %d \n", BLOCK_SIZE, BLOCK_SIZE2); + + setup(argc, argv); + __visc__cleanup(); +} + +__attribute__((noinline)) int kmeansOCL(float **feature, /* in: [npoints][nfeatures] */ + int n_features, + int n_points, + int n_clusters, + int *membership, + float **clusters, + int *new_centers_len, + float **new_centers) +{ + + int delta = 0; + int i, j, k; + + unsigned global_work[3] = { n_points, 1, 1 }; + + /// Ke Wang adjustable local group size 2013/08/07 10:37:33 + unsigned local_work_size=BLOCK_SIZE2; // work group size is defined by RD_WG_SIZE_1 or RD_WG_SIZE_1_0 2014/06/10 17:00:41 + if(global_work[0]%local_work_size !=0) + global_work[0]=(global_work[0]/local_work_size+1)*local_work_size; + + int size = 0; + int offset = 0; + size_t bytes = n_clusters * n_features * sizeof(float); + size_t bytes_feature = n_points * n_features * sizeof(float); + size_t bytes_membership = n_points * sizeof(int); + + + unsigned kmeansDFG = __visc__node(kmeans_kernel_c, 2, 1, local_work_size, + global_work[0]/local_work_size, 11, feature_swap_d, bytes_feature, clusters[0], + bytes, membership_OCL, bytes_membership, n_points, n_clusters, n_features, + offset, size, 0); + __visc__wait(kmeansDFG); + llvm_visc_request_mem(membership_OCL, bytes_membership); // read membership into membership_OCL + + delta = 0; + for (i = 0; i < n_points; i++) + { + int cluster_id = membership_OCL[i]; + new_centers_len[cluster_id]++; + if (membership_OCL[i] != membership[i]) + { + delta++; + membership[i] = membership_OCL[i]; + } + for (j = 0; j < n_features; j++) + { + new_centers[cluster_id][j] += feature[i][j]; + } + } + + return delta; +} diff --git a/llvm/test/VISC/parboil/benchmarks/kmeans/src/visc/kmeans.h b/llvm/test/VISC/parboil/benchmarks/kmeans/src/visc/kmeans.h new file mode 100644 index 0000000000000000000000000000000000000000..0397992475a6023e2958c99b3098680d90285e5c --- /dev/null +++ b/llvm/test/VISC/parboil/benchmarks/kmeans/src/visc/kmeans.h @@ -0,0 +1,64 @@ +/*****************************************************************************/ +/*IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. */ +/*By downloading, copying, installing or using the software you agree */ +/*to this license. If you do not agree to this license, do not download, */ +/*install, copy or use the software. */ +/* */ +/* */ +/*Copyright (c) 2005 Northwestern University */ +/*All rights reserved. */ + +/*Redistribution of the software in source and binary forms, */ +/*with or without modification, is permitted provided that the */ +/*following conditions are met: */ +/* */ +/*1 Redistributions of source code must retain the above copyright */ +/* notice, this list of conditions and the following disclaimer. */ +/* */ +/*2 Redistributions in binary form must reproduce the above copyright */ +/* notice, this list of conditions and the following disclaimer in the */ +/* documentation and/or other materials provided with the distribution.*/ +/* */ +/*3 Neither the name of Northwestern University nor the names of its */ +/* contributors may be used to endorse or promote products derived */ +/* from this software without specific prior written permission. */ +/* */ +/*THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS */ +/*IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED */ +/*TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND */ +/*FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL */ +/*NORTHWESTERN UNIVERSITY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, */ +/*INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */ +/*(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR */ +/*SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ +/*HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, */ +/*STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN */ +/*ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */ +/*POSSIBILITY OF SUCH DAMAGE. */ +/******************************************************************************/ + +#ifndef _H_FUZZY_KMEANS +#define _H_FUZZY_KMEANS + +#ifndef FLT_MAX +#define FLT_MAX 3.40282347e+38 +#endif + +/* rmse.c */ +float euclid_dist_2 (float*, float*, int); +int find_nearest_point (float* , int, float**, int); +float rms_err(float**, int, int, float**, int); +int cluster(int, int, float**, int, int, float, int*, float***, float*, int, int); +#ifdef __cplusplus +extern "C" { +#endif + int setup(int argc, char** argv); + int allocate(int npoints, int nfeatures, int nclusters, float **feature); + void deallocateMemory(); + int kmeansOCL(float **feature, int nfeatures, int npoints, int nclusters, int *membership, float **clusters, int *new_centers_len, float **new_centers); +#ifdef __cplusplus +} +#endif +float** kmeans_clustering(float **feature, int nfeatures, int npoints, int nclusters, float threshold, int *membership); + +#endif diff --git a/llvm/test/VISC/parboil/benchmarks/kmeans/src/visc/kmeans_clustering.c b/llvm/test/VISC/parboil/benchmarks/kmeans/src/visc/kmeans_clustering.c new file mode 100644 index 0000000000000000000000000000000000000000..173ffa5e5a0eb6eb8be6de5a5cd4857aafc1af29 --- /dev/null +++ b/llvm/test/VISC/parboil/benchmarks/kmeans/src/visc/kmeans_clustering.c @@ -0,0 +1,181 @@ +/*****************************************************************************/ +/*IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. */ +/*By downloading, copying, installing or using the software you agree */ +/*to this license. If you do not agree to this license, do not download, */ +/*install, copy or use the software. */ +/* */ +/* */ +/*Copyright (c) 2005 Northwestern University */ +/*All rights reserved. */ + +/*Redistribution of the software in source and binary forms, */ +/*with or without modification, is permitted provided that the */ +/*following conditions are met: */ +/* */ +/*1 Redistributions of source code must retain the above copyright */ +/* notice, this list of conditions and the following disclaimer. */ +/* */ +/*2 Redistributions in binary form must reproduce the above copyright */ +/* notice, this list of conditions and the following disclaimer in the */ +/* documentation and/or other materials provided with the distribution.*/ +/* */ +/*3 Neither the name of Northwestern University nor the names of its */ +/* contributors may be used to endorse or promote products derived */ +/* from this software without specific prior written permission. */ +/* */ +/*THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS */ +/*IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED */ +/*TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND */ +/*FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL */ +/*NORTHWESTERN UNIVERSITY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, */ +/*INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */ +/*(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR */ +/*SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ +/*HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, */ +/*STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN */ +/*ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */ +/*POSSIBILITY OF SUCH DAMAGE. */ +/******************************************************************************/ + +/*************************************************************************/ +/** File: kmeans_clustering.c **/ +/** Description: Implementation of regular k-means clustering **/ +/** algorithm **/ +/** Author: Wei-keng Liao **/ +/** ECE Department, Northwestern University **/ +/** email: wkliao@ece.northwestern.edu **/ +/** **/ +/** Edited by: Jay Pisharath **/ +/** Northwestern University. **/ +/** **/ +/** ================================================================ **/ +/** **/ +/** Edited by: Shuai Che, David Tarjan, Sang-Ha Lee **/ +/** University of Virginia **/ +/** **/ +/** Description: No longer supports fuzzy c-means clustering; **/ +/** only regular k-means clustering. **/ +/** No longer performs "validity" function to analyze **/ +/** compactness and separation crietria; instead **/ +/** calculate root mean squared error. **/ +/** **/ +/*************************************************************************/ + +#include <stdio.h> +#include <stdlib.h> +#include <float.h> +#include <math.h> + +#include "kmeans.h" +#include <visc.h> + +#define RANDOM_MAX 2147483647 + +extern double wtime(void); + +/*----< kmeans_clustering() >---------------------------------------------*/ +float** kmeans_clustering(float **feature, /* in: [npoints][nfeatures] */ + int nfeatures, + int npoints, + int nclusters, + float threshold, + int *membership) /* out: [npoints] */ +{ + int i, j, n = 0; /* counters */ + int loop=0, temp; + int *new_centers_len; /* [nclusters]: no. of points in each cluster */ + float delta; /* if the point moved */ + float **clusters; /* out: [nclusters][nfeatures] */ + float **new_centers; /* [nclusters][nfeatures] */ + + int *initial; /* used to hold the index of points not yet selected + prevents the "birthday problem" of dual selection (?) + considered holding initial cluster indices, but changed due to + possible, though unlikely, infinite loops */ + int initial_points; + int c = 0; + + /* nclusters should never be > npoints + that would guarantee a cluster without points */ + if (nclusters > npoints) + nclusters = npoints; + + /* allocate space for and initialize returning variable clusters[] */ + clusters = (float**) malloc(nclusters * sizeof(float*)); + clusters[0] = (float*) malloc(nclusters * nfeatures * sizeof(float)); + llvm_visc_track_mem(clusters[0], nclusters * nfeatures * sizeof(float)); + + for (i=1; i<nclusters; i++) + clusters[i] = clusters[i-1] + nfeatures; + + /* initialize the random clusters */ + initial = (int *) malloc (npoints * sizeof(int)); + for (i = 0; i < npoints; i++) + { + initial[i] = i; + } + initial_points = npoints; + + /* randomly pick cluster centers */ + for (i=0; i<nclusters && initial_points >= 0; i++) { + //n = (int)rand() % initial_points; + + for (j=0; j<nfeatures; j++) + clusters[i][j] = feature[initial[n]][j]; // remapped + + /* swap the selected index to the end (not really necessary, + could just move the end up) */ + temp = initial[n]; + initial[n] = initial[initial_points-1]; + initial[initial_points-1] = temp; + initial_points--; + n++; + } + + /* initialize the membership to -1 for all */ + for (i=0; i < npoints; i++) + membership[i] = -1; + + /* allocate space for and initialize new_centers_len and new_centers */ + new_centers_len = (int*) calloc(nclusters, sizeof(int)); + + new_centers = (float**) malloc(nclusters * sizeof(float*)); + new_centers[0] = (float*) calloc(nclusters * nfeatures, sizeof(float)); + for (i=1; i<nclusters; i++) + new_centers[i] = new_centers[i-1] + nfeatures; + + /* iterate until convergence */ + do { + delta = 0.0; + // CUDA + delta = (float) kmeansOCL(feature, /* in: [npoints][nfeatures] */ + nfeatures, /* number of attributes for each point */ + npoints, /* number of data points */ + nclusters, /* number of clusters */ + membership, /* which cluster the point belongs to */ + clusters, /* out: [nclusters][nfeatures] */ + new_centers_len, /* out: number of points in each cluster */ + new_centers /* sum of points in each cluster */ + ); + + /* replace old cluster centers with new_centers */ + /* CPU side of reduction */ + llvm_visc_request_mem(clusters[0], nclusters * nfeatures * sizeof(float)); + for (i=0; i<nclusters; i++) { + for (j=0; j<nfeatures; j++) { + if (new_centers_len[i] > 0) + clusters[i][j] = new_centers[i][j] / new_centers_len[i]; /* take average i.e. sum/n */ + new_centers[i][j] = 0.0; /* set back to 0 */ + } + new_centers_len[i] = 0; /* set back to 0 */ + } + c++; + } while ((delta > threshold) && (loop++ < 500)); /* makes sure loop terminates */ + printf("iterated %d times\n", c); + free(new_centers[0]); + free(new_centers); + free(new_centers_len); + + return clusters; +} + diff --git a/llvm/test/VISC/parboil/benchmarks/kmeans/src/visc/read_input.c b/llvm/test/VISC/parboil/benchmarks/kmeans/src/visc/read_input.c new file mode 100644 index 0000000000000000000000000000000000000000..103bdd5e1ef793a7d68b010396e00ac72b254cd4 --- /dev/null +++ b/llvm/test/VISC/parboil/benchmarks/kmeans/src/visc/read_input.c @@ -0,0 +1,332 @@ +/*****************************************************************************/ +/*IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. */ +/*By downloading, copying, installing or using the software you agree */ +/*to this license. If you do not agree to this license, do not download, */ +/*install, copy or use the software. */ +/* */ +/* */ +/*Copyright (c) 2005 Northwestern University */ +/*All rights reserved. */ + +/*Redistribution of the software in source and binary forms, */ +/*with or without modification, is permitted provided that the */ +/*following conditions are met: */ +/* */ +/*1 Redistributions of source code must retain the above copyright */ +/* notice, this list of conditions and the following disclaimer. */ +/* */ +/*2 Redistributions in binary form must reproduce the above copyright */ +/* notice, this list of conditions and the following disclaimer in the */ +/* documentation and/or other materials provided with the distribution.*/ +/* */ +/*3 Neither the name of Northwestern University nor the names of its */ +/* contributors may be used to endorse or promote products derived */ +/* from this software without specific prior written permission. */ +/* */ +/*THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS */ +/*IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED */ +/*TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND */ +/*FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL */ +/*NORTHWESTERN UNIVERSITY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, */ +/*INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */ +/*(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR */ +/*SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ +/*HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, */ +/*STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN */ +/*ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */ +/*POSSIBILITY OF SUCH DAMAGE. */ +/******************************************************************************/ + +/*************************************************************************/ +/** File: example.c **/ +/** Description: Takes as input a file: **/ +/** ascii file: containing 1 data point per line **/ +/** binary file: first int is the number of objects **/ +/** 2nd int is the no. of features of each **/ +/** object **/ +/** This example performs a fuzzy c-means clustering **/ +/** on the data. Fuzzy clustering is performed using **/ +/** min to max clusters and the clustering that gets **/ +/** the best score according to a compactness and **/ +/** separation criterion are returned. **/ +/** Author: Wei-keng Liao **/ +/** ECE Department Northwestern University **/ +/** email: wkliao@ece.northwestern.edu **/ +/** **/ +/** Edited by: Jay Pisharath **/ +/** Northwestern University. **/ +/** **/ +/** ================================================================ **/ +/** **/ +/** Edited by: Shuai Che, David Tarjan, Sang-Ha Lee **/ +/** University of Virginia **/ +/** **/ +/** Description: No longer supports fuzzy c-means clustering; **/ +/** only regular k-means clustering. **/ +/** No longer performs "validity" function to analyze **/ +/** compactness and separation crietria; instead **/ +/** calculate root mean squared error. **/ +/** **/ +/*************************************************************************/ +#define _CRT_SECURE_NO_DEPRECATE 1 + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <limits.h> +#include <math.h> +#include <fcntl.h> + +#include "kmeans.h" +#include <unistd.h> +#include <visc.h> + +extern double wtime(void); + + + +/*---< usage() >------------------------------------------------------------*/ +void usage(char *argv0) { + char *help = + "\nUsage: %s [switches] -i filename\n\n" + " -i filename :file containing data to be clustered\n" + " -m max_nclusters :maximum number of clusters allowed [default=5]\n" + " -n min_nclusters :minimum number of clusters allowed [default=5]\n" + " -t threshold :threshold value [default=0.001]\n" + " -l nloops :iteration for each number of clusters [default=1]\n" + " -b :input file is in binary format\n" + " -r :calculate RMSE [default=off]\n" + " -o :output cluster center coordinates [default=off]\n"; + fprintf(stderr, help, argv0); + exit(-1); +} + +/*---< main() >-------------------------------------------------------------*/ +int setup(int argc, char **argv) { + int opt; + extern char *optarg; + char *filename = 0; + char* outfilename = 0; + float *buf; + char line[1024]; + int isBinaryFile = 0; + + float threshold = 0.001; /* default value */ + int max_nclusters=5; /* default value */ + int min_nclusters=5; /* default value */ + int best_nclusters = 0; + int nfeatures = 0; + int npoints = 0; + float len; + + float **features; + float **cluster_centres=NULL; + int i, j, index; + int nloops = 1; /* default value */ + + int isRMSE = 0; + float rmse; + + int isOutput = 0; + //float cluster_timing, io_timing; + + /* obtain command line arguments and change appropriate options */ + while ( (opt=getopt(argc,argv,"i:t:m:n:l:o:br"))!= EOF) { + switch (opt) { + case 'i': + filename=optarg; + break; + case 'b': + isBinaryFile = 1; + break; + case 't': + threshold=atof(optarg); + break; + case 'm': + max_nclusters = atoi(optarg); + break; + case 'n': + min_nclusters = atoi(optarg); + break; + case 'r': + isRMSE = 1; + break; + case 'o': + isOutput = 1; + outfilename = optarg; + break; + case 'l': + nloops = atoi(optarg); + break; + case '?': + usage(argv[0]); + break; + default: + usage(argv[0]); + break; + } + } + + if (filename == 0) usage(argv[0]); + + /* ============== I/O begin ==============*/ + /* get nfeatures and npoints */ + //io_timing = omp_get_wtime(); + if (isBinaryFile) { //Binary file input + int infile; + if ((infile = open(filename, O_RDONLY, "0600")) == -1) { + fprintf(stderr, "Error: no such file (%s)\n", filename); + exit(1); + } + read(infile, &npoints, sizeof(int)); + read(infile, &nfeatures, sizeof(int)); + + /* allocate space for features[][] and read attributes of all objects */ + buf = (float*) malloc(npoints*nfeatures*sizeof(float)); + features = (float**)malloc(npoints* sizeof(float*)); + features[0] = (float*) malloc(npoints*nfeatures*sizeof(float)); + for (i=1; i<npoints; i++) + features[i] = features[i-1] + nfeatures; + + + read(infile, buf, npoints*nfeatures*sizeof(float)); + + close(infile); + } + else { + FILE *infile; + if ((infile = fopen(filename, "r")) == NULL) { + fprintf(stderr, "Error: no such file (%s)\n", filename); + exit(1); + } + while (fgets(line, 1024, infile) != NULL) + if (strtok(line, " \t\n") != 0) + npoints++; + rewind(infile); + while (fgets(line, 1024, infile) != NULL) { + if (strtok(line, " \t\n") != 0) { + /* ignore the id (first attribute): nfeatures = 1; */ + while (strtok(NULL, " ,\t\n") != NULL) nfeatures++; + break; + } + } + + /* allocate space for features[] and read attributes of all objects */ + buf = (float*) malloc(npoints*nfeatures*sizeof(float)); + features = (float**)malloc(npoints* sizeof(float*)); + features[0] = (float*) malloc(npoints*nfeatures*sizeof(float)); + for (i=1; i<npoints; i++) + features[i] = features[i-1] + nfeatures; + rewind(infile); + i = 0; + while (fgets(line, 1024, infile) != NULL) { + if (strtok(line, " \t\n") == NULL) continue; + for (j=0; j<nfeatures; j++) { + buf[i] = atof(strtok(NULL, " ,\t\n")); + i++; + } + } + fclose(infile); + } + //io_timing = omp_get_wtime() - io_timing; + llvm_visc_track_mem(features[0], npoints*nfeatures*sizeof(float)); + + printf("\nI/O completed\n"); + printf("\nNumber of objects: %d\n", npoints); + printf("Number of features: %d\n", nfeatures); + /* ============== I/O end ==============*/ + + // error check for clusters + if (npoints < min_nclusters) + { + printf("Error: min_nclusters(%d) > npoints(%d) -- cannot proceed\n", min_nclusters, npoints); + exit(0); + } + + srand(7); /* seed for future random number generator */ + memcpy(features[0], buf, npoints*nfeatures*sizeof(float)); /* now features holds 2-dimensional array of features */ + free(buf); + + /* ======================= core of the clustering ===================*/ + + //cluster_timing = omp_get_wtime(); /* Total clustering time */ + cluster_centres = NULL; + index = cluster(npoints, /* number of data points */ + nfeatures, /* number of features for each point */ + features, /* array: [npoints][nfeatures] */ + min_nclusters, /* range of min to max number of clusters */ + max_nclusters, + threshold, /* loop termination factor */ + &best_nclusters, /* return: number between min and max */ + &cluster_centres, /* return: [best_nclusters][nfeatures] */ + &rmse, /* Root Mean Squared Error */ + isRMSE, /* calculate RMSE */ + nloops); /* number of iteration for each number of clusters */ + + //cluster_timing = omp_get_wtime() - cluster_timing; + + + /* =============== Command Line Output =============== */ + + /* cluster center coordinates + :displayed only for when k=1*/ + + //printf("Input file = %s\n", filename); + //printf("Output file = %s\n", outfilename); + if((min_nclusters == max_nclusters) && (isOutput == 1)) { + FILE *outfile; + if ((outfile = fopen(outfilename, "w")) == NULL) { + fprintf(stderr, "Error: no such file (%s)\n", outfilename); + exit(1); + } + fwrite(&max_nclusters, sizeof(int), 1, outfile); + fwrite(&nfeatures, sizeof(int), 1, outfile); + fwrite(&cluster_centres[0][0], sizeof(float), max_nclusters*nfeatures, outfile); + fclose(outfile); + /*printf("\n================= Centroid Coordinates =================\n");*/ + /*for(i = 0; i < max_nclusters; i++) {*/ + /*printf("%d:", i);*/ + /*for(j = 0; j < nfeatures; j++) {*/ + /*printf(" %.2f", cluster_centres[i][j]);*/ + /*}*/ + /*printf("\n\n");*/ + /*}*/ + } + + len = (float) ((max_nclusters - min_nclusters + 1)*nloops); + + //printf("Time for I/O: %.5fsec\n", io_timing); + //printf("Time for Entire Clustering: %.5fsec\n", cluster_timing); + + if(min_nclusters != max_nclusters) { + if(nloops != 1) { //range of k, multiple iteration + //printf("Average Clustering Time: %fsec\n", + // cluster_timing / len); + printf("Best number of clusters is %d\n", best_nclusters); + } + else { //range of k, single iteration + //printf("Average Clustering Time: %fsec\n", + // cluster_timing / len); + printf("Best number of clusters is %d\n", best_nclusters); + } + } + else { + if(nloops != 1) { // single k, multiple iteration + //printf("Average Clustering Time: %.5fsec\n", + // cluster_timing / nloops); + if(isRMSE) // if calculated RMSE + printf("Number of trials to approach the best RMSE of %.3f is %d\n", rmse, index + 1); + } + else { // single k, single iteration + if(isRMSE) // if calculated RMSE + printf("Root Mean Squared Error: %.3f\n", rmse); + } + } + + + /* free up memory */ + free(features[0]); + free(features); + return(0); +} + diff --git a/llvm/test/VISC/parboil/benchmarks/kmeans/src/visc/rmse.c b/llvm/test/VISC/parboil/benchmarks/kmeans/src/visc/rmse.c new file mode 100644 index 0000000000000000000000000000000000000000..0029c64dc73e27c24c96a10d4f3adb5c5d7c278c --- /dev/null +++ b/llvm/test/VISC/parboil/benchmarks/kmeans/src/visc/rmse.c @@ -0,0 +1,95 @@ +/*************************************************************************/ +/** File: rmse.c **/ +/** Description: calculate root mean squared error of particular **/ +/** clustering. **/ +/** Author: Sang-Ha Lee **/ +/** University of Virginia. **/ +/** **/ +/** Note: euclid_dist_2() and find_nearest_point() adopted from **/ +/** Minebench code. **/ +/** **/ +/*************************************************************************/ + +#include <stdio.h> +#include <stdlib.h> +#include <float.h> +#include <math.h> + + +#include "kmeans.h" + +extern double wtime(void); + +/*----< euclid_dist_2() >----------------------------------------------------*/ +/* multi-dimensional spatial Euclid distance square */ +__inline +float euclid_dist_2(float *pt1, + float *pt2, + int numdims) +{ + int i; + float ans=0.0; + + for (i=0; i<numdims; i++) + ans += (pt1[i]-pt2[i]) * (pt1[i]-pt2[i]); + + return(ans); +} + +/*----< find_nearest_point() >-----------------------------------------------*/ +__inline +int find_nearest_point(float *pt, /* [nfeatures] */ + int nfeatures, + float **pts, /* [npts][nfeatures] */ + int npts) +{ + int index, i; + float max_dist=FLT_MAX; + + /* find the cluster center id with min distance to pt */ + for (i=0; i<npts; i++) { + float dist; + dist = euclid_dist_2(pt, pts[i], nfeatures); /* no need square root */ + if (dist < max_dist) { + max_dist = dist; + index = i; + } + } + return(index); +} + +/*----< rms_err(): calculates RMSE of clustering >-------------------------------------*/ +float rms_err (float **feature, /* [npoints][nfeatures] */ + int nfeatures, + int npoints, + float **cluster_centres, /* [nclusters][nfeatures] */ + int nclusters) +{ + int i; + int nearest_cluster_index; /* cluster center id with min distance to pt */ + float sum_euclid = 0.0; /* sum of Euclidean distance squares */ + float ret; /* return value */ + + /* calculate and sum the sqaure of euclidean distance*/ + #pragma omp parallel for \ + shared(feature,cluster_centres) \ + firstprivate(npoints,nfeatures,nclusters) \ + private(i, nearest_cluster_index) \ + schedule (static) + for (i=0; i<npoints; i++) { + nearest_cluster_index = find_nearest_point(feature[i], + nfeatures, + cluster_centres, + nclusters); + + sum_euclid += euclid_dist_2(feature[i], + cluster_centres[nearest_cluster_index], + nfeatures); + + } + /* divide by n, then take sqrt */ + ret = sqrt(sum_euclid / npoints); + + return(ret); +} + diff --git a/llvm/test/VISC/parboil/benchmarks/kmeans/src/visc/run b/llvm/test/VISC/parboil/benchmarks/kmeans/src/visc/run new file mode 100755 index 0000000000000000000000000000000000000000..9fcc65554d21c9fcfbc2057804c4a82df1105c8b --- /dev/null +++ b/llvm/test/VISC/parboil/benchmarks/kmeans/src/visc/run @@ -0,0 +1 @@ +./kmeans -o -i ../../../../datasets/kmeans/kdd_cup diff --git a/llvm/test/VISC/parboil/benchmarks/kmeans/src/visc/unistd.h b/llvm/test/VISC/parboil/benchmarks/kmeans/src/visc/unistd.h new file mode 100644 index 0000000000000000000000000000000000000000..ff334e56eb5314f4efe7714b202180da2bdd1fea --- /dev/null +++ b/llvm/test/VISC/parboil/benchmarks/kmeans/src/visc/unistd.h @@ -0,0 +1,945 @@ +/* IBM_PROLOG_BEGIN_TAG */ +/* This is an automatically generated prolog. */ +/* */ +/* bos53H src/bos/usr/include/unistd.h 1.38.4.46 */ +/* */ +/* Licensed Materials - Property of IBM */ +/* */ +/* (C) COPYRIGHT International Business Machines Corp. 1985,1995 */ +/* All Rights Reserved */ +/* */ +/* US Government Users Restricted Rights - Use, duplication or */ +/* disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ +/* */ +/* IBM_PROLOG_END_TAG */ +/* @(#)82 1.38.4.46 src/bos/usr/include/unistd.h, incstd, bos53H, h2006_17B8 4/25/06 11:53:09 */ +/* + * COMPONENT_NAME: (INCSTD) Standard Include Files + * + * FUNCTIONS: + * + * ORIGINS: 3 27 + * + * (C) COPYRIGHT International Business Machines Corp. 1985, 2006 + * All Rights Reserved + * Licensed Materials - Property of IBM + * + * US Government Users Restricted Rights - Use, duplication or + * disclosure restricted by GSA ADP Schedule Contract with IBM Corp. + * + * Copyright (c) 1984 AT&T + * All Rights Reserved + * + * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T + * The copyright notice above does not evidence any + * actual or intended publication of such source code. + */ + +#ifndef _H_UNISTD +#define _H_UNISTD + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _H_STANDARDS +#include <standards.h> +#endif + +#include <strict_stdtypes.h> + +#ifndef _H_TYPES +#include <sys/types.h> +#endif + +#include <end_strict_stdtypes.h> + +#ifndef _H_ACCESS +#include <sys/access.h> /* for the "access" function */ +#endif + +/* + * POSIX requires that certain values be included in unistd.h. It also + * requires that when _POSIX_SOURCE is defined only those standard + * specific values are present. This header includes all the POSIX + * required entries. + */ + +#ifdef _POSIX_SOURCE +#ifdef _LARGE_FILES +#define lseek lseek64 +#endif + + +/* Symbolic constants for the "lseek" function: */ +#ifndef SEEK_SET +#define SEEK_SET 0 /* Set file pointer to "offset" */ +#define SEEK_CUR 1 /* Set file pointer to current plus "offset" */ +#define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ +#endif /* SEEK_SET */ + +#ifdef _NO_PROTO + +#ifndef _KERNEL +extern int access(); +extern unsigned int alarm(); +extern int chdir(); +extern int chown(); +extern int close(); +extern char *ctermid(); +extern int dup(); +extern int dup2(); +extern int execl(); +extern int execv(); +extern int execle(); +extern int execve(); +extern int execlp(); +extern int execvp(); +extern void _exit(); +extern pid_t fork(); +extern long fpathconf(); +extern char *getcwd(); +extern gid_t getegid(); +extern uid_t geteuid(); +extern gid_t getgid(); +extern int getgroups(); +extern char *getlogin(); +extern pid_t getpgrp(); +extern pid_t getpid(); +extern pid_t getppid(); +extern uid_t getuid(); +extern int isatty(); +extern int link(); +extern off_t lseek(); +extern long pathconf(); +extern int pause(); +extern int pipe(); +#if defined(_XOPEN_SOURCE) && ( _XOPEN_SOURCE >= 500 ) +extern int pthread_atfork(); +#endif +extern int read(); +extern int rmdir(); +extern int setgid(); +extern int setpgid(); +extern int setsid(); +extern int setuid(); +extern unsigned int sleep(); +extern long sysconf(); +extern pid_t tcgetpgrp(); +extern int tcsetpgrp(); +extern char *ttyname(); +extern int unlink(); +extern int write(); +#endif /* !_KERNEL */ + +#else /* POSIX required prototypes */ + +#ifndef _KERNEL +extern int access(const char *, int); +extern unsigned int alarm(unsigned int); +extern int chdir(const char *); +extern int chown(const char *, uid_t, gid_t); +extern int close(int); +extern char *ctermid(char *); +extern int dup(int); +extern int dup2(int, int); +extern int execl(const char *, const char *, ...); +extern int execv(const char *, char *const []); +extern int execle(const char *, const char *, ...); +extern int execve(const char *, char *const [], char *const []); +extern int execlp(const char *, const char *, ...); +extern int execvp(const char *, char *const []); +extern void _exit(int); +extern pid_t fork(void); +extern long fpathconf(int, int); +extern char *getcwd(char *, size_t); +extern gid_t getegid(void); +extern uid_t geteuid(void); +extern gid_t getgid(void); +extern int getgroups(int, gid_t []); +extern char *getlogin(void); +#ifndef _BSD +extern pid_t getpgrp(void); +#endif /* _BSD */ +extern pid_t getpid(void); +extern pid_t getppid(void); +extern uid_t getuid(void); +extern int isatty(int); +extern int link(const char *, const char *); +extern off_t lseek(int, off_t, int); +#ifdef _LARGE_FILE_API +extern off64_t lseek64(int, off64_t, int); +#endif +extern long pathconf(const char *, int); +extern int pause(void); +extern int pipe(int []); +#if defined(_XOPEN_SOURCE) && ( _XOPEN_SOURCE >= 500 ) +extern int pthread_atfork(void (*)(void), void (*)(void), void (*)(void)); +#endif +extern ssize_t read(int, void *, size_t); +extern int rmdir(const char *); +extern int setgid(gid_t); +extern int setpgid(pid_t, pid_t); +extern pid_t setsid(void); +extern int setuid(uid_t); +extern unsigned int sleep(unsigned int); +extern long sysconf(int); +extern pid_t tcgetpgrp(int); +extern int tcsetpgrp(int, pid_t); +extern char *ttyname(int); +extern int unlink(const char *); +extern ssize_t write(int, const void *, size_t); +#endif /* !_KERNEL */ +#endif /* !_NO_PROTO */ + +#define STDIN_FILENO 0 +#define STDOUT_FILENO 1 +#define STDERR_FILENO 2 + +#define _POSIX_JOB_CONTROL 1 +#define _POSIX_SAVED_IDS 1 + +#define _POSIX_VERSION 200112L +#define _POSIX2_VERSION 200112L +#define _POSIX2_C_VERSION 200112L + + +#ifdef _XOPEN_SOURCE + +#define _XOPEN_VERSION 600 +#define _XOPEN_XCU_VERSION 4 +#define _XOPEN_XPG3 1 +#define _XOPEN_XPG4 1 +#define _XOPEN_UNIX 1 + +#define _XOPEN_REALTIME (-1) +#define _XOPEN_REALTIME_THREADS (-1) + +#if (_XOPEN_SOURCE >= 600) +#define _XOPEN_STREAMS 1 +#endif + +#define _XBS5_ILP32_OFF32 1 +#define _XBS5_ILP32_OFFBIG 1 +#define _XBS5_LP64_OFF64 1 +#define _XBS5_LPBIG_OFFBIG 1 + +#define _POSIX2_C_BIND 200112L +#define _POSIX2_C_DEV 200112L +#define _POSIX2_CHAR_TERM 1 +#define _POSIX2_LOCALEDEF 200112L +#define _POSIX2_UPE 200112L +#define _POSIX2_FORT_DEV (-1) +#define _POSIX2_FORT_RUN (-1) +#define _POSIX2_SW_DEV (-1) + +#if (_POSIX_C_SOURCE >= 200112L) +#define _POSIX_REGEXP 1 +#define _POSIX_SHELL 1 +#define _POSIX2_PBS (-1) +#define _POSIX2_PBS_ACCOUNTING (-1) +#define _POSIX2_PBS_CHECKPOINT (-1) +#define _POSIX2_PBS_LOCATE (-1) +#define _POSIX2_PBS_MESSAGE (-1) +#define _POSIX2_PBS_TRACK (-1) +#define _V6_ILP32_OFF32 1 +#define _V6_ILP32_OFFBIG 1 +#define _V6_LP64_OFF64 1 +#define _V6_LPBIG_OFFBIG 1 + +#define _POSIX_ADVISORY_INFO 200112L +#define _POSIX_BARRIERS 200112L +#define _POSIX_CLOCK_SELECTION 200112L +#define _POSIX_CPUTIME 200112L +#define _POSIX_MONOTONIC_CLOCK 200112L + +#ifdef _POSIX_RAW_SOCKETS +#undef _POSIX_RAW_SOCKETS +#endif + +#define _POSIX_SPAWN 200112L +#define _POSIX_SPIN_LOCKS 200112L +#define _POSIX_SPORADIC_SERVER (-1) +#define _POSIX_THREAD_CPUTIME 200112L +#define _POSIX_THREAD_SPORADIC_SERVER (-1) +#define _POSIX_TIMEOUTS 200112L +#define _POSIX_TRACE (-1) +#define _POSIX_TRACE_EVENT_FILTER (-1) +#define _POSIX_TRACE_INHERIT (-1) +#define _POSIX_TRACE_LOG (-1) +#define _POSIX_TYPED_MEMORY_OBJECTS (-1) + +#endif /* _POSIX_C_SOURCE >= 200112L */ + +#define _XOPEN_CRYPT 1 +#define _XOPEN_SHM 1 +#define _XOPEN_ENH_I18N 1 +#define _XOPEN_LEGACY (-1) +#ifndef __64BIT__ +#define _UNIX_ABI (-1) +#define _UNIX_ABI_IA64 (-1) +#define _UNIX_ABI_BIG_ENDIAN (-1) +#define _UNIX_ABI_LITTLE_ENDIAN (-1) +#endif /* __64BIT__ */ + +extern char *optarg; +extern int optind, opterr, optopt; + +#ifdef _NO_PROTO +extern size_t confstr(); +extern char *crypt(); +extern void encrypt(); +extern int fsync(); +extern int getopt(); +extern int nice(); +extern void swab(); +#if (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE<200112L) || defined(_ALL_SOURCE) +extern char *getpass(); +extern int chroot(); +#endif +#else +extern size_t confstr(int, char*, size_t); +extern char *crypt(const char *, const char *); +extern void encrypt(char *, int); +extern int fsync(int); +extern int getopt(int, char* const*, const char*); +extern int nice(int); +extern void swab(const void *, void *, ssize_t); +extern int fdatasync(int); +#if (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE<200112L) || defined(_ALL_SOURCE) +extern char *getpass(const char *); +extern int chroot(const char *); +#endif +#endif + +#endif /* _XOPEN _SOURCE */ + +/* Threads options for 1003.1c and XPG UNIX98 */ +#define _POSIX_THREADS 200112L +#define _POSIX_THREAD_ATTR_STACKADDR 200112L +#define _POSIX_THREAD_ATTR_STACKSIZE 200112L +#define _POSIX_THREAD_PROCESS_SHARED 200112L +#define _POSIX_THREAD_SAFE_FUNCTIONS 200112L +#ifdef _ALL_SOURCE +#define _POSIX_REENTRANT_FUNCTIONS _POSIX_THREAD_SAFE_FUNCTIONS +#endif + +/* Realtime threads options for 1003.1c and XPG UNIX98 */ +#define _POSIX_THREAD_PRIORITY_SCHEDULING (-1) +#define _POSIX_THREAD_PRIO_INHERIT (-1) +#define _POSIX_THREAD_PRIO_PROTECT (-1) + +#undef _POSIX_THREAD_FORKALL + +/* Realtime options for 1003.1c and XPG UNIX98 */ +#define _POSIX_ASYNCHRONOUS_IO 200112L +#define _POSIX_FSYNC 200112L +#define _POSIX_MAPPED_FILES 200112L +#define _POSIX_MEMLOCK 200112L +#define _POSIX_MEMLOCK_RANGE 200112L +#define _POSIX_MEMORY_PROTECTION 200112L +#define _POSIX_MESSAGE_PASSING 200112L +#define _POSIX_PRIORITIZED_IO 200112L +#define _POSIX_PRIORITY_SCHEDULING 200112L +#define _POSIX_REALTIME_SIGNALS 200112L +#define _POSIX_SEMAPHORES 200112L +#define _POSIX_SHARED_MEMORY_OBJECTS 200112L +#define _POSIX_SYNCHRONIZED_IO 200112L +#define _POSIX_TIMERS 200112L + +#define _POSIX_ASYNC_IO (-1) +#undef _POSIX_SYNC_IO +#define _POSIX_PRIO_IO (-1) + +#define _POSIX_CHOWN_RESTRICTED 0 +#define _POSIX_VDISABLE 0xFF +#define _POSIX_NO_TRUNC 0 + +/* UNIX03 and POSIX01 */ +/* Always enabled */ +#define _POSIX_IPV6 200112L +#define _POSIX_RAW_SOCKETS 200112L + + +#ifndef NULL +#define NULL 0 +#endif + +#if (_POSIX_C_SOURCE >= 200112L) +#define _POSIX_READER_WRITER_LOCKS 200112L +#endif + +/* arguments for the confstr() function */ + +#define _CS_PATH 1 + +/* compile,link,lib,lint flags for 32bit, no_LARGE_FILES system */ +#define _CS_XBS5_ILP32_OFF32_CFLAGS 2 +#define _CS_XBS5_ILP32_OFF32_LDFLAGS 3 +#define _CS_XBS5_ILP32_OFF32_LIBS 4 +#define _CS_XBS5_ILP32_OFF32_LINTFLAGS 5 + +/* compile,link,lib,lint flags for 32bit, _LARGE_FILES system */ +#define _CS_XBS5_ILP32_OFFBIG_CFLAGS 6 +#define _CS_XBS5_ILP32_OFFBIG_LDFLAGS 7 +#define _CS_XBS5_ILP32_OFFBIG_LIBS 8 +#define _CS_XBS5_ILP32_OFFBIG_LINTFLAGS 9 + +/* compile,link,lib,lint flags for LP64 64bit system */ +#define _CS_XBS5_LP64_OFF64_CFLAGS 10 +#define _CS_XBS5_LP64_OFF64_LDFLAGS 11 +#define _CS_XBS5_LP64_OFF64_LIBS 12 +#define _CS_XBS5_LP64_OFF64_LINTFLAGS 13 + +/* compile,link,lib,lint flags for ILP64 64bit system */ +/* AIX does not currently support this */ +#define _CS_XBS5_LPBIG_OFFBIG_CFLAGS 14 +#define _CS_XBS5_LPBIG_OFFBIG_LDFLAGS 15 +#define _CS_XBS5_LPBIG_OFFBIG_LIBS 16 +#define _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS 17 + +#define _CS_AIX_BOOTDEV 24 +#define _CS_AIX_MODEL_CODE 25 +#define _CS_AIX_ARCHITECTURE 26 +#define _CS_AIX_MODEL_CLASS 40 + +#if (_POSIX_C_SOURCE >= 200112L) +#define _CS_POSIX_V6_ILP32_OFF32_CFLAGS 27 +#define _CS_POSIX_V6_ILP32_OFF32_LDFLAGS 28 +#define _CS_POSIX_V6_ILP32_OFF32_LIBS 29 +#define _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS 30 +#define _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS 31 +#define _CS_POSIX_V6_ILP32_OFFBIG_LIBS 32 +#define _CS_POSIX_V6_LP64_OFF64_CFLAGS 33 +#define _CS_POSIX_V6_LP64_OFF64_LDFLAGS 34 +#define _CS_POSIX_V6_LP64_OFF64_LIBS 35 +#define _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS 36 +#define _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS 37 +#define _CS_POSIX_V6_LPBIG_OFFBIG_LIBS 38 +#define _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS 39 +#endif + +/* Values for the above */ +#define _CSPATH "/usr/bin:/usr/vac/bin" + +/* ILP32_OFF32 */ +#define _CSPOSIX_V6_ILP32_OFF32_CFLAGS "-q32" +#define _CSXBS5_ILP32_OFF32_CFLAGS _CSPOSIX_V6_ILP32_OFF32_CFLAGS + +#ifdef __ia64 +#define _CSXBS5_ILP32_OFF32_LDFLAGS "" +#else /* POWER */ +#define _CSPOSIX_V6_ILP32_OFF32_LDFLAGS "-b32" +#define _CSXBS5_ILP32_OFF32_LDFLAGS _CSPOSIX_V6_ILP32_OFF32_LDFLAGS +#endif + +#define _CSPOSIX_V6_ILP32_OFF32_LIBS "-lc -lpthread -lm" +#define _CSXBS5_ILP32_OFF32_LIBS _CSPOSIX_V6_ILP32_OFF32_LIBS + +#define _CSXBS5_ILP32_OFF32_LINTFLAGS "" + +/* ILP32_OFFOFFBIG */ +#define _CSPOSIX_V6_ILP32_OFFBIG_CFLAGS "-q32 -D_LARGE_FILES -qlonglong" +#define _CSXBS5_ILP32_OFFBIG_CFLAGS _CSPOSIX_V6_ILP32_OFFBIG_CFLAGS + +#ifdef __ia64 +#define _CSXBS5_ILP32_OFFBIG_LDFLAGS "" +#else /* POWER */ +#define _CSPOSIX_V6_ILP32_OFFBIG_LDFLAGS "-b32" +#define _CSXBS5_ILP32_OFFBIG_LDFLAGS _CSPOSIX_V6_ILP32_OFFBIG_LDFLAGS +#endif + +#define _CSPOSIX_V6_ILP32_OFFBIG_LIBS "-lc -lpthread -lm" +#define _CSXBS5_ILP32_OFFBIG_LIBS _CSPOSIX_V6_ILP32_OFFBIG_LIBS + +#define _CSXBS5_ILP32_OFFBIG_LINTFLAGS "-D_LARGE_FILES -qlonglong" + +/* LP64_OFF64 */ +#define _CSPOSIX_V6_LP64_OFF64_CFLAGS "-q64" +#define _CSXBS5_LP64_OFF64_CFLAGS _CSPOSIX_V6_LP64_OFF64_CFLAGS + +#ifdef __ia64 +#define _CSXBS5_LP64_OFF64_LDFLAGS "" +#else /* POWER */ +#define _CSPOSIX_V6_LP64_OFF64_LDFLAGS "-b64" +#define _CSXBS5_LP64_OFF64_LDFLAGS _CSPOSIX_V6_LP64_OFF64_LDFLAGS +#endif + +#define _CSPOSIX_V6_LP64_OFF64_LIBS "-lc -lpthread -lm" +#define _CSXBS5_LP64_OFF64_LIBS _CSPOSIX_V6_LP64_OFF64_LIBS + +#define _CSXBS5_LP64_OFF64_LINTFLAGS "-D__64BIT__" + +/* LPBIG_OFFBIG */ +#define _CSPOSIX_V6_LPBIG_OFFBIG_CFLAGS "-q64" +#define _CSXBS5_LPBIG_OFFBIG_CFLAGS _CSPOSIX_V6_LPBIG_OFFBIG_CFLAGS + +#ifdef __ia64 +#define _CSXBS5_LPBIG_OFFBIG_LDFLAGS "" +#else /* POWER */ +#define _CSPOSIX_V6_LPBIG_OFFBIG_LDFLAGS "-b64" +#define _CSXBS5_LPBIG_OFFBIG_LDFLAGS _CSPOSIX_V6_LPBIG_OFFBIG_LDFLAGS +#endif + +#define _CSPOSIX_V6_LPBIG_OFFBIG_LIBS "-lc -lpthread -lm" +#define _CSXBS5_LPBIG_OFFBIG_LIBS _CSPOSIX_V6_LPBIG_OFFBIG_LIBS + +#define _CSXBS5_LPBIG_OFFBIG_LINTFLAGS "-D__64BIT__" + +#if (_POSIX_C_SOURCE >= 200112L) +#define _CSPOSIX_V6_WIDTH_RESTRICTED_ENVS \ + "POSIX_V6_ILP32_OFF32\n" \ + "POSIX_V6_ILP32_OFFBIG\n" \ + "POSIX_V6_LP64_OFF64\n" \ + "POSIX_V6_LPBIG_OFFBIG" +#endif + +/* arguments for the pathconf() function */ + +#define _PC_CHOWN_RESTRICTED 10 +#define _PC_LINK_MAX 11 +#define _PC_MAX_CANON 12 +#define _PC_MAX_INPUT 13 +#define _PC_NAME_MAX 14 +#define _PC_NO_TRUNC 15 +#define _PC_PATH_MAX 16 +#define _PC_PIPE_BUF 17 +#define _PC_VDISABLE 18 +#define _PC_ASYNC_IO 19 +#define _PC_SYNC_IO 20 +#define _PC_PRIO_IO 21 +#define _PC_FILESIZEBITS 22 /* # bits needed to hold offset */ +#define _PC_AIX_DISK_PARTITION 23 +#define _PC_AIX_DISK_SIZE 24 +#if (_POSIX_C_SOURCE >= 200112L) +#define _PC_SYMLINK_MAX 25 +#define _PC_ALLOC_SIZE_MIN 26 +#define _PC_REC_INCR_XFER_SIZE 27 +#define _PC_REC_MAX_XFER_SIZE 28 +#define _PC_REC_MIN_XFER_SIZE 29 +#define _PC_REC_XFER_ALIGN 30 +#define _PC_2_SYMLINKS 31 +#endif + +/* arguments for the sysconf() function, the defined numbers are used as + * array index in sysconf(). + * + * POSIX.1(1990), Table 4-2 + */ +#define _SC_ARG_MAX 0 +#define _SC_CHILD_MAX 1 +#define _SC_CLK_TCK 2 +#define _SC_NGROUPS_MAX 3 +#define _SC_OPEN_MAX 4 +#define _SC_STREAM_MAX 5 +#define _SC_TZNAME_MAX 6 +#define _SC_JOB_CONTROL 7 +#define _SC_SAVED_IDS 8 +#define _SC_VERSION 9 + +/* POSIX.1(1990), Table 2-3, required by command getconf */ + +#define _SC_POSIX_ARG_MAX 10 +#define _SC_POSIX_CHILD_MAX 11 +#define _SC_POSIX_LINK_MAX 12 +#define _SC_POSIX_MAX_CANON 13 +#define _SC_POSIX_MAX_INPUT 14 +#define _SC_POSIX_NAME_MAX 15 +#define _SC_POSIX_NGROUPS_MAX 16 +#define _SC_POSIX_OPEN_MAX 17 +#define _SC_POSIX_PATH_MAX 18 +#define _SC_POSIX_PIPE_BUF 19 +#define _SC_POSIX_SSIZE_MAX 20 +#define _SC_POSIX_STREAM_MAX 21 +#define _SC_POSIX_TZNAME_MAX 22 + +/* POSIX.2 (Draft 10), Table 41) */ + +#define _SC_BC_BASE_MAX 23 +#define _SC_BC_DIM_MAX 24 +#define _SC_BC_SCALE_MAX 25 +#define _SC_BC_STRING_MAX 26 +#define _SC_EQUIV_CLASS_MAX 27 +#define _SC_EXPR_NEST_MAX 28 +#define _SC_LINE_MAX 29 +#define _SC_RE_DUP_MAX 30 +#define _SC_2_VERSION 31 +#define _SC_2_C_DEV 32 +#define _SC_2_FORT_DEV 33 +#define _SC_2_FORT_RUN 34 +#define _SC_2_LOCALEDEF 35 +#define _SC_2_SW_DEV 36 + +/* POSIX.2 (Draft 10), Table 13) */ + +#define _SC_POSIX2_BC_BASE_MAX 37 +#define _SC_POSIX2_BC_DIM_MAX 38 +#define _SC_POSIX2_BC_SCALE_MAX 39 +#define _SC_POSIX2_BC_STRING_MAX 40 +#define _SC_POSIX2_EQUIV_CLASS_MAX 41 +#define _SC_POSIX2_EXPR_NEST_MAX 42 +#define _SC_POSIX2_LINE_MAX 43 +#define _SC_POSIX2_RE_DUP_MAX 44 +#define _SC_PASS_MAX 45 +#define _SC_XOPEN_VERSION 46 +#define _SC_ATEXIT_MAX 47 +#if _XOPEN_SOURCE_EXTENDED==1 +#define _SC_PAGE_SIZE 48 +#endif /* _XOPEN_SOURCE_EXTENDED */ +#define _SC_AES_OS_VERSION 49 +#define _SC_COLL_WEIGHTS_MAX 50 +#define _SC_2_C_BIND 51 +#define _SC_2_C_VERSION 52 +#define _SC_2_UPE 53 +#define _SC_2_CHAR_TERM 54 +#define _SC_XOPEN_SHM 55 +#define _SC_XOPEN_CRYPT 56 +#define _SC_XOPEN_ENH_I18N 57 +#if _XOPEN_SOURCE_EXTENDED==1 +#define _SC_PAGESIZE _SC_PAGE_SIZE +#define _SC_IOV_MAX 58 +#endif /* _XOPEN_SOURCE_EXTENDED */ +#define _SC_THREAD_SAFE_FUNCTIONS 59 +#define _SC_THREADS 60 +#define _SC_THREAD_ATTR_STACKADDR 61 +#define _SC_THREAD_ATTR_STACKSIZE 62 +#define _SC_THREAD_FORKALL 63 +#define _SC_THREAD_PRIORITY_SCHEDULING 64 +#define _SC_THREAD_PRIO_INHERIT 65 +#define _SC_THREAD_PRIO_PROTECT 66 +#define _SC_THREAD_PROCESS_SHARED 67 +#define _SC_THREAD_KEYS_MAX 68 +#define _SC_THREAD_DATAKEYS_MAX _SC_THREAD_KEYS_MAX +#define _SC_THREAD_STACK_MIN 69 +#define _SC_THREAD_THREADS_MAX 70 +#ifdef _ALL_SOURCE +#define _SC_NPROCESSORS_CONF 71 +#define _SC_NPROCESSORS_ONLN 72 +#endif /* _ALL_SOURCE */ +#define _SC_XOPEN_UNIX 73 + +#if (_XOPEN_SOURCE >= 500) + +/* POSIX 1003.1c and XPG UNIX98 */ +/* look to defines above for meanings */ +#define _SC_AIO_LISTIO_MAX 75 +#define _SC_AIO_MAX 76 +#define _SC_AIO_PRIO_DELTA_MAX 77 +#define _SC_ASYNCHRONOUS_IO 78 +#define _SC_DELAYTIMER_MAX 79 +#define _SC_FSYNC 80 +#define _SC_GETGR_R_SIZE_MAX 81 +#define _SC_GETPW_R_SIZE_MAX 82 +#define _SC_LOGIN_NAME_MAX 83 +#define _SC_MAPPED_FILES 84 +#define _SC_MEMLOCK 85 +#define _SC_MEMLOCK_RANGE 86 +#define _SC_MEMORY_PROTECTION 87 +#define _SC_MESSAGE_PASSING 88 +#define _SC_MQ_OPEN_MAX 89 +#define _SC_MQ_PRIO_MAX 90 +#define _SC_PRIORITIZED_IO 91 +#define _SC_PRIORITY_SCHEDULING 92 +#define _SC_REALTIME_SIGNALS 93 +#define _SC_RTSIG_MAX 94 +#define _SC_SEMAPHORES 95 +#define _SC_SEM_NSEMS_MAX 96 +#define _SC_SEM_VALUE_MAX 97 +#define _SC_SHARED_MEMORY_OBJECTS 98 +#define _SC_SIGQUEUE_MAX 99 +#define _SC_SYNCHRONIZED_IO 100 +#define _SC_THREAD_DESTRUCTOR_ITERATIONS 101 +#define _SC_TIMERS 102 +#define _SC_TIMER_MAX 103 +#define _SC_TTY_NAME_MAX 104 +#define _SC_XBS5_ILP32_OFF32 105 +#define _SC_XBS5_ILP32_OFFBIG 106 +#define _SC_XBS5_LP64_OFF64 107 +#define _SC_XBS5_LPBIG_OFFBIG 108 +#define _SC_XOPEN_XCU_VERSION 109 +#define _SC_XOPEN_REALTIME 110 +#define _SC_XOPEN_REALTIME_THREADS 111 +#define _SC_XOPEN_LEGACY 112 +#endif /* _XOPEN_SOURCE >= 500 */ + +#ifdef _ALL_SOURCE +#define _SC_REENTRANT_FUNCTIONS _SC_THREAD_SAFE_FUNCTIONS +#define _SC_PHYS_PAGES 113 +#define _SC_AVPHYS_PAGES 114 +#define _SC_LPAR_ENABLED 115 +#define _SC_LARGE_PAGESIZE 116 +#endif /* _ALL_SOURCE */ + +#define _SC_AIX_KERNEL_BITMODE 117 +#define _SC_AIX_REALMEM 118 +#define _SC_AIX_HARDWARE_BITMODE 119 +#define _SC_AIX_MP_CAPABLE 120 + +#define _SC_V6_ILP32_OFF32 121 +#define _SC_V6_ILP32_OFFBIG 122 +#define _SC_V6_LP64_OFF64 123 +#define _SC_V6_LPBIG_OFFBIG 124 + +#define _SC_XOPEN_STREAMS 125 + +#if (_POSIX_C_SOURCE >= 200112L) +#define _SC_HOST_NAME_MAX 126 +#define _SC_REGEXP 127 +#define _SC_SHELL 128 +#define _SC_SYMLOOP_MAX 129 +#define _SC_ADVISORY_INFO 130 +#define _SC_FILE_LOCKING 131 +#define _SC_2_PBS 132 +#define _SC_2_PBS_ACCOUNTING 133 +#define _SC_2_PBS_CHECKPOINT 134 +#define _SC_2_PBS_LOCATE 135 +#define _SC_2_PBS_MESSAGE 136 +#define _SC_2_PBS_TRACK 137 +#define _SC_BARRIERS 138 +#define _SC_CLOCK_SELECTION 139 +#define _SC_CPUTIME 140 +#define _SC_MONOTONIC_CLOCK 141 +#define _SC_READER_WRITER_LOCKS 142 +#define _SC_SPAWN 143 +#define _SC_SPIN_LOCKS 144 +#define _SC_SPORADIC_SERVER 145 +#define _SC_THREAD_CPUTIME 146 +#define _SC_THREAD_SPORADIC_SERVER 147 +#define _SC_TIMEOUTS 148 +#define _SC_TRACE 149 +#define _SC_TRACE_EVENT_FILTER 150 +#define _SC_TRACE_INHERIT 151 +#define _SC_TRACE_LOG 152 +#define _SC_TYPED_MEMORY_OBJECTS 153 +#define _SC_IPV6 154 +#define _SC_RAW_SOCKETS 155 +#define _SC_SS_REPL_MAX 156 +#define _SC_TRACE_EVENT_NAME_MAX 157 +#define _SC_TRACE_NAME_MAX 158 +#define _SC_TRACE_SYS_MAX 159 +#define _SC_TRACE_USER_EVENT_MAX 160 +#endif /* _POSIX_C_SOURCE >= 200112L */ + +#ifdef _ALL_SOURCE +#define _SC_AIX_UKEYS 161 +#endif /* _ALL_SOURCE */ + +#endif /* _POSIX_SOURCE */ + + +#if _XOPEN_SOURCE_EXTENDED==1 +#ifdef _LARGE_FILES +#define ftruncate ftruncate64 +#define truncate truncate64 +#endif + +#ifndef _H_LOCKF +#include <sys/lockf.h> /* lockf definitions for portability */ +#endif + +#ifdef _NO_PROTO +#if (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE<200112L) || defined(_ALL_SOURCE) +extern int brk(); +extern int getpagesize(); +#ifndef _MSGQSUPPORT +extern int __fd_getdtablesize(); +static int getdtablesize() +{ + return __fd_getdtablesize(); +} +#else +extern int getdtablesize(); +#endif /* _MSGQSUPPORT */ + +extern void *sbrk(); +#endif /* _POSIX_C_SOURCE<200112L */ +extern int fchdir(); +extern int fchown(); +extern int ftruncate(); +extern long gethostid(); +extern int gethostname(); +extern pid_t getpgid(); +extern pid_t getsid(); +extern char *getwd(); +extern int lchown(); +extern int readlink(); +extern pid_t setpgrp(); +extern int setregid(); +extern int setreuid(); +extern int symlink(); +extern void sync(); +extern int truncate(); +extern useconds_t ualarm(); +extern int usleep(); +extern pid_t vfork(); +#else /* _NO_PROTO */ +#if (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE<200112L) || defined(_ALL_SOURCE) +extern int brk(void *); +extern int getpagesize(void); +#ifndef _MSGQSUPPORT +extern int __fd_getdtablesize(void); +static int getdtablesize() +{ + return __fd_getdtablesize(); +} +#else +extern int getdtablesize(void); +#endif /* _MSGQSUPPORT */ +#ifdef _LINUX_SOURCE_COMPAT +extern void *sbrk(ptrdiff_t); +#elif (_XOPEN_SOURCE >= 500) || defined(__64BIT__) +extern void *sbrk(intptr_t); +#else +extern void *sbrk(int); +#endif +#endif /* _POSIX_C_SOURCE<200112L */ +extern int fchdir(int); +extern int fchown(int, uid_t, gid_t); +extern int ftruncate(int, off_t); +#ifdef _LARGE_FILE_API +extern int ftruncate64(int, off64_t); +#endif +extern int gethostname(char *, size_t); +extern long gethostid(void); +extern pid_t getpgid(pid_t); +extern pid_t getsid(pid_t); +extern char *getwd(char *); +extern int lchown(const char *, uid_t, gid_t); + +#if (defined(_SUSV3_READLINK) || \ + (!defined(_ALL_SOURCE) && (_POSIX_C_SOURCE >= 200112L))) +/* If SUSV3 readlink specifically requested or if strict SUSv3 + * environment requested */ +#ifdef __64BIT__ +static ssize_t readlink(const char *__restrict__ __path, + char *__restrict__ __buf, size_t __bufsize) +{ + extern ssize_t __readlink64(const char *__restrict__, char *__restrict__, size_t); + return __readlink64(__path, __buf, __bufsize); +} +#else +extern ssize_t readlink(const char *__restrict__, char *__restrict__, size_t); +#endif /* __64BIT__ */ +#else +extern int readlink(const char *, char *, size_t); +#endif /* _SUSV3_READLINK || !_ALL_SOURCE && _POSIX_C_SOURCE >= 200112L */ + +#ifndef _BSD +extern pid_t setpgrp(void); +#endif /* _BSD */ +extern int setregid(gid_t, gid_t); +extern int setreuid(uid_t, uid_t); +extern int symlink(const char *, const char *); +extern void sync(void); +extern int truncate(const char *, off_t); +#ifdef _LARGE_FILE_API +extern int truncate64(const char *, off64_t); +#endif +extern useconds_t ualarm(useconds_t, useconds_t); +extern int usleep(useconds_t); +extern pid_t vfork(void); +#if _XOPEN_SOURCE>=500 +extern int getlogin_r(char *, size_t); +extern int ttyname_r(int, char *, size_t); + +#ifdef _LARGE_FILES +#define pread pread64 +#define pwrite pwrite64 +#endif /* _LARGE_FILES */ + +extern ssize_t pread(int, void *, size_t, off_t); +extern ssize_t pwrite(int, const void *, size_t, off_t); +#ifdef _LARGE_FILE_API +extern ssize_t pread64(int, void *, size_t, off64_t); +extern ssize_t pwrite64(int, const void *, size_t, off64_t); +#endif /* _LARGE_FILE_API */ +#endif /* _XOPEN_SOURCE>=500 */ + +#endif /* _NO_PROTO */ + +#endif /* _XOPEN_SOURCE_EXTENDED */ + +#ifdef _ALL_SOURCE + +extern char **environ; + +#ifndef _KERNEL +#ifdef _NO_PROTO +extern pid_t f_fork(); +#else /* _NO_PROTO */ +extern pid_t f_fork(void); +#endif /* _NO_PROTO */ +#endif /* _KERNEL */ + +#ifdef _NO_PROTO +extern char * cuserid(); +extern int ioctl(); +#ifdef __64BIT__ +extern int ioctlx(); +extern int ioctl32(); +extern int ioctl32x(); +#endif /* __64BIT__ */ +extern int readx(); +extern int setgroups(); +extern int writex(); +extern int setegid(); +extern int seteuid(); +extern int setrgid(); +extern int setruid(); +extern offset_t llseek(); +extern char * getusershell(); +extern void setusershell(); +extern void endusershell(); +extern char * get_current_dir_name(); +extern int sysfs(); +#else +extern char * cuserid(char *); +extern int setegid(gid_t); +extern int seteuid(uid_t); +extern int setrgid(gid_t); +extern int setruid(uid_t); +#ifndef _BSD +extern int ioctl(int, int, ...); +#endif /* _BSD */ +#ifdef __64BIT__ +extern int ioctlx(int, int, void *, long); +extern int ioctl32(int, int, ...); +extern int ioctl32x(int, int, unsigned int, unsigned int); +#endif /* __64BIT__ */ +extern int setgroups(int, gid_t []); +#ifndef _KERNEL +extern int readx(int, char*, unsigned, long); +extern int writex(int, char*, unsigned, long); + +#ifdef _LARGE_FILES +#define fclear fclear64 +#define fsync_range fsync_range64 +#endif +extern off_t fclear(int, off_t); +extern int fsync_range(int, int, off_t, off_t); +#ifdef _LARGE_FILE_API +extern off64_t fclear64(int, off64_t); +extern int fsync_range64(int, int, off64_t, off64_t); +#endif +extern offset_t llseek(int, offset_t, int); +extern char * getusershell(void); +extern void setusershell(void); +extern void endusershell(void); +extern char * get_current_dir_name(void); +extern int sysfs(int, ...); +extern int finfo(const char *, int, void *, int32long64_t); +extern int ffinfo(int, int, void *, int32long64_t); + +#endif /* ndef _KERNEL */ + +#endif /* _NO_PROTO */ + +#define _AES_OS_VERSION 1 /* OSF, AES version */ + +#endif /* _ALL_SOURCE */ + +#ifdef __cplusplus +} +#endif + +#endif /* _H_UNISTD */